Skip to content

fix(agents): preserve child results while parent recovery is running - #140930

Merged
roboclaw-bot merged 1 commit into
mainfrom
openclaw/subagents-missing-after-gateway-restart
Sep 7, 2026
Merged

roboclaw-bot merged 1 commit into
mainfrom
openclaw/subagents-missing-after-gateway-restart

Conversation

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Closes #140911

What Problem This Solves

Fixes an issue where users restarting the Gateway during delegated work could lose the child-completion handoff while the parent was still recovering. The child could finish successfully, but the parent-settle turn failed before entering its normal session lane and spent its retry budget. The parent could then repeat already completed work.

Why This Change Was Made

The accepted subagent_settle command now waits for the existing named recovery admission owner to release the parent, preserving the same accepted dispatch and idempotency key. It refreshes preparation afterward and uses the unchanged durable recovery guard to authorize execution. The owner is also rechecked around the asynchronous claim, covering recovery starting after the first check.

Cancellation, Gateway generation changes, target replacement/rerouting, tombstones, and ownerless recovery residue still fail closed. Existing recovery and preparation leases remain owned by cleanup. Ordinary commands, transferred recovery leases, internal recovery effects, retry budgets, database schemas, and UI retention policies are unchanged.

User Impact

Completed delegated work can reach its parent after recovery instead of failing simply because that recovery is still active. No new configuration or manual recovery step is required for future handoffs. This does not revive already-exhausted delivery batches or change cross-restart ambiguous-delivery guarantees.

Evidence

  • Root owner regressions fail on the original base and pass with the repair, including recovery appearing during the writer-ordered claim.
  • Composed regression exercises the settled batch, direct in-process handoff, and actual SQLite-backed recovery guard. It waits five simulated minutes with one accepted dispatch, no child-result execution, and no recorded failure; owner release produces exactly one direct final and retires the batch. On the original base it records failed admission instead.
  • Eight focused/sibling files passed 240 tests, covering command recovery, recovery state/store, requester-settle dispatch/wakes, session admission, and reply-turn admission.
  • A final cancellation-during-claim regression also failed before its final revalidation change. Final touched suites passed 41 tests (28 owner + 13 dispatch).
  • Full selected check:changed passed: formatting, core/test typechecking, changed lint, dead-export scans, schema/store guards, and import-cycle checks. git diff --check passed.
  • Fresh independent autoreview through P2: scoped-clean; no actionable findings.

Proof uses isolated synthetic SQLite fixtures and in-process delivery; provider execution is stubbed. No live provider, production Gateway, or UI test is claimed. Initial test/check/review attempts interrupted by a Gateway restart were not counted as passing; completed reruns supplied the evidence above.

Production change: +70/-2 lines. Tests: +345/-1 lines. The additional production logic owns the accepted wait, snapshot refresh, and cancellation/identity checks; it does not introduce a new queue or persistent state.

Worked on by


View the OpenClaw team session

Wait for the existing named recovery admission owner before a subagent
settle command claims its parent. Keep the accepted dispatch and idempotency
key, refresh preparation after release, and revalidate cancellation, target
identity, and lifecycle generation before execution.

Closes #140911

Worked on by:
- @Takhoffman

Co-authored-by: Tak Hoffman <[email protected]>
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 7, 2026 06:37
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 7, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 2:44 AM ET / 06:44 UTC.

ClawSweeper review

What this changes

The PR keeps accepted child-completion handoffs pending while parent recovery runs, then refreshes session preparation and checks cancellation and identity before continuing.

Merge readiness

✅ Ready for maintainer review

This remains a useful repair for an observed child-completion failure that current main and the latest release still permit. No actionable introduced defect was found, and the maintainer-protected PR should remain open.

Priority: P1
Reviewed head: cefecf7a715d8c4a67a2b6312cd1b38510427a6f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful race and cleanup coverage and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The bot-authored PR is exempt from the external-contributor proof gate. Its composed test exercises the command recovery owner and direct handoff with real SQLite state but mocked turn execution; no live Gateway or provider result is claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The bot-authored PR is exempt from the external-contributor proof gate. Its composed test exercises the command recovery owner and direct handoff with real SQLite state but mocked turn execution; no live Gateway or provider result is claimed.
Evidence reviewed 8 items Introduced change boundary: The pinned merge-base-to-head delta contains one production owner and two regression suites. Host-verified test-merge evidence contains those same three paths, so unrelated base-branch changes were excluded from review.
Repair still absent from current main: Fetched main still claims recovery ownership immediately after preparation and propagates invalidation without waiting for the named recovery owner. The production file has no difference between the pinned merge base and fetched main.
Latest-release check: The v2026.9.2 version also performs the immediate claim without the proposed wait. The supplied latest-release identity is 3928bad.
Findings None None.
Security None None.

How this fits together

Subagent completion delivery sends finished child results back through the parent’s agent-command entrypoint. Recovery ownership controls when that parent can safely process the handoff.

flowchart TD
  A[Finished child result] --> B[Accepted parent handoff]
  B --> C{Parent recovery active?}
  C -->|Yes| D[Wait for recovery release]
  D --> E[Refresh session and validate]
  C -->|No| E
  E -->|Valid| F[Parent consumes result]
  E -->|Cancelled or changed| G[Reject and clean up]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +68, Tests +344. Total +412 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 70 2 +68
Tests 2 345 1 +344
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 415 3 +412

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +70/-2; tests +345/-1 Production growth implements the accepted wait and revalidation; regression coverage targets contention timing, invalidation, cleanup, and single delivery.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #140911
Summary: This PR explicitly proposes the repair for the linked recovery-contention incident; the issue remains open until implementation lands.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Preserve the accepted handoff through temporary recovery contention while retaining the existing durable admission guard, cancellation behavior, and delivery identity.

Do we have a high-confidence way to reproduce the issue?

Yes, source provides a high-confidence path: complete a child while its parent has an active recovery owner, causing the immediate foreground claim to reject before normal lane waiting. The supplied regressions target that ordering; this review did not execute them.

Is this the best way to solve the issue?

Yes. Waiting at the early command-recovery boundary addresses the rejection before downstream queueing can help, reuses existing owner-release notification, and preserves the durable guard without increasing retry budgets.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 240aa9e573c4.

Labels

Label changes:

  • add P1: The linked incident establishes a broken delegated-work handoff after restart that can cause completed child work to be repeated.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The bot-authored PR is exempt from the external-contributor proof gate. Its composed test exercises the command recovery owner and direct handoff with real SQLite state but mocked turn execution; no live Gateway or provider result is claimed.

Label justifications:

  • P1: The linked incident establishes a broken delegated-work handoff after restart that can cause completed child work to be repeated.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The bot-authored PR is exempt from the external-contributor proof gate. Its composed test exercises the command recovery owner and direct handoff with real SQLite state but mocked turn execution; no live Gateway or provider result is claimed.

Evidence

What I checked:

  • Introduced change boundary: The pinned merge-base-to-head delta contains one production owner and two regression suites. Host-verified test-merge evidence contains those same three paths, so unrelated base-branch changes were excluded from review. (src/agents/agent-command-recovery-owner.ts:183, cefecf7a715d)
  • Repair still absent from current main: Fetched main still claims recovery ownership immediately after preparation and propagates invalidation without waiting for the named recovery owner. The production file has no difference between the pinned merge base and fetched main. (src/agents/agent-command-recovery-owner.ts:177, 240aa9e573c4)
  • Latest-release check: The v2026.9.2 version also performs the immediate claim without the proposed wait. The supplied latest-release identity is 3928bad. (src/agents/agent-command-recovery-owner.ts:177, 3928bad9badf)
  • Lifecycle and cleanup checks: Waiting is restricted to ordinary subagent-settle claims. After release, preparation is refreshed, session/store identity is compared, and the existing durable claim remains authoritative; cancellation and lifecycle generation are checked before execution. Acquired recovery and preparation leases remain covered by finally cleanup. (src/agents/agent-command-recovery-owner.ts:183, cefecf7a715d)
  • Focused regression coverage: The owner suite exercises recovery present before preparation or starting during claim, plus eight cancellation, replacement, tombstone, ownerless-state, and generation outcomes. The composed suite asserts one accepted dispatch remains pending for five simulated minutes and produces one direct final after recovery release. These tests were inspected, not executed during this read-only review. (src/agents/subagents/announce/subagent-announce.requester-settle-dispatch.test.ts:362, cefecf7a715d)
  • Existing completion contract: Subagent documentation specifies stable-idempotency parent handoff and waiting for busy requesters. Existing reply-turn admission already observes the same named recovery owner, but that separate path does not prevent the earlier agent-command claim failure repaired here. Public docs: docs/tools/subagents.md. (docs/tools/subagents.md:106, cefecf7a715d)

Likely related people:

  • Brett Daman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@roboclaw-bot

roboclaw-bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

Maintainer-side verification for cefecf7a715d8c4a67a2b6312cd1b38510427a6f:

  • Reviewed the command admission owner, existing named recovery admission, its release lifetime, and direct requester-settle caller. The durable execution guard remains unchanged.
  • Confirmed original-base red owner and composed-dispatch regressions, followed by candidate green. Eight focused/sibling files passed 240 tests; the final touched suites passed 41 tests after final cancellation revalidation.
  • Selected node scripts/check-changed.mjs --base 9230180f699e738d39bac1feecd0187b845026a0 -- src/agents/agent-command-recovery-owner.ts src/agents/agent-command-recovery-owner.test.ts src/agents/subagents/announce/subagent-announce.requester-settle-dispatch.test.ts passed. Fresh independent P2 autoreview and native review-artifact validation passed.
  • Read the completed ClawSweeper review: no actionable findings, no before-merge requirements.
  • Exact-head required CI is green: run 34091679793 attempt 2 completed successfully on the unchanged head, including the narrowly rerun checks-node-compact-small-8 shard. openclaw/ci-gate is successful and the live check rollup has no non-green checks. https://github.com/openclaw/openclaw/actions/runs/34091679793/attempts/2. No check bypass was used.

Limit: proof uses isolated synthetic SQLite fixtures and in-process delivery with stubbed provider execution, not a live production Gateway or provider. The patch does not revive already-exhausted batches.

@roboclaw-bot
roboclaw-bot merged commit 663f352 into main Sep 7, 2026
366 of 368 checks passed
@roboclaw-bot
roboclaw-bot deleted the openclaw/subagents-missing-after-gateway-restart branch September 7, 2026 07:03
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 8, 2026
…claw#140930)

Wait for the existing named recovery admission owner before a subagent
settle command claims its parent. Keep the accepted dispatch and idempotency
key, refresh preparation after release, and revalidate cancellation, target
identity, and lifecycle generation before execution.

Closes openclaw#140911

Worked on by:
- @Takhoffman

Co-authored-by: Tak Hoffman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recovered subagent completion can fail to reach a recovering parent

1 participant