Repository navigation
fix(subagents): drain an expired stuck completion and add a supported dismiss (#154834) - #166604
waynegault wants to merge 9 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Dismissal has stale-authorization and retained-settle-marker bugs, and a required API dependency breaks an existing test factory.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
Fixes permanently re-rendered failed subagent completions and adds a tool action to dismiss them.
Changes:
- Treats cleaned-up failed deliveries as drained.
- Adds
subagents dismiss. - Adds predicate and tool tests.
| File | Description |
|---|---|
src/agents/tools/subagents-tool.ts |
Adds the dismiss action. |
src/agents/tools/subagents-tool.test.ts |
Tests delegation and ownership gating. |
src/agents/subagents/registry/subagent-registry.ts |
Exports the dismissal API. |
src/agents/subagents/registry/subagent-registry-public-api.ts |
Implements persisted dismissal. |
src/agents/subagents/registry/subagent-active-context.ts |
Excludes drained failures. |
src/agents/subagents/registry/subagent-active-context.test.ts |
Covers drained and retrying failures. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| export function createSubagentRegistryPublicApi(config: { | ||
| runs: Map<string, SubagentRunRecord>; | ||
| restoreOnce: (context?: OpenClawStateWorkerContext) => Promise<void>; | ||
| startAnnounceCleanup: (runId: string, entry: SubagentRunRecord) => boolean; | ||
| settleRequesterTurn: SubagentLifecycleController["settleRequesterTurnAfterSessionSpawns"]; | ||
| markRequesterYielded: SubagentLifecycleController["markRequesterTurnYielded"]; | ||
| discardTerminalDelivery: typeof SubagentLifecycleController.discardTerminalDelivery; |
| signal?.throwIfAborted(); | ||
| // A terminal run whose result can never be delivered must be clearable, else | ||
| // its dead result re-renders as outstanding on every later requester turn. | ||
| const result = await dismissSubagentRunDelivery({ runId }); |
|
Codex review: needs real behavior proof before merge. What this changesThe branch hides drained or expired failed child results, adds a completion-dismissal action, and classifies unsuccessful no-route delivery as intentional non-delivery. Example: A parent takes another turn after a child’s delivery gives up.
Review scores
ProductKind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial Merge readiness⛔ Blocked before merge - 7 items remain This PR needs real behavior proof before merge. The latest commit resolves the two test-type findings, but three functional blockers remain; current main still contains the reported defect, and related PRs do not cover all of this branch’s proposed recovery behavior. Priority: P2 Decision needed
Before merge
Findings
Tests
Agent review detailsHow this fits togetherSubagents perform delegated work and retain their results in the shared registry. Delivery and requester-settlement facts determine which completed results appear in later parent prompts. flowchart TD
A[Child finishes delegated work] --> B[Shared subagent registry]
B --> C[Completion delivery attempt]
C --> D[Delivery and cleanup facts]
E[Parent requests dismissal] --> F[Controller ownership check]
F --> B
D --> G[Outstanding result selection]
G --> H[Later parent prompt]
Technical reviewBest possible solution: Keep outstanding-result selection aligned with terminal lifecycle facts, preserve retryable delivery outcomes, and place any approved dismissal capability behind the existing live controller-authority and registry writer owners. Do we have a high-confidence way to reproduce the issue? Yes, current source establishes the reported mechanism: terminal failed deliveries remain outstanding even after cleanup completes. No runtime reproduction was executed during this read-only review. Is this the best way to solve the issue? No, the cleanup guard is useful, but the new dismissal and no-route classification introduce avoidable defects; the narrower proof-positive repair is safer. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3ed1e21065ea. Provenance checked
TestingProof path: unit tests only. SecurityNeeds attention: The new persisted discard capability does not preserve current controller authority through its final write. EvidenceSecurity concerns:
What I checked:
PR surfaceSource +121, Tests +268. Total +389 across 16 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (7 earlier review cycles)
Reviewed October 8, 2026, 1:39 PM ET / 17:39 UTC (Revision 8). |
a49209b to
89a7d44
Compare
…ivery as outstanding A run killed by a gateway restart ends with delivery.status="failed"; once the announce finaliser gives up and cleanup bookkeeping completes, resumeSubagentRun hard-stops the row, yet hasOutstandingCompletion() kept re-rendering the dead result into "## Child results awaiting delivery" on every later requester turn, forever and across gateway restarts (#154834). Treat a `failed` delivery with completed cleanup as drained (not outstanding), while a still-retrying `failed` row (no cleanupCompletedAt) stays outstanding. Adds regression tests for both.
) A run killed by a gateway restart can end with a permanently undeliverable completion: its announce gives up, nothing clears the obligation, and hasOutstandingCompletion() re-renders the dead result into the requester's "## Child results awaiting delivery" context on every later turn, forever and across gateway restarts. There was no supported way to retire it — operators had to hand-edit the state DB. Reuse the existing internal primitive (SubagentLifecycleController .discardTerminalDelivery: disposition intentional_non_delivery + dismissedAt + cleanupCompletedAt) behind a new `subagents` tool action: subagents { action: "dismiss", runId } - dismissSubagentRunDelivery() applies the discard inside a mutateSubagentRuns transaction and returns ok | not_found | not_terminal. - The tool gates on the controlled session tree and rejects non-terminal runs. Depends on the companion drain fix in the previous commit.
… announce hard-expiry (#154834) Cleanup bookkeeping is written after the transport give-up, so a crash in between (e.g. a gateway restart) can leave a give-up row with delivery=failed and no cleanupCompletedAt. The previous drain only covered rows whose cleanup had completed, so such a row stayed outstanding forever and kept re-rendering into '## Child results awaiting delivery'. Drain it once past the announce hard-expiry too, which is the absolute bound: nothing can deliver it after that, and a give-up row never renews its window. suspended is deliberately excluded - it is a successful completion waiting for the requester to take its next turn, not a dead obligation.
…drop-reason assertion - annotate the first-party subagent-registry mock with an adjacent // mock-isolation: reason so check-test-mock-exports accepts the stub. - drop the lastDropReason assertion in the no-route give-up test: the pending-delivery clear deliberately resets transient delivery markers, so the field is undefined after give-up; the disposition invariant is what actually drains the row and is already asserted. Refs #154834
…ged-path checks - the // mock-isolation: marker must be the line immediately above the mock call, not a multi-line comment whose tail sits above it. - oxfmt 0.68.0 normalisation: collapse a wrap in subagent-registry-lifecycle-give-up.ts and reorder the subagent-registry.js import in subagents-tool.ts. Refs #154834
2711a25 to
88d764a
Compare
The rebase onto a newer main introduced four type-check failures on this PR's head (check-test-types-core-2 and -4): - createSubagentRegistryPublicApi now requires discardTerminalDelivery, so the two test mocks that construct the config gain that member. - recordAnnounceDeliveryResult gained a third runs argument; the four no-route/disposition test cases pass the entry's own map. - subagent-active-context.test.ts used endedReason 'complete', which is now the SubagentLifecycleEndedReason value 'subagent-complete'.

What Problem This Solves
A child run killed by a gateway restart can end with a permanently undeliverable completion. Its announce gives up (
delivery path none did not complete,retries=1,Subagent announce give up (expiry)), yet nothing clears the obligation.hasOutstandingCompletion()keeps returningtrue, so the dead result is re-rendered into the requester's prompt under## Child results awaiting deliveryon every later turn, forever and across gateway restarts (#154834).There is also no supported way to retire it. The
subagentstool exposes onlylist | wait | cancel;cancelon an already-terminal run returnskilled: falseand does not retire the obligation. Operators are left hand-editing the state DB.Change
Five commits, all about draining a stuck completion:
1.
fix(subagents): don't re-render a drained give-up terminal failed delivery as outstandingIn
hasOutstandingCompletion()(subagent-active-context.ts), afaileddelivery whose cleanup bookkeeping has completed (cleanupCompletedAtstamped) is drained:resumeSubagentRunhard-stops that row, so it can never be delivered and must not count as outstanding. Afailedrow with nocleanupCompletedAtis still retrying and stays outstanding.2.
feat(subagents): add a supported dismiss for a stuck completionReuses the existing internal primitive —
SubagentLifecycleController.discardTerminalDelivery(entry, at, reason)already setsdisposition: "intentional_non_delivery"+dismissedAt+cleanupCompletedAt— and exposes it as a new tool action:dismissSubagentRunDelivery()applies the discard inside amutateSubagentRunstransaction and returnsok | not_found | not_terminal.cancel) and rejects non-terminal runs.3.
fix(subagents): absolutely bound a give-up failed completion past the announce hard-expiryCommit 1 only drains a give-up
failedrow oncecleanupCompletedAtis stamped — but that stamp is written after the transport give-up, so a crash in between (e.g. a gateway restart) can leavefailedwith no stamp. Thefailedbranch is now also time-bounded: pastresolveAnnounceDeliveryDeadline(entry, now, ANNOUNCE_COMPLETION_HARD_EXPIRY_MS)the row is drained regardless of the stamp.suspendedis deliberately not bounded this way — it is a successful completion waiting for the requester's next turn.4.
fix(subagents): resolve a no-route completion as an intentional non-deliveryA
nonedelivery path selected no transport at all — there is no sink to retry against — so a give-up on it is a deliberate non-delivery, not an undischargeablefailedobligation.recordAnnounceDeliveryResult()now resolves a non-deliveredpath: "none"result with no explicit disposition tointentional_non_deliveryinstead ofretryable(thesink_unavailablemarker is kept for diagnostics).finalizeResumedAnnounceGiveUp()preserves that disposition across the give-up —clearSubagentPendingDelivery()used to wipe it, which is why the terminal row fell back to a barefailed.hasOutstandingCompletion()disposition check then drains the row immediately.Regression tests cover the drain predicate (drained vs. still-retrying), the dismiss action incl. its ownership gate, the hard-expiry bound (expired
faileddrained; recentsuspendedkept), and the no-route classification (none→intentional_non_delivery, direct→retryable, explicit disposition preserved, give-up keeps the no-route disposition while an ordinary give-up stays a barefailed).Evidence
failed→true→false; still-retryingfailed→true→true; row after manual dismissal →false.node_modules, sovitest/tscwere not executed. The added tests are for CI.cleanupCompletedAtgate for the predicate; fix(subagents): don't re-list delivered child results because of a retained settle marker #166270 fixes a distinct retained-settle-marker case. This PR is complementary — it adds the missing operator surface and the no-route classification, which none of those provide.Still open (not in this PR)