Task Worktree
The saved record of a standalone graph node's own worktree and branch: its owner, base, state, and size.
A task worktree is a worktree and branch of a session, apart from the session worktree, where a standalone execution graph node and its children work. Its record names the node that reserved it, where it starts, how far creation or removal got, and what it takes on disk, so after a restart the host knows what to discard, keep, or finish removing. Env covers its identity and names.
Lifecycle🔗
stateDiagram-v2
[*] --> creating: claim reserves it
creating --> ready: prepare created it
creating --> removing: interrupted
ready --> removing: retired
removing --> ready: put back
removing --> creating: put back, no checkout
removing --> [*]: record deletedRecord🔗
| Field | Meaning |
|---|---|
| Owner | The top-level node that reserved it, its only creator |
| Base branch | The branch it starts from |
| Base commit | That branch's tip when it was created, fixed once so a retry starts there |
| State | creating, ready, or removing |
| Size | Last measured bytes, a lower bound when the walk stopped early |
A creating worktree may be partly made and is created again when its owner is retried; a removing one is never used until its removal ends or is put back.
Reservation🔗
- A top-level
ExclusiveWritenode asks for one with"environment": "standalone"; its children share it. Each worktree has one top-level node, a writer withSessionWorkflowpost-processing, since only its commit puts its work on the branch. - The owner's claim checks the limit and reserves the record as
creatingin the claim's transaction. A session keeps at mostTASK_WORKTREE_LIMIT(10), counting ones being created or removed. Children wait until it isready, and a record another node owns, or whose names it shares, leaves the node waiting withWorktreeConflict. preparecreates it under the worktree cleanup lane and a session status lease. It refuses a branch of its name that does not point at the recorded base commit, and tells the session chat once the worktree is ready.
Base🔗
ExecutionGraph::task_worktree_base picks the base from the owner's direct dependencies:
| Dependency | Base |
|---|---|
| A node in another task worktree | That worktree's branch, so the worktrees stack |
| A writer in the session worktree | The session branch |
| None of these | The session's base branch |
Two bases left is GraphContractError::MultipleBases, and a writer outside the worktree that a dependency names must commit its work (GraphContractError::UncommittedDependency). Nodes amend the branch's one commit with commit hooks in their own runtime sandbox; the branch is never pushed. The commit message still goes through clean_forge_commit_message before Agentty's trailer, so the branch can later be published as the node's pull request; one that cleans to nothing reads Update node and the start of the worktree's id.
Removal🔗
SessionManager::remove_task_worktree reads what a worktree holds before changing anything and keeps work its reason may not discard; an interrupted or ownerless record goes while its work stays on disk. The record moves to removing only in a write transaction, like a claim's, while no queued or running execution works there, so a claim either precedes the removal or finds the worktree being removed.
| Reason | When | Drops uncommitted | Drops commits |
|---|---|---|---|
Unfinished | A removal was cut off; work found puts it back | No | No |
Interrupted | Its creation failed or was cut off | Yes | No |
Ownerless | Its record predates graph owners | No | No |
OwnerCanceled | The user confirmed canceling its owner or graph, in this run | Yes | No |
OwnerStopped | Its owner ended any other way | No | No |
SessionEnded | The session merged, was archived, or was canceled without confirming | No | No |
Discarded | The user pressed d | When typed | When typed |
- The cancel confirmation is kept in memory only, so after a restart a canceled owner's worktree keeps its changes.
- A stopped owner's worktree also stays while an unstarted node still works in it or starts from its branch.
- Removal deletes a real folder without following links in it, and deletes the branch only while it still points at the commit removal read and nothing is checked out on it, so a commit or checkout made meanwhile keeps the worktree.
- The driver reconciles a session after each pass that settled or failed nodes and when it stops; startup reconciles every session that keeps a worktree. The chat hears once of work left on disk, a worktree put back, or a failed removal.
- Deleting a session, or a session cancel the terminal confirmed, removes every task worktree without reading what it holds. A failed removal keeps its record
removing, so it still counts toward the limit.
Space🔗
After nodes settle, a background walk measures each ready worktree with its nodes' attempt directories, stopping at 250,000 entries per directory, and harness directories of superseded attempts go. Freeing space always asks the user; see the graph inspector for d and f, and Graph Resources for the limit and disk waits.