Skip to content

Agent workflow lifecycle

Triage classifies issues. Run-once advances a selected issue. The kernel owns issue labels and run comments. The agent owns git, artifacts, and pull requests. Skills guide judgment within those boundaries.

  1. The kernel selects an open ready or in-progress issue and acquires its permanent local OS lock.
  2. The kernel swaps the ready label for in-progress and rereads the issue.
  3. The kernel fetches origin and reads the required gates and their planning pull requests. It selects the workspace for the next stage.
  4. The planning agent writes the required documents, commits, and pushes them. A required gate also publishes a non-closing planning pull request.
  5. The kernel checks the artifacts and host facts. A required planning gate keeps the issue in-progress until that pull request merges.

A Sub-issue run reads its parent’s newest spec on origin/<base> as an approved, read-only design input. On GitHub, only native sub-issues record the parent link. A Part of #N body line has no effect there. On Forgejo and Gitea, the first non-empty body line must start with Part of #N, for example Part of #356. Patchmill reads only the direct parent in the same repository. A parent spec that exists only on an unmerged branch is not an input.

The Sub-issue still writes its own short spec through the normal stages and gates. That spec links to the Parent spec and names the sections it delivers. It records only decisions that the Parent spec leaves open. If there are none, it says so. If the Parent spec needs a change, the agent asks for input instead of changing or overriding it. The kernel does not enforce the read-only rule.

The envelope, console, planning dialog, and run progress show the Parent spec and its issue number. The envelope gives a git show origin/<base>:<path> command because an existing issue worktree can hold an older copy or none. Parent lookup errors stop the run with needs-info; they are not treated as “no parent”.

Both planning gates default off. Enable workflow.specApproval.required for a separate spec PR, or workflow.planApproval.required for a separate plan PR. Only merging a required planning PR into the base unlocks the next stage. Review approval or an approval label is not enough. An open planning PR causes no further Pi sessions, even if the issue also has agent-ready.

With both gates enabled, merge the spec PR first, then the plan PR. Run patchmill run-once --issue N after each merge. Each later branch starts from the fetched base and must contain the merged artifacts. A closed, unmerged planning PR, missing artifact, or stale copy of a merged artifact needs human input.

If a gate is off, its document accompanies the next required planning PR. Without any remaining gate, missing documents go into the implementation branch. Planning PRs use Refs #N, never an issue-closing reference. Merging a planning PR never marks the issue done.

Implementation reads the spec and plan, prepares the environment, implements, validates, commits, pushes, and marks the implementation pull request ready. The kernel checks that an open, non-draft PR has the implementation branch as head and closes the issue in its body. It then sets agent-done. Merge is a later human or host action, not a completion prerequisite. A later rerun on an open ready implementation PR addresses its review comments.

A missing result, unverified claim, timeout, needs-input, or failed stops with needs-info. The kernel posts the summary and warnings. A human answers questions and adds agent-ready before retrying. After a hard crash, patchmill release --issue N locks the issue before resetting a stale in-progress label. Do not release a normal planning wait to approve it.

Every attempt derives its phase from git and the host. Logs, sessions, and result.json never select a phase. A cleanup-only success receipt does not serve as a workflow checkpoint.

Before selection, every real run sweeps local issue branches and registered worktrees. This includes non-interactive runs, --plan-only, and interactive startup. A dry run performs no cleanup. The sweep can clean a closed issue even when normal selection finds no work or refuses that explicit issue.

Under the issue OS lock, fresh host facts must prove a closed issue and a merged implementation PR into the base. Its head and issue-closing body must match. Planning merges, open PRs, closed-unmerged PRs, and wrong-target PRs never qualify. A confirmed interactive merge also cleans up before the run returns. If the operator quits before merge, the next real run’s sweep handles cleanup.

The optional cleanupHook runs with Bash from the implementation worktree before any workspace removal. Relative script paths resolve there without an executable bit. The hook still runs for a dirty worktree. After the hook, each dirty workspace and its branch remain, with an operator notice.

A hook failure preserves all targets and the done outcome. Diagnostics enter the console and <runsDir>/issue-N/cleanup.log. Immediate cleanup also records diagnostics in the current run log. A matching cleanup.json success receipt prevents hook repetition during partial cleanup retries. It never authorizes removal without fresh host facts.

The kernel never removes the permanent lock inode or its parent directory. Use the human-controlled cleanup skill for inspected manual recovery. It offers the configured hook before removal. Read Run-once for hook guidance, receipt recovery, and the full derivation table.