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 deleted

Record🔗

FieldMeaning
OwnerThe top-level node that reserved it, its only creator
Base branchThe branch it starts from
Base commitThat branch's tip when it was created, fixed once so a retry starts there
Statecreating, ready, or removing
SizeLast 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 ExclusiveWrite node asks for one with "environment": "standalone"; its children share it. Each worktree has one top-level node, a writer with SessionWorkflow post-processing, since only its commit puts its work on the branch.
  • The owner's claim checks the limit and reserves the record as creating in the claim's transaction. A session keeps at most TASK_WORKTREE_LIMIT (10), counting ones being created or removed. Children wait until it is ready, and a record another node owns, or whose names it shares, leaves the node waiting with WorktreeConflict.
  • prepare creates 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:

DependencyBase
A node in another task worktreeThat worktree's branch, so the worktrees stack
A writer in the session worktreeThe session branch
None of theseThe 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.

ReasonWhenDrops uncommittedDrops commits
UnfinishedA removal was cut off; work found puts it backNoNo
InterruptedIts creation failed or was cut offYesNo
OwnerlessIts record predates graph ownersNoNo
OwnerCanceledThe user confirmed canceling its owner or graph, in this runYesNo
OwnerStoppedIts owner ended any other wayNoNo
SessionEndedThe session merged, was archived, or was canceled without confirmingNoNo
DiscardedThe user pressed dWhen typedWhen 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.