Skip to content

fix: workers wait for their own subagents before ending (#388) - #411

Merged
rochecompaan merged 6 commits into
mainfrom
agent/issue-388-implementation-worker-ends-without-a-result-whil
Nov 22, 2026
Merged

rochecompaan merged 6 commits into
mainfrom
agent/issue-388-implementation-worker-ends-without-a-result-whil

Conversation

@rochecompaan

@rochecompaan rochecompaan commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Closes #388

A worker now waits for its own subagent runs in the same turn, the Console agent never tells it to yield, and a no result outcome names a run that was still running.

Changes

  • src/kernel/unfinished-runs.ts (new): reads the worker's own session JSONL and lists subagent runs it started or resumed and never saw finish (subagent-notify, bg_wait completion, or stop). Entries copied from before a fork, child sessions in subdirectories, and broken lines are ignored.
  • src/kernel/run-once.ts: after a phase session that did not time out or abort, a no result reason becomes e.g. no result: the worker ended its turn while its reviewer run <id> was still running. Status stays invalid, label stays needs-info.
  • src/cli/commands/init/agent-dir.ts: the console worker gets bg_wait and subagent_supervisor.
  • skills/patchmill-implementation/SKILL.md: new "Wait for your own subagents" section; the reviewer launches with async: true and is awaited with bg_wait. Documents the resume workaround: a top-level resume always detaches (documented pi-subagents 0.80.0 behavior), so wait on its new run id with bg_wait.
  • skills/patchmill-frontend-review/SKILL.md: same reviewer launch rule (review finding).
  • src/kernel/run-envelope.md, envelope.ts: new hard rule for all envelopes except interactive planning.
  • src/console/tools.ts: Console agent prompt guidelines: never tell a worker to yield or end without its result; tell it to wait with bg_wait.
  • Installed skill copies and manifest refreshed with skills update.

Rulings (cost if wrong)

  • With a session header, entries without a parseable timestamp do not count — cost: such a run is not named (diagnostic wording only).
  • A later receipt for the same run id moves it to the end of the start order — cost: name order in a several-runs reason.
  • Review Important docs: clarify Patchmill software factory framing #1 accepted: the frontend-review skill also told the worker to run its reviewer with async: false; changed to async: true + bg_wait — cost: none beyond prose.
  • The planning skill's foreground reviewer is left as-is: interactive planning runs in the Console agent, which completion notices wake (plan non-goal) — cost: an unattended planner could still hit a blocked foreground reviewer.
  • skills update also moved manifest source patchmill 1.0.0 → 1.1.0 (package version) and installedAt — cost: none.
  • Reviewer "Declined to judge" items (run finished only via status, bg_wait error with completions, empty-runs notify, comment trust boundary, stop by id prefix, RPC tool registration) — all accepted as out of scope or unreachable; at worst they affect diagnostic wording.

Deferred Minor findings

  • No test asserts that the interactive planning envelope lacks the bg_wait rule (plan forbade text-assertion tests).
  • No test proves timed-out/aborted sessions skip the transcript check; only wording would change.

Validation

  • npm test: 1656 pass, 0 fail (baseline 1639 pass, 0 fail)
  • npm run lint: pass
  • npm run build: pass
  • No npm dependency changes; Nix build not required.

Frontend review

Not applicable: no browser-visible change (kernel, skills, prompts only).

Human Reviewer Callouts (Non-Blocking)

  • Permission change: the worker agent definition now also allows bg_wait and subagent_supervisor (src/cli/commands/init/agent-dir.ts:24). Existing repositories pick this up at the next console or Web session start, without a new patchmill init.
  • Public contract: the outcome comment for no result can now have a cause after the prefix (no result: the worker ended …). Anything that reads it, such as the planned Recover when an implementation worker finishes without its result block #407 re-prompt, must match the no result prefix rather than the whole reason.
  • Manifest: .patchmill/skills/patchmill-skill-pack.json records source patchmill 1.0.0 → 1.1.0 and a new installedAt, as a side effect of skills update.
  • No migrations, dependency changes or irreversible operations.

Patchmill run cost

Phase Model Prompt tokens Output tokens Estimated cost (USD)
Planning claude-opus-5-5 35,031,312 199,804 Unavailable
Planning Unknown model 7,590,908 44,965 $0.0000
Implementation claude-opus-5-5 11,022,644 75,854 Unavailable
Implementation Unknown model 2,565,398 17,387 $0.0000
Total 56,210,262 338,010 Unavailable

Includes all retained local runs for this issue, including specification and planning PRs. Prompt tokens include uncached input, cache reads, and cache writes. Estimated cost uses Pi's recorded model pricing and includes parent and subagent sessions.

@rochecompaan
rochecompaan marked this pull request as ready for review November 22, 2026 15:15
@rochecompaan
rochecompaan merged commit 43c9824 into main Nov 22, 2026
3 checks passed
@rochecompaan
rochecompaan deleted the agent/issue-388-implementation-worker-ends-without-a-result-whil branch November 22, 2026 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implementation worker ends without a result while its reviewer is still running

1 participant