fix(agents): reconcile child output before lost-context sweep failure (fixes #90299)#91400
fix(agents): reconcile child output before lost-context sweep failure (fixes #90299)#91400zenglingbiao wants to merge 2 commits into
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed June 8, 2026, 7:19 AM ET / 11:19 UTC. Summary PR surface: Source +71, Tests +280. Total +351 across 4 files. Reproducibility: yes. at source level: current main's sweeper hardcodes a lost-context error after session-store reconciliation misses, while the linked report includes a non-empty child result in the same completion event. I did not run a live cross-process repro in this read-only review. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Revise the resolver to share the existing terminal-output selection semantics, add stale-run coverage for Do we have a high-confidence way to reproduce the issue? Yes at source level: current main's sweeper hardcodes a lost-context error after session-store reconciliation misses, while the linked report includes a non-empty child result in the same completion event. I did not run a live cross-process repro in this read-only review. Is this the best way to solve the issue? No: the repair is in the right owner area, but it needs to reuse the existing completion-output semantics so Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against 439dcbde3b1f. Label changesLabel justifications:
Evidence reviewedPR surface: Source +71, Tests +280. Total +351 across 4 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Summary
status: failed: subagent run lost active execution contextand a non-empty child result, disagreeing with each other.sweepSubagentRuns()(commit 4980c32, 2026-05-26) hardcoded{ status: "error", error: "subagent run lost active execution context" }without checking whether the child session still had readable assistant output.okso the parent receives a consistent lifecycle/result pair.src/agents/subagent-lost-context-completion.ts— new module:resolveStaleActiveSubagentOutcome()reads child output via the existingreadSubagentOutput()helper and returns{ status: "ok" }when output is present, preserving the existing error path when none is available.src/agents/subagent-lost-context-completion.test.ts— three cases: output → ok, no output → error, whitespace-only → error.src/agents/subagent-registry.ts— sweeper lost-context branch now callsresolveStaleActiveSubagentOutcome()instead of hardcoding the error outcome; setsendedReasontosubagent-completeon recovery.src/agents/subagent-registry.test.ts— two integration tests: stale active run with readable output recovers as ok; stale active run with no output stays as error.readSubagentOutputhelper is already insubagent-announce-output.tsand is reused as-is.Reproduction
sessions_spawnto create a subagent, then callssessions_yieldto wait for completion.agent.runcontext be cleared before the sweeper resolves it.status: "error"/"subagent run lost active execution context"even though the same event carries the child's output.status: "ok"with the captured result.Real behavior proof
Behavior or issue addressed (#90299): The sweeper resolves stale active runs by checking whether the child session has delivered readable assistant text; with output it completes as
ok, without output it keeps the existing lost-context error path.Real environment tested: Linux, Node 22.22.0 —
node scripts/run-vitest.mjsagainst the project's colocated Vitest suite with fake timer-controlled gateway mocks.Exact steps or command run after this patch:
node scripts/run-vitest.mjs src/agents/subagent-lost-context-completion.test.ts src/agents/subagent-registry.test.tsEvidence after fix:
Observed result after fix: The sweeper correctly distinguishes subagents that delivered output (recovered as
ok) from those that did not (kept as lost-context error). When a subagent delivered# ARCHITECTURE.md\nrelease readiness designbefore its process context disappeared, the parent now receives a successful completion with the captured result instead of a contradictory failed-completion-with-output pair.What was not tested: Live Gateway round-trip with a real subagent process that genuinely loses its execution context mid-run was not driven; the sweeper integration tests use Vitest fake timers with mocked
chat.historyresponses. Real cross-process subagent lifecycle timing is covered by the existing e2e suite.Repro confirmation: The two new integration tests in
subagent-registry.test.tspass on the branch:run-lost-context-with-outputsettles as{ status: "ok" }(was hardcoded{ status: "error" }before the patch), whilerun-lost-context-no-outputcontinues to settle as{ status: "error" }.Risk / Mitigation
Risk: The fix calls
readSubagentOutput→chat.historyfor every stale active run the sweeper encounters. Ifchat.historyis slow or unavailable, the sweeper could stall.Mitigation: The sweeper already runs on a periodic timer (default 60s interval);
readSubagentOutputhas a boundedlimit: 100message read. The lost-context branch only fires for runs whose active context is truly gone, which is a narrow population.Risk: A subagent that delivered output but whose session was externally deleted between delivery and the sweeper's reconciliation would still end as lost-context error.
Mitigation: That matches the existing behavior and is correct — when no output is retrievable, the parent should know the result is lost.
Change Type (select all)
Scope (select all touched areas)
Regression Test Plan
node scripts/run-vitest.mjs src/agents/subagent-lost-context-completion.test.tsnode scripts/run-vitest.mjs src/agents/subagent-registry.test.tsReview Findings Addressed
From ClawSweeper review (🧂 initial, 2026-06-08):
resolveStaleActiveSubagentOutcomenow readschat.historydirectly and checks for visible (non-silent, non-skip) assistant text viahasVisibleAssistantOutput(). Tool-call-only histories, silent reply tokens, and whitespace-only output remain on the error path."keeps lost-context error when child history only contains tool calls without visible assistant text"insubagent-registry.test.ts, plus unit test"returns lost-context error when history only contains tool calls without visible output"insubagent-lost-context-completion.test.ts.chat.historyresponses (output-present, tool-call-only, and no-output). The unit tests cover visible text, string content, tool-only, silent reply, and whitespace edge cases.Linked Issue/PR
Fixes #90299
Also note: this PR replaces the approach in #90492 which has been inactive for 3 days. This version adds an extra whitespace-only edge case to
resolveStaleActiveSubagentOutcome, two integration tests in the registry suite that directly exercise the sweeper path, and fuller evidence documentation.