Skip to content

fix(subagents): complete nested fleets after Gateway restarts - #177652

Merged
steipete merged 5 commits into
mainfrom
steipete/nested-restart-handoff
Oct 19, 2026
Merged

steipete merged 5 commits into
mainfrom
steipete/nested-restart-handoff

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

#176861 made flat owner-started sub-agent fleets survive a Gateway restart, but nested fleets (top parent → sub-leads → workers) still stalled after a restart: the workers finished, the sub-leads finished their integration branches, and the top parent was never woken. A later restart sometimes unstuck it. Reproduced live (Linux, real OpenAI and Anthropic keys, shared-token owner via openclaw agent): kill -9 after all workers committed, restart, then nothing for 15+ minutes. Four defects were involved:

  1. Replay identity (embedded requesters). The requester-origin producer (src/agents/requester-origin.ts) emitted explicit undefined fields. JSON persistence dropped them, stableStringify kept them, so every post-restart replay of an already-committed worker completion failed Input completion retry conflicts with the committed input, and the sub-lead received four bogus "Subagent completion delivery is blocked" notices.
  2. Obsolete wake reservation. Startup reserved the requester's cohort input in the FIFO mailbox; paused-run adoption then remapped the cohort's run ids, leaving the old unbound reservation ahead of the real completion, so the top parent's settle wake never dispatched (completion_handoff_pending). The next boot cleared it, which is why another restart "fixed" it.
  3. Replay identity (Codex app-server requesters). For Codex-harness requesters the committed transcript row is the native-annotated mirror of the prompt (mirrorIdentity, mirrorOrigin: "codex-app-server", mirrorSourceFingerprint), so the whole-payload comparison against the original completion could never match.
  4. Orphan recovery ordering. For a sub-lead interrupted inside its settle-continuation turn, restart recovery attempted the orphan interruption commit before checking the incoming settle batch that already owned the continuation, failing with subagent orphan ownership changed before interruption commit and leaving the sub-lead execution=running forever.

User Impact

Nested sub-agent fleets now resume and complete after a Gateway restart, including Codex app-server parents. No migration or user action is required.

Why This Change Was Made

  • The requester-origin producer omits undefined fields before hashing or persistence; existing receipts are reconciled by their complete historical hash. The strict committed-payload comparison is unchanged.
  • The replacement owner retires the obsolete unclaimed reservation after durable publication (existing cleanup owner; claimed inputs, same-id continuation ordering, completed-source obligations, and authority checks preserved).
  • Replay re-applies the saved native-prompt annotation through the same validated producer before the whole-message equality check; changed content or requester facts still fail.
  • Recovery checks incoming settle custody before orphan mutation and again at commit; source, incarnation, live-work, and CAS guards stay intact.
  • No stored-format, protocol, config, or authority changes. docs/tools/subagents/operations.md documents the replay identity guarantee.

Evidence

  • Live: nested fleet (2 sub-leads × 4 workers) on both the Codex app-server route and the embedded Anthropic route, Gateway kill -9 after all workers committed, one restart, no further restarts. Both fleets merged into main within ~2 minutes (35/35 tests each), zero conflicts with the committed input, zero failed to reconcile interrupted. On main the Codex route never completes without a second restart and the embedded route receives spurious "delivery is blocked" notices.
  • Cold-reload regressions through real registry, announce, mailbox, and session-accessor owners: committed replay, adopted replay mailbox admission, Codex mirror replay, and interrupted settle-continuation reconcile each fail on the prior commit and pass now. 438 focused tests pass (registry restart recovery, completion authority, requester-settle restart/wake, announce delivery, user-turn transcript, pending-input replay/mirror/consumed, harness annotation). Targeted typecheck, typed lint, formatting, and isolated review are clean.

Release note context

Fix: nested sub-agent fleets (sub-agents that spawn their own sub-agents) now resume and complete after a Gateway restart, including Codex app-server parents.

Landing validation

Merged current main at b413bdc277e into the reviewed branch, resolving only the annotation-owner conflict. Main's exact-session-key authority lookup and the shared validated annotation producer are both preserved. On fa631ad2d63, all 266 tests across pending-input mirror/origin replay, user-turn transcript/media/persistence, harness annotation, registry restart recovery, and completion authority pass. Changed-file formatting, lint, targeted annotation typed lint, and git diff --check pass. The live proof above is the coordinator's pre-landing proof; it was not repeated for this mechanical conflict resolution.

Normalize requester origins before hashing and persistence so recovered worker completions match their committed envelopes. Reconcile existing raw receipts only against their complete historical hash, preserving strict payload and authority checks.

Cover a committed worker replay through cold reload, sub-lead settlement, and the top-parent handoff. Document the replay identity guarantee.
Release the replaced run’s unclaimed controller inputs after its successor is durably published. A restored cohort reservation otherwise retains the old batch identity and blocks the adopted sub-lead’s completion from waking its parent until another Gateway restart.

Preserve claimed inputs, completed-source obligations, same-ID FIFO ordering, and existing completion authority. Extend cold-reload nested replay coverage through real mailbox admission; the regression fails on c200a67 and passes with this fix. Focused registry, announce, and session-accessor suites pass.
…ions

Reapply committed native annotations through the original producer before comparing replayed completion input. Preserve exact payload checks and reject changed requester facts without adding stored fields.
Check the exact restored requester-settle batch before marking a sub-lead interrupted. Keep the existing live-owner and commit guards for actual orphan recovery, and prove a hard-killed continuation never enters that mutation path.
Merge origin/main to resolve the transcript annotation conflict. Preserve main's exact-session-key lookup and the shared annotation producer used by completion replay.
@clawsweeper

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

@steipete
steipete marked this pull request as ready for review October 19, 2026 19:28
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T19:44:27.228063Z fa631ad Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: L labels Oct 19, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 19, 2026
@steipete
steipete enabled auto-merge (squash) October 19, 2026 19:41
@clawsweeper

clawsweeper Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR repairs completion replay and recovery ordering so nested subagent fleets can finish after a Gateway restart.

Example: An owner starts two sub-leads with four workers each, then the Gateway is killed after the workers commit.

  • Before: Completion replay can conflict or remain behind an obsolete reservation, leaving the top parent waiting.
  • After: Existing completions reconcile and the recovered sub-leads can wake the top parent after one restart.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The repair is coherent and its regressions cover distinct failures; independently inspectable execution evidence remains limited to the in-process test composition.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate and does not materially change authority; its body reports both provider routes recovering after one restart, while inspected regressions exercise the real replay and registry owners with mocked execution delivery.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Nested subagent fleets can stop progressing after a Gateway restart even when their workers and sub-leads finish.
Reason: The maintainer-authored repair restores an existing completion contract without adding configuration, a public API, or another recovery owner.

Merge readiness

✅ Ready for maintainer review

Keep this PR: it repairs source-confirmed nested restart failures through existing owners, and no actionable introduced defect was found.

Priority: P1
Reviewed head: fa631ad2d63c7589cb95f0e39248a61a8309ef5a

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The reported live nested-fleet restart runs have no attached execution trace or media for independent inspection.
Agent review details

How this fits together

The subagent registry coordinates retained child results, requester continuations, and session mailbox admission; recovery consumes persisted execution facts and produces bounded continuation or interruption outcomes.

flowchart TD
  A[Persisted subagent registry] --> B[Restart recovery]
  B --> C[Incoming settle custody]
  C --> D[Requester mailbox]
  D --> E[Pending input replay]
  F[Committed transcript annotation] --> E
  E --> G[Requester continuation]
  G --> H[Parent completion]
Loading

Technical review

Best possible solution:

Retain this focused repair using the existing replay, annotation, replacement, and recovery owners.

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

Source shows the hash mismatch, annotated-transcript comparison, retained reservation, and premature orphan mutation paths; the body reports matching live failures, but this read-only review ran no target code.

Is this the best way to solve the issue?

The smallest complete fix is to stabilize captured identity, reconcile exact historical receipts and annotations, retire replaced reservations, and check existing continuation custody before orphan mutation.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Requester-origin capture keeps the original intent (fd2a6ca: Preserve authenticated requester facts across delegation and recovery; omitting undefined properties preserves those facts while making hashing agree with JSON persistence.)
  • Historical replay identity keeps the original intent (e9999a0: Reconcile sibling replay only against complete accepted requests and exact frozen-cohort provenance; the patch retains those restrictions.)
  • Native transcript annotation keeps the original intent (f5f44fa: Preserve verified native user-turn provenance for canonical history and forks; the shared producer retains its fingerprint and conflict checks.)
  • Incoming continuation custody keeps the original intent (915a974: An admitted child-result continuation must finish before orphan settlement can publish a false interruption; moving the check ahead of mutation implements that intent.)
  • Paused-run replacement keeps the original intent (f71437a: Adoption retains real completion cohorts while discarding pause-only wakes; cleanup now removes the obsolete reservation after the replacement is published.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Introduced patch and main behavior: The pinned introduced diff contains the four reported repairs; fetched main retains the original requester-origin producer, replay comparison, reservation handling, and recovery ordering. (src/agents/requester-origin.ts:81, fa631ad2d63c)
  • Historical receipt compatibility: Legacy requester shapes are accepted only when reconstruction matches the complete accepted hash; changed content and requester facts remain rejected, with interrupted and consumed receipts covered by cold-reload regressions. (src/config/sessions/session-accessor.pending-input-request.ts:37, fa631ad2d63c)
  • Single annotation owner: The patch extracts existing fingerprint and provenance validation for reuse during replay, preserves whole-message equality, and retains main's exact-session-key annotation authority lookup. (src/sessions/user-turn-transcript-annotation.ts:76, fa631ad2d63c)
  • Recovery ordering and reservation cleanup: Incoming settle custody is checked before orphan mutation and in its commit guard; obsolete controller inputs are retired only after replacement publication, using existing cleanup that preserves claimed inputs. (src/agents/subagents/registry/subagent-registry-restart-recovery.ts:337, fa631ad2d63c)
  • Related repair and supplied behavior evidence: The complete body reports successful Linux kill-and-restart runs for embedded Anthropic and Codex app-server fleets; fix(subagents): restore owner-started fleets after Gateway restarts #176861 previously repaired owner recovery authority, a distinct prerequisite rather than a replacement for this work.
  • Current review state: The reviewed head remains mergeable; PostgreSQL conformance and the aggregate CI gate are pending, with no failing code check established. The checkout remained clean. (fa631ad2d63c)

Likely related people:

  • Peter Steinberger: Raw commit da07630 adds src/agents/subagents/registry/subagent-registry-restart-recovery.ts:284 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: da07630c114a; files: src/agents/subagents/registry/subagent-registry-restart-recovery.ts)
  • Josh Avant: Raw commit fd2a6ca adds src/agents/requester-origin.ts:83 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: fd2a6caa89df; files: src/agents/requester-origin.ts)
  • Vincent Koc: Raw commit 1e4beb8 adds src/sessions/user-turn-transcript-annotation.ts:100 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1e4beb8dc346; files: src/sessions/user-turn-transcript-annotation.ts)

PR surface

Source +139, Tests +525, Docs +4. Total +668 across 14 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 7 198 59 +139
Tests 6 572 47 +525
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 774 106 +668

Labels

Label changes:

  • add P1: A Gateway restart can strand an active nested agent workflow despite completed child work.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: A Gateway restart can strand an active nested agent workflow despite completed child work.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 19, 2026, 3:44 PM ET / 19:44 UTC.

@steipete
steipete merged commit 90703b4 into main Oct 19, 2026
204 of 207 checks passed
@steipete
steipete deleted the steipete/nested-restart-handoff branch October 19, 2026 19:45
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 20, 2026
…aw#177652)

* fix(agents): preserve nested completion replay after restart

Normalize requester origins before hashing and persistence so recovered worker completions match their committed envelopes. Reconcile existing raw receipts only against their complete historical hash, preserving strict payload and authority checks.

Cover a committed worker replay through cold reload, sub-lead settlement, and the top-parent handoff. Document the replay identity guarantee.

* fix(agents): retire remapped requester wake reservations

Release the replaced run’s unclaimed controller inputs after its successor is durably published. A restored cohort reservation otherwise retains the old batch identity and blocks the adopted sub-lead’s completion from waking its parent until another Gateway restart.

Preserve claimed inputs, completed-source obligations, same-ID FIFO ordering, and existing completion authority. Extend cold-reload nested replay coverage through real mailbox admission; the regression fails on c200a67 and passes with this fix. Focused registry, announce, and session-accessor suites pass.

* fix(sessions): reconcile completion replay with native prompt annotations

Reapply committed native annotations through the original producer before comparing replayed completion input. Preserve exact payload checks and reject changed requester facts without adding stored fields.

* fix(agents): honor incoming settle custody before orphan recovery

Check the exact restored requester-settle batch before marking a sub-lead interrupted. Keep the existing live-owner and commit guards for actual orphan recovery, and prove a hard-killed continuation never enters that mutation path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. docs Improvements or additions to documentation size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant