Skip to content

fix(subagents): keep restart recovery running past stale transfer records - #165335

Merged
steipete merged 1 commit into
mainfrom
fix/subagent-recovery-superseded-episode
Oct 5, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/subagent-recovery-superseded-episode

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: after a Gateway restart, subagent restart recovery can fail to start entirely (Initial requester transfer episode was superseded), so no interrupted subagent is recovered.

User Impact

User impact: one stale subagent registry record no longer blocks restart recovery for every other subagent. Interrupted subagents recover, or are terminalized under the existing policy so their parent can continue. A warning names any skipped stale run. There are no config or schema changes.

Why This Change Was Made

During restart, registry hydration restored stale and current requester completion claims for the same requester turn together. The requester transfer guard correctly rejected the superseded claim, but that rejection escaped the activation await and aborted the whole subagent-registry activation.

The requester-turn selector now applies the existing completion-cohort currency check (isRequesterCompletionCohortCurrent) to drop superseded records. Activation logs a warning per skipped run and skips a requester turn whose cohort is entirely superseded. The settlement owner already rejects zero accepted spawns. The four live callers of the selector were audited: each should only see current completion obligations, and admission revalidation still enforces membership, identity, and live authority. To stay under the restorer's line cap, the existing Gateway-owner recovery function moved unchanged into subagent-registry-gateway-owner.ts.

Observed in production alongside a main-session restart recovery bug (fixed separately): subagent restart recovery failed to activate: SubagentRegistryWriteError: Queued subagent registry persistence failed: Initial requester transfer episode was superseded.

Evidence

  • src/agents/subagents/registry/subagent-parent-recovery.restart-integration.test.ts reproduces the original order: children restart-aborted, then the main requester marked interrupted, then hydration restoring stale and current claims. Before: 2 failed / 14 passed with the exact production error. With the all-superseded case added and the fix applied: 17/17 pass. pnpm test <file> --maxWorkers=1 took 205s locally (an existing heavy file; it was 212s before this change); an earlier Testbox run of the file took 44s.

  • Earlier remote sibling runs passed requester-yield 43/43 and wake-commit 25/25.

  • Codex autoreview was scoped-clean through P2 on the final diff.

  • Gap: the full remote check-changed gate did not run locally, because shared Crabbox/Testbox capacity was saturated. PR CI is the gate for it.

  • Conflict resolution: rebased the reviewed eefa38d0bb728b24da550a9ee76f2b08e4a4d84f candidate onto main b57e493c831749ac097e7f7e8f28f48bb85add3c. Main had extracted requester restoration into settleRestoredRequesterTurns; the current-child selection, stale-run warning, and empty-cohort guard now run in that helper. Main retains failed-cohort isolation, retry custody, and one-time collector resumption. The earlier 17/17 local result remains prior-head evidence; no earlier passing PR CI run exists. After resolution, pnpm test src/agents/subagents/registry/subagent-parent-recovery.restart-integration.test.ts --maxWorkers=1 passed 17/17 (415.43s wall), and pnpm test src/agents/subagents/registry/subagent-registry-queued-recovery.test.ts --maxWorkers=1 passed 8/8 (167.10s wall).

  • Fresh Codex autoreview of the full conflict-resolved candidate was scoped-clean through P2, with no actionable findings.

Release note: subagent restart recovery keeps going past stale requester transfer records instead of failing for every subagent after a Gateway restart.

@clawsweeper

clawsweeper Bot commented Oct 5, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 5, 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 Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 1:58 AM ET / 05:58 UTC (Revision 2).

ClawSweeper review

What this changes

The branch excludes stale subagent completion claims during restart recovery, warns about skipped runs, adds recovery regressions, and extracts the existing Gateway ownership helper.

Merge readiness

✅ Ready for maintainer review

The PR remains useful: main isolates failed recovery groups but still includes superseded records within an affected group. The resolved patch preserves that isolation and its retries, addresses the previous review request, and introduces no actionable correctness findings.

Priority: P1
Reviewed head: 75c4381805925f8409cdd94e0d5489586f1dff9c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful persistence regressions and preserved recovery safeguards; the previous conflict-resolution request is addressed.
Proof confidence 🌊 off-meta tidepool Not applicable: Verified repository-admin authorship exempts this PR from external-contributor proof requirements. Reported post-resolution tests exercise registry activation against persisted stale claims with mocked transport; they are supplemental evidence, not live recovery proof. No stored-data format or schema contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Verified repository-admin authorship exempts this PR from external-contributor proof requirements. Reported post-resolution tests exercise registry activation against persisted stale claims with mocked transport; they are supplemental evidence, not live recovery proof. No stored-data format or schema contract changes.
Evidence reviewed 8 items Pinned introduced change: Reviewed the complete merge-base-to-head patch, including original deleted code. Gateway ownership recovery is moved without changing its implementation, and both production and worker-test imports are migrated.
Still necessary on current main: Fetched main still groups all matching requester claims without the currency filter or empty-current-group guard. The merged recovery work at #165184 provides failure isolation and retries, rather than this stale-member exclusion.
Shared selection and admission invariant: The selector reuses the existing task-generation and superseded-cancellation predicate. Transfer admission continues checking that predicate, exact captured identity, cancellation state, membership, and current database/Gateway authority before publication and scheduling; the patch does not create broader execution authority.
Findings None None.
Security None None.

How this fits together

The subagent registry restores saved child tasks after a Gateway restart and transfers their completion obligations back to the parent. Its recovery selector determines which retained records can participate in that transfer.

flowchart TD
  A[Saved subagent records] --> B[Registry hydration]
  B --> C[Current completion selection]
  C --> D[Skip stale claims and warn]
  C --> E[Transfer current obligations]
  E --> F[Owner and membership checks]
  F --> G[Child settlement and parent continuation]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +38, Tests +137, Docs +7. Total +182 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 5 102 64 +38
Tests 2 138 1 +137
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 247 65 +182

Review metrics

Metric Value Why it matters
Production and regression growth production +38 net lines; tests +137 net lines Production growth is justified by shared currency selection and stale-run diagnostics; the helper extraction preserves existing behavior.

Technical review

Best possible solution:

Use one current-completion selector for restoration and live settlement while preserving historical cleanup, transfer fencing, and independent recovery retries.

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

Yes, source establishes a focused path: hydrate stale and current completion claims for one requester turn, then activate recovery; the existing transfer guard rejects the stale member. The reviewer did not execute this path.

Is this the best way to solve the issue?

Yes. Reusing the admission owner's existing currency predicate avoids competing policy and preserves main's recovery isolation and retry ownership.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7b295df476ae.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The reported production failure strands interrupted subagent completion and parent continuation after restart.
  • 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: Verified repository-admin authorship exempts this PR from external-contributor proof requirements. Reported post-resolution tests exercise registry activation against persisted stale claims with mocked transport; they are supplemental evidence, not live recovery proof. No stored-data format or schema contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-05T04:39:51.036Z sha eefa38d :: needs changes before merge. :: none

…episodes

Select current completion owners before restoring requester transfers and
use the same cohort for saved yield policy and accepted receipts. Warn for
superseded claims and skip empty cohorts so retained historical rows cannot
block recovery of current siblings and nested children.

Extract Gateway-owner recovery unchanged to keep the restorer below its
existing line cap, and migrate the production and native-worker callers.

Validation: 17 restart integration cases pass locally (205.79s wall,
including cold worker preparation). The all-superseded case fails without
the guard. Full-diff review is scoped-clean through P2. Remote gates follow
this commit under maintainer direction.
@steipete
steipete force-pushed the fix/subagent-recovery-superseded-episode branch from eefa38d to 75c4381 Compare October 5, 2026 05:52
@steipete
steipete marked this pull request as ready for review October 5, 2026 05:53
@steipete
steipete merged commit fcc6b90 into main Oct 5, 2026
188 checks passed
@steipete
steipete deleted the fix/subagent-recovery-superseded-episode branch October 5, 2026 06:24
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
…episodes (openclaw#165335)

Select current completion owners before restoring requester transfers and
use the same cohort for saved yield policy and accepted receipts. Warn for
superseded claims and skip empty cohorts so retained historical rows cannot
block recovery of current siblings and nested children.

Extract Gateway-owner recovery unchanged to keep the restorer below its
existing line cap, and migrate the production and native-worker callers.

Validation: 17 restart integration cases pass locally (205.79s wall,
including cold worker preparation). The all-superseded case fails without
the guard. Full-diff review is scoped-clean through P2. Remote gates follow
this commit under maintainer direction.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime 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.

1 participant