Skip to content

fix(agents): preserve restart recovery for delegated child work - #181373

Merged
steipete merged 2 commits into
mainfrom
fix/delegated-dashboard-restart-recovery
Oct 23, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/delegated-dashboard-restart-recovery

Conversation

@steipete

@steipete steipete commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Delegated child sessions can stay interrupted after a Gateway restart, including dashboard-keyed children and follow-ups whose caller waited for an inline result.

User Impact

Parent-owned child work retains its existing recovery owner and normal late completion delivery across restarts. Missing requester authority produces a visible interruption in the child's history. Explicit cancellation remains final, and ordinary cron completion stays quiet.

This cannot reconstruct a missing historic execution record or a lost requester grant. A fresh authenticated sessions.send can continue retained child history under the current caller's authority; sessions.recover still requires the original recovery evidence. Check retained history and uncertain tool outcomes before repeating work.

Why This Change Was Made

Dashboard keys already belong to the native subagent registry. The gaps were in admission: synchronous sessions_send follow-ups lacked a durable execution record, internal replies could omit requester recovery facts when there was no outward delivery route, and an outer drain-error handler could clear the claim as an ordinary failure.

Use the existing registry for child follow-ups regardless of inline wait, consume an inline terminal result through its existing completion obligation, and transfer the already-captured requester authority for late delivery. Save internal requester facts independently of delivery routing and classify live restart refusals consistently. The main-session owner continues to exclude delegated children.

No schema or configuration changes. Production delta: +229 lines (+301/-72); test delta: +342 (+366/-24). The growth preserves the existing authority and completion lifecycle while adding the missing durable admission and visible failure behavior; it introduces no additional recovery owner or state store.

Evidence

The unchanged base fails the dashboard-resume, missing-authority visibility, synchronous-custody, and live-drain claim-retention regressions.

All 72 cases passed across:

  • subagent-detached-recovery.restart-integration.test.ts: real reply admission, persisted SQLite state, dashboard child continuation, late completion, and missing-source visibility after simulated restart.
  • restart-recovery-claim.lifecycle.test.ts: requester facts without delivery, live drain preservation, stale drain and explicit Stop controls.
  • openclaw-tools.sessions-send-child-coordination.test.ts: synchronous and asynchronous custody, yielded/pending observations, inline success/error/timeout, and quiet cron follow-up.
  • server.sessions-send-owner-continuation.test.ts: real Gateway admission and final plugin-write authority for success, child error, revocation, reassignment, and a new user turn.

Independent autoreview: no actionable P0–P2 findings. Changed-file formatting and lint, the core native typecheck, and export-name collision checks passed. An additional 63 authority and import-closure cases passed; both recovery files were rerun successfully after a small lint-driven simplification.

Local proof preceded a patch-identical, conflict-free rebase; PR CI validates the current head.

No benchmark was needed for this correctness repair. Production diagnosis was read-only; no recovery RPC or deployment was performed. Restart simulation stubs model dispatch and delivery transport; the Gateway authority test exercises native admission with a synthetic plugin effect.

CI Follow-up

The first CI run found an unsafe property access in the new transcript assertion and a pre-existing strict steering-options expectation. The assertion now narrows the reader's unknown values; the steering test explicitly expects isInboundUserReply: false. The complete sessions tool file passed 64 cases and the restart integration file passed all 10 cases after these repairs. The repair diff also received independent autoreview with no actionable findings.

The separate progress-card failure in subagent-control.worker.test.ts (settles the progress card according to intentional external silence) reproduces identically on this PR and with all changed production modules replaced by their unchanged base versions at b9689588648536c51480404580835776a2112485: one failure, 25 skipped in each run, expected one retirement and received zero. Commit 535989c929969613a4641a8b32acdf6fffe1c192 (#181260), already in the base, made public settlement honor its required visible-result obligation. This older fixture creates required public results but still expects NO_REPLY to retire the card. The affected settlement path is unchanged by this PR. This is retained as an attributed inherited CI failure, not reported as passing.

Final exact-head CI: run 39906904038, head 3b5f46f78f69f8b7d7a7800d4633d1defeb2b0df. All three PostgreSQL conformance shards, builds, production/test typechecks, lint, security checks, and other test shards passed. The only failed test is the attributed progress-card assertion above, in checks-node-changed-compact-small-3; the CI gate fails downstream from it. Its test and settlement-source blobs are identical across the reproduced baseline, CI's protected-main parent c902f9aa2f647863825e1337cb6eed671256d40a, and tested merge 5b155949226f8593a39cf9627c50f08a144c21a8.

Review follow-up: retain the same guarded host-notice append API used by main-session restart failure reporting (#181180). It resolves the active transcript parent inside the transaction and retains exact-session, lifecycle, expected-recovery-state, and idempotency checks. Direct SessionManager append does not expose the expected-recovery-state contract. The reported branch-placement defect was independently checked and not reproduced from the source path; the broad wording in the agents guide should distinguish model appends from existing host-owned lifecycle notices.

No storage schema or decoder changed. The restart regressions use persisted SQLite state and replace the Gateway generation/resolver in-process; they are not a packaged stable-binary upgrade. An upgrade run from v2026.10.6 was not performed.

@clawsweeper

clawsweeper Bot commented Oct 23, 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 23, 2026 05:27
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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-23T05:42:01.161209Z 3b5f46f New commits
ℹ️ 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.

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 3b5f46f78f69f8b7d7a7800d4633d1defeb2b0df
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/subagents/requester-cron-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: L labels Oct 23, 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 23, 2026
@steipete
steipete force-pushed the fix/delegated-dashboard-restart-recovery branch from 16b70ec to 3b5f46f Compare October 23, 2026 05:38

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3b5f46f78f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

) {
// A denied source cannot notify the parent. The recovery owner still owes
// this exact child a local outcome, without borrowing execution authority.
const notice = await appendAssistantMessageToSessionTranscript({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Route the recovery notice through SessionManager

When an interrupted child lacks a restorable requester source, this writes the synthetic assistant notice through appendAssistantMessageToSessionTranscript rather than the required awaited SessionManager.appendMessageAsync owner. That bypasses the scoped transcript invariant responsible for assigning parentId and persisting the message, so the recovery notice can be attached outside the child transcript's active branch; route this append through the session manager while retaining the existing recovery fences.

AGENTS.md reference: src/agents/AGENTS.md:L15-L15

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 23, 2026
@clawsweeper

clawsweeper Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR preserves registry custody, requester recovery facts, and completion delivery for delegated child follow-ups across Gateway restarts.

Example: A parent sends a follow-up to agent:main:dashboard:existing-child with timeoutSeconds: 1, then the Gateway restarts.

  • Before: The accepted follow-up can lack durable registry custody and remain interrupted.
  • After: The registry retains the follow-up for recovery, while an inline terminal result consumes its completion obligation.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful owner-approved repair with meaningful authority coverage, one scoped writer violation, and an unresolved persisted-state upgrade gate.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Accepted delegated child work can remain interrupted after restart or lose its normal result continuation.
Reason: The maintainer-authored direction restores the existing recovery contract without a new setting, schema, or recovery subsystem.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR open: it repairs a current recovery gap with maintainer-approved direction, but the new interruption notice violates the scoped transcript append contract.

Priority: P2
Reviewed head: 3b5f46f78f69f8b7d7a7800d4633d1defeb2b0df

Before merge

  • Use the required SessionManager owner for the recovery notice (P2) - When requester authority cannot be restored, this new path appends the interruption notice through the config transcript accessor. src/agents/AGENTS.md:15 explicitly requires agent transcript messages to use awaited SessionManager.appendMessageAsync. Route this notice through that owner while preserving the exact-session, lifecycle, recovery-state, and idempotency fences. The accessor already resolves the active parent, so this finding does not assert the earlier review's unproven branch-placement failure.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P2] Use the required SessionManager owner for the recovery notice — src/agents/subagents/registry/subagent-registry-restart-recovery.ts:620

Tests

  • Missing end-to-end proof: Supply an upgrade from v2026.10.6 with retained child history and recovery records, showing preserved state and the intended recovery or visible interruption outcome.
Agent review details

How this fits together

The sessions_send tool admits child work into the subagent registry, which coordinates restart recovery and returns results to the original requester under current authority.

flowchart TD
  A[Requester turn] --> B[Sessions send tool]
  B --> C[Subagent registry]
  C --> D[Restart recovery]
  D --> E[Child execution]
  E --> F[Requester completion]
  C --> F
Loading

Technical review

Best possible solution:

Retain the existing registry recovery owner and completion lifecycle, with the interruption notice appended through the required SessionManager owner.

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

Current main restricts durable follow-up completion custody to zero-timeout callers and can omit requester recovery facts without an outward route; supplied regressions report base failures, but no reproduction was executed during this read-only review.

Is this the best way to solve the issue?

Using the existing registry and requester authority owner is the smallest coherent repair; the added notice should follow the scoped transcript writer contract.

Full review comments:

  • [P2] Use the required SessionManager owner for the recovery notice — src/agents/subagents/registry/subagent-registry-restart-recovery.ts:620
    When requester authority cannot be restored, this new path appends the interruption notice through the config transcript accessor. src/agents/AGENTS.md:15 explicitly requires agent transcript messages to use awaited SessionManager.appendMessageAsync. Route this notice through that owner while preserving the exact-session, lifecycle, recovery-state, and idempotency fences. The accessor already resolves the active parent, so this finding does not assert the earlier review's unproven branch-placement failure.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Synchronous follow-up custody changes intended behavior with a stated reason (f83b7ad: Session input consolidation retained the existing zero-timeout completion-claim restriction; earlier follow-up work placed completion ownership in the registry.)
  • Requester continuation authority keeps the original intent (9c5a1c3: Preserve verified owner identity for child results while revocation, reassignment, and replacement turns continue denying the final effect.)
  • Requester restart facts keeps the original intent (fd2a6ca: Preserve the authenticated requester across queued, forwarded, and recovered execution under applicable current permissions.)
  • Restart refusal handling keeps the original intent (bf76b0c: Resume interrupted peer work while retaining cancellation, access revocation, and exact-session boundaries.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 3357ca7 adds src/agents/subagents/registry/subagent-registry-restart-recovery.ts:435 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3357ca762843; files: src/agents/subagents/registry/subagent-registry-restart-recovery.ts)

PR surface

Source +230, Tests +341, Docs +11. Total +582 across 17 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 12 302 72 +230
Tests 4 365 24 +341
Docs 1 19 8 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 686 104 +582

Review metrics

Metric Value Why it matters
Production versus test delta Production +301/-72; tests +366/-24 The growth covers durable inline custody, authority handoff, recovery facts, and distinct lifecycle regressions without adding another recovery owner or store.

Labels

Label changes:

  • add P2: This repairs a bounded delegated-work recovery failure after Gateway restart.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This repairs a bounded delegated-work recovery failure after Gateway restart.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 23, 2026, 1:57 AM ET / 05:57 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Reviewed the notice-writer finding against the full source path, with a second independent source review. I am retaining the guarded host-owned notice API used by main-session-restart-recovery-failure.ts:84, matching the requested #181180-style interruption behavior.

appendAssistantMessageToSessionTranscript delegates to persistSessionTranscriptTurn; resolveTranscriptMessageAppendParent selects the active parent inside the transaction. The write also rechecks the exact session, lifecycle, expected recovery state, and idempotency key. The reported out-of-branch write is therefore not supported by this implementation. SessionManager.appendMessageAsync does not expose the expected-recovery-state contract, so switching only this caller would lose a guard or duplicate settlement machinery. I acknowledge the literal mismatch with the broad agents-guide wording; the existing host lifecycle owner is the appropriate boundary for this notice.

The PR has no schema or decoder change. The focused proof uses persisted SQLite state and simulated Gateway generation/resolver replacement, including missing-authority and legacy/unverified records. It does not claim a packaged upgrade from v2026.10.6; that unrun scenario is now explicit in the body. No concrete incompatible stored shape was identified.

Exact-head CI has completed. Only subagent-control.worker.test.ts / settles the progress card according to intentional external silence fails, identically on the unchanged baseline and PR. The source attribution and CI links are in the body; the other test shards, PostgreSQL conformance, builds, typechecks, lint, and security passed. Landing uses the standing inherited-failure authorization and does not relabel that test green.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 23, 2026
@steipete
steipete merged commit a8a3680 into main Oct 23, 2026
147 of 150 checks passed
@steipete
steipete deleted the fix/delegated-dashboard-restart-recovery branch October 23, 2026 06:10
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 24, 2026
…claw#181373)

* fix(agents): preserve restart recovery for delegated child work

* test(sessions): tighten restart recovery proof typing and expectations
RomneyDa added a commit that referenced this pull request Oct 28, 2026
)

* fix(agents): preserve restart recovery for delegated child work

* test(sessions): tighten restart recovery proof typing and expectations

(cherry picked from commit a8a3680)

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 2df5f5982cc6bab8d19c90e061602caa62ad04ed)
RomneyDa added a commit that referenced this pull request Oct 28, 2026
)

* fix(agents): preserve restart recovery for delegated child work

* test(sessions): tighten restart recovery proof typing and expectations

(cherry picked from commit a8a3680)

Adaptation-Base: cecd7059127eb19b4d2a2d2143e6bd4cb126b40b
Adaptation-Scope: Durable operator original-requester custody and denied-source child-local interruption; no preexisting process-local hunks replayed
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit bccdf933e1b70e6fb62fe894efa1cb5ca0a2ac2a)
RomneyDa added a commit that referenced this pull request Oct 28, 2026
)

* fix(agents): preserve restart recovery for delegated child work

* test(sessions): tighten restart recovery proof typing and expectations

Candidate adaptation: qualify persisted delegated-child custody with an exited native writer and two fresh native readers; test-only cold-process and fail-closed controls. Non-operator durable grants remain deliberately undefined.

(cherry picked from commit a8a3680)
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 271315112e62861bd6f91c46e1646b5a89cf6610)
RomneyDa added a commit that referenced this pull request Oct 29, 2026
…ns in gateway lane FRV tests (#187589)

* fix(sessions): keep malformed rows out of the legacy transcript locator projection

The #181247 backport (08ee066) adapted the main change for the release
branch's legacy sessionFile locator by projecting json_extract(entry_json,
'$.sessionFile') on every selected row. SQLite raises 'malformed JSON' for an
unreadable entry_json before parseSessionEntryJson can apply its skip/reject
policy, so ordinary selected listings and gateway lookups failed with a raw
SQLite error. Project the locator only for transcript selections and only for
valid JSON rows. Release-only: main retired the sessionFile locator.

* test(logging): isolate log-tail prefix cases from cached inode (#173376)

(cherry picked from commit 40806cf)

* test(gateway): realign sessions_send owner continuation to the #181373 backport

9b8ee9c (#181373 backport) adopts timed sessions_send children into the
requester turn and changes the inline wait to waitForAgentRunReply. The backport
dropped a8a3680's matching fixture changes, so the test spied on the old
SessionFollowupCompletion.take and waited forever. Apply main's fixture hunk
(observe waitForAgentRunReply and registry persistence). The release branch has
no session-controller liveness check (#175837), so a claimed result is handed
back only by the requester run's settlement; the synthetic original run now
performs the settleRequesterRun call its embedded runner makes on completion.

Adapted from a8a3680

* test(agents): keep six-outcome settle fixture undelivered after consumed-cohort backport

The 2f7589a backport of #181260 filters delivered child findings from
settle wakes (needsRequesterSettleFindings). On main, #178104 moved the shared
makeSettledChild default to pending delivery; the release fixture still
defaults to delivered, so this case lost every finding. Mark its children
pending, as the backport did for its other undelivered fixtures.

* test(gateway): keep progress-only settle recovery undelivered after #181260 backport

Backport 2f7589a dropped the source commit's fixture change because
main had moved the recovery case into
server.subagent-settle-replay-recovery.test-support.ts. Apply the same
'progress only' pending-delivery setup to the inline release copy.

(adapted from commit 535989c)

* test(agents): keep private settle policy fixtures undelivered after #181260 backport

Backport 2f7589a filters delivered child findings from settle wakes.
On main, #178104 moved the shared fixture default to pending and renamed
these cases to pending pairs; the release fixture still defaults to
delivered, so the private marker was filtered. Mark the children pending.

* test(agents): mock retireRequesterFollowupAuthority in settle retry fixture

Backport 9b8ee9c (#181373) made execution cleanup call
retireRequesterFollowupAuthority. This release-only fixture mocks
requester-cron-authority.js without that export, so the retry wake threw
and warned. Main no longer has this mock.

* fix(subagents): keep queued collectors out of operator completion custody

The release adaptation 4643f86 of #181373 started capturing the
operator continuation context for every spawn so collectors also record
their original requester source. It dropped the collect guard on binding
completion authority, so a queued collector retained an operator source
hold after its parent completed or stopped. Main binds only non-collect
runs (authority && !registerParams.collect); restore that guard here and
keep completionAuthorityRequired aligned with it.

* test(agents): mark settle retry cron-authority mock as isolation

The added retireRequesterFollowupAuthority export changed the grandfathered
factory hash. Name the isolation reason and prune the stale baseline entry.

---------

Co-authored-by: Patrick Erichsen <[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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. security-sensitive-changed size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant