Skip to content

fix(kernel): recover when a phase worker ends without its result block (#407) - #413

Merged
rochecompaan merged 7 commits into
mainfrom
agent/issue-407-recover-when-an-implementation-worker-finishes-w
Nov 22, 2026
Merged

rochecompaan merged 7 commits into
mainfrom
agent/issue-407-recover-when-an-implementation-worker-finishes-w

Conversation

@rochecompaan

@rochecompaan rochecompaan commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Closes #407

Summary

A phase worker can end normally without its final fenced json result block. Before this change, Patchmill then stopped the run as needs-info with no result. This PR:

  • Interactive result source: the pi-subagents worker launcher now reads the result from the worker's last assistant message (in the session file) when that message has a result block. It falls back to output.md when the message has none. The five failed runs (Prepare the kernel for control-plane mode #357, Add a local patchmill run loop for one runner per clone #398, Show an issue's spec, plan and mockups on the live web issue page #384, Show who is on a web issue page and who is typing #386, Include the issue slug in spec and plan branch names #377) did end their last message with a valid block, but the launcher parsed the prose output.md report instead.
  • Result reminder: when a session settles normally and has no block, Patchmill sends one reminder in the same conversation. Unattended runs use a prompt over the open RPC session (startPiRpc remind option). Interactive runs use client.resume (createWorkerLauncher). A non-zero exit, timeout, abort, error or truncated response, crash, or failed or handled first prompt gets no reminder (Fail a phase when Pi exits abnormally after a done result #374).
  • Repository-facts fallback (verifyOutcome, implementation phase only, exit 0, no timeout or abort): an open, ready PR on the right base that closes the issue counts as done, with the warning the worker ended without a result block, so Patchmill verified the ready pull request. An interactive run then enters the review wait. Otherwise the run stops as needs-info with The worker ended without a result block[, also after a reminder]. The repository does not prove completion. <diagnostics>.
  • Envelope and implementation skill: both now say that the result block is the required last step, also when the runtime asks for a findings file. The installed skill copy and its manifest sha256 are updated.

Spec: docs/specs/2026-11-22-issue-407-recover-when-an-implementation-worker-finishes-w-design.md
Plan: docs/plans/2026-11-22-issue-407-recover-when-an-implementation-worker-finishes-w-plan.md

Rulings

  • Planning question 1, confirm R1: ruled confirmed. The independent reviewer checked the R1 correction line by line in worker-launcher.ts (rebind, then the interrupted() check, then stop the new id). The deadline and shutdown regression tests cover it. Cost if wrong: a shutdown during the reminder resume could leave a resumed worker running.
  • Planning question 2, interactive result source in scope: ruled in scope. It is the root cause of the five failed runs. The change only applies to complete completions and falls back to output.md. Cost if wrong: an interactive worker whose last message has a stale block would be read from that block, not from output.md.
  • Reviewer Important 1 (duplicated reminded-result rule and prompt classification): accepted, fixed in c274a36 (parseAgentResult(text, { reminded }) in result.ts, one prompt classification in pi-rpc.ts).
  • Reviewer Important 2 (failed or handled reminder prompt untested): accepted, fixed in c274a36 with fake-Pi reminder.promptError and reminder.handled tests.
  • Declined to judge, resumed session file naming: accepted as is. copySession handles both a new file and an appended file. Cost if wrong: the copied session misses the reminder turn, but the result text still comes from the completion.
  • Declined to judge, client.resume returns a new id: accepted as is. Guidance resumes already rely on it. Cost if wrong: the reminder would return the first completion, which then falls back to the PR facts.
  • Declined to judge, failed resume after start: accepted as is. The spawn path has the same exposure. Cost if wrong: one orphan worker that the operator must stop.
  • Declined to judge, last assistant line vs branch leaf: accepted as is. Worker sessions do not branch. Cost if wrong: an older message is read on a branched session.
  • Declined to judge, stopReason of the last message: accepted as is. Only complete completions read it and a block must be closed to parse. Cost if wrong: a truncated message with a closed block is used.
  • Declined to judge, RPC reminder for unattended planning: accepted as specified. Cost if wrong: one extra prompt in an unattended planning session.
  • Merge with main: origin/main (Fail a phase when Pi exits abnormally after a done result #374, Implementation worker ends without a result while its reviewer is still running #388, Pi 1.6.0) is merged in caf982e. verifyOutcome keeps the Fail a phase when Pi exits abnormally after a done result #374 abnormal-exit check for a done result and the missing-block fallback now also requires no signal. explainMissingResult (Implementation worker ends without a result while its reviewer is still running #388) now keys on missing: true and appends its cause to the new reason. Cost if wrong: a Implementation worker ends without a result while its reviewer is still running #388 diagnosis would not show in a missing-block stop.

Deferred Minor findings

  • verify.ts: make missingResultBlock a type predicate to drop the redundant !result.ok narrowing.
  • worker-launcher.ts: use interrupted() for both post-bind checks (after spawn and after resume).

Validation

On the final head caf982e:

  • npm test: passed, 1703/1703.
  • npm run lint (prettier, eslint, markdownlint): passed.
  • npm run build: passed.
  • Skill pack: both patchmill-implementation/SKILL.md copies have sha256 122b62b2…54eb1, which matches the manifest.
  • PR checks: Node test and lint, Nix package build, Site audit and build: all passed.

Frontend review

Not applicable. The change is kernel, console worker launcher, envelope, and skill text, with no browser-visible UI.

Human Reviewer Callouts (Non-Blocking)

  • The parseAgentResult missing-block reason changes from no result to The worker ended without a result block. (plus missing: true). Any external tooling that matches the old reason text in stop comments would break. parseJsonBlock keeps no result for triage.
  • A fallback done keeps status: "invalid" in the result.json session record. The spec intends this.
  • The installed skill pack's manifest hash changed (.patchmill/skills/patchmill-skill-pack.json).

@rochecompaan
rochecompaan marked this pull request as ready for review November 22, 2026 17:26
@rochecompaan
rochecompaan merged commit 9ef23e7 into main Nov 22, 2026
3 checks passed
@rochecompaan
rochecompaan deleted the agent/issue-407-recover-when-an-implementation-worker-finishes-w branch November 22, 2026 17:30
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.

Recover when an implementation worker finishes without its result block

1 participant