fix: harden subagent completion announce cleanup races#76332
fix: harden subagent completion announce cleanup races#76332neilofneils404 wants to merge 1 commit into
Conversation
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Keep open for now: the fix direction is useful, but the PR is currently conflicting, lacks real after-fix behavior proof, and needs a current-main refresh that preserves merged subagent cleanup guards before it can be a safe landing candidate. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review. So I’m closing this here because the remaining work is already tracked in the canonical issue. Review detailsBest possible solution: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review. Do we have a high-confidence way to reproduce the issue? Yes, source-level. Current main still waits on an active embedded child before using a frozen reply, still awaits browser cleanup before starting the announce tail, and still writes later completion outcome/reason without the PR branch's prior-error preservation logic. Is this the best way to solve the issue? No, not as submitted. The patch shape is plausible, but the branch needs a current-main refresh that preserves the merged browser cleanup guard, removes the changelog edit, and adds real behavior proof. Security review: Security review cleared: No concrete security or supply-chain concern was found; the diff changes in-repo agent lifecycle code, tests, docs, and changelog text only. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 68e06b9ea148. |
329d72b to
ea78e92
Compare
|
Addressed the review feedback in ea78e92067.\n\n- Moved the cleanup preclaim to immediately before , after the awaited pre-cleanup work, so hook/setup exceptions cannot leave without cleanup completion.\n- Added the required Unreleased/Fixes changelog entry.\n- Fixed the lint issue from the original patch.\n\nVerified locally:\n\n |
ea78e92 to
4ac3b9d
Compare
|
Follow-up after rebasing onto current
Verified locally: git diff --check
pnpm test src/agents/subagent-registry-lifecycle.test.ts src/agents/subagent-announce.test.ts
pnpm lint src/agents/subagent-registry-lifecycle.ts src/agents/subagent-registry-lifecycle.test.ts src/agents/subagent-announce.ts src/agents/subagent-announce.test.ts |
4ac3b9d to
36043e0
Compare
|
Addressed the latest review note in
Verified locally: git diff --check
pnpm check:docs
pnpm test src/agents/subagent-registry-lifecycle.test.ts src/agents/subagent-announce.test.ts
pnpm lint src/agents/subagent-registry-lifecycle.ts src/agents/subagent-registry-lifecycle.test.ts src/agents/subagent-announce.ts src/agents/subagent-announce.test.tsI also inspected the current failing CI jobs: the visible failure is in plugin runtime dependency contracts for |
|
This pull request has been automatically marked as stale due to inactivity. |
|
ClawSweeper applied the proposed close for this PR.
|
Summary
Fixes a set of subagent completion lifecycle races that can leave completed child runs stuck behind cleanup/announce sequencing or overwrite a terminal error with a later success signal.
The patch makes three related changes:
Why this matters
The lifecycle path has a few asynchronous pieces that can finish in different orders:
Before this patch, a slow or stuck browser cleanup could delay the announce/cleanup flow. Separately, if a child run had already produced frozen reply text but still appeared active, the announce flow could wait unnecessarily. And in a failure path, a later
completeevent could overwrite the already-recorded terminal error.That combination makes subagent completion feel flaky from the user's side: the work is done, but the parent session may not receive the completion promptly, or the persisted final task state can become misleading.
Implementation notes
Lifecycle cleanup lease
completeSubagentRunnow preclaims cleanup whentriggerCleanupis true and cleanup has not already completed/been handled. That lease is passed intostartSubagentAnnounceCleanupFlowasskipBeginCleanup, avoiding a secondbeginSubagentCleanuprace while still protecting duplicate cleanup attempts.If cleanup is not actually triggered, or announce is suppressed for steer-restart, the preclaim is released so the record does not stay permanently handled.
Browser cleanup no longer blocks announce cleanup
Previously browser cleanup was awaited before starting the subagent announce cleanup flow. This patch starts the announce cleanup flow first, retires run-mode bundle MCP runtime as before, and then launches browser cleanup as a best-effort async task:
cleanupBrowserSessionsForLifecycleEndwhen providedFrozen reply short-circuit
runSubagentAnnounceFlownow checks whetherroundOneReplyalready contains non-empty frozen reply text. If it does, the flow does not wait forwaitForEmbeddedPiRunEndeven ifisEmbeddedPiRunActivereports true. The frozen reply is already the durable completion payload; waiting only increases the chance of a stale active-state race.Terminal error preservation
When a run already has a terminal error outcome/reason, a later successful completion signal no longer overwrites it unless the entry's
startedAtproves the run restarted after the error'sendedAt. The ended hook and persisted outcome use the preserved effective reason/outcome.Tests
Added/updated coverage for:
Verification run locally:
pnpm test src/agents/subagent-registry-lifecycle.test.ts src/agents/subagent-announce.test.tsResult: 2 files passed, 29 tests passed.