Graph Executor
How a ready execution graph node is claimed, placed in its Env, run on a worker lane, and settled.
The graph executor takes ready nodes of an execution graph from the saved snapshot to a model turn and stores what each returns. ag-worker owns GraphExecutor; Agentty supplies its storage adapter, Env resolver, and node runners, and a graph driver that calls it. It lets independent nodes run concurrently while the store admits each node exactly once.
Connections🔗
flowchart TD
D[Graph Driver] -->|run_ready_pass| X[Graph Executor]
X -->|slots, leases| GR[Graph Resources]
X -->|locate, prepare| E[Env Resolver]
X -.->|claim, finish, fail| S[(Graph records)]
X -->|GraphRunRequest| N[Node runner]
N -->|session writer| SW[Serial session worker]
N -->|reader, task worktree| B[Lane beside the worker]
N -->|fresh node| U[Utility worker]One Node's Path🔗
A scan walks the graph's current revision in declaration order. For each node:
- Slot: take one of the shared graph dispatch slots and, for a fresh node, its Env lease.
- Budget: reserve the node's first provider call.
- Locate:
GraphEnvResolver::locatenames where the node would run, with no durable effect. - Claim:
GraphDispatchRepository::claim, orclaim_gatedfor a writer, checks and creates the execution in one transaction; see guarantees. A writer's claim also asks the disk and writer gates. - Prepare:
GraphEnvResolver::preparereadies the location at most once per claim, such as creating a task worktree. - Run: the node runner executes it on its lane, with the host permission ceiling intersected with its definition's permissions.
- Settle: after the node's effects,
finishsaves the complete schema-valid response and validates a question-free one;failrecords a runner, preparation, effect, or panic failure, which publishes no validated output.
A refused step leaves the node unclaimed and returns what it took, as Graph Resources describes; an admitted node holds its leases through settlement. A running call scans again when one of its nodes settles, a resource it waited for frees, or the host calls rescan, and reloads the graph each time. With with_wave_limit, each wave settles first.
Contexts and Lanes🔗
GraphContext::TaskConversation gives each node its own task, whose attempts keep an isolated history; GraphContext::Fresh starts an independent utility run per execution.
| Node | Runs on |
|---|---|
| Task writer in the session worktree | The serial session worker, in order with chat turns |
| Read-only task conversation | Beside the serial worker, overlapping other readers |
| Task conversation in a task worktree | Beside the serial worker, apart from session work |
| Fresh utility | The utility worker, through GraphUtilityRunner |
Agentty admits fresh nodes of explicitly launched graphs only as SharedRead, so their writers are task conversations. A node beside the worker leaves session status to its graph lease, so it neither waits for nor hides a pending chat question; stopping the session cancels it.
Focused Review🔗
Each focused-review generation launches its own graph of BackgroundRead fresh nodes, one per diff fragment, joined by a cross-file node and a consolidation node. It runs with with_wave_limit, and each node coordinates its child utility calls through RunWorker::coordinate_recorded, holding no utility slot while they run. See Focused Review Graph.
Graph Driver🔗
Agentty's GraphDriver follows one graph from an explicit launch, approval, or resume until the graph completes or is canceled. It keeps the executor and live budgets when dispatch stops; what starts a stopped one again is in the guarantees.
- While its session is in a state that cannot dispatch, it parks and leaves the writer queue until woken.
- During a pass, which lasts as long as its longest turn, it forwards each gate change, such as a freed worktree or an accepted output, and each disk-wait tick as a rescan.
- When a node settles, beside the running pass, it reconciles and measures the session's task worktrees, announces an output awaiting approval, and records orchestration events.
- After a pass it finishes the pass's session status leases. A failed pass stops the driver unless some node of the graph has executed.
Session Status and Settlement🔗
Each running node, each task worktree being prepared, and each proposal generation and reply decision holds a GraphActivity lease that shows the session InProgress. A node's lease lasts until the driver settles the pass that ran it, including between a node and the dependent it unblocks. The lease's recovery operation never blocks graph claims.
A run turns terminal before settlement stores its response, so hosts sample GraphExecutor::unsettled_executions before reading progress and report those nodes as running. A finished run without a response that no live executor owns, such as after a restart or a failed store, stays failed until an explicit retry.
See Run Worker for budgets and Execution Graphs for the design reasons.