Skip to content

fix: keep subagent results owed after a Gateway restart - #200823

Merged
steipete merged 2 commits into
mainfrom
codex/subagent-restart-settle-wake
Nov 17, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/subagent-restart-settle-wake

Conversation

@steipete

@steipete steipete commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

After a Gateway restart, an idle requester can lose finished subagent results when a restored settle attempt loses ownership. An obsolete requester-settle restart marker can also try to resume under unrecoverable operator authority, even though the registry already retains the continuation.

User Impact

Recovered results remain owed to their current registry owner and reach the requester. Restart clears obsolete settle markers through the existing registry handoff. Real Stop, supersession, restart drain, and operator-authority checks retain their existing behavior; there are no protocol, schema, or configuration changes.

Why This Change Was Made

The native completion owner rejects stale execution/cohort mutations in subagent-completion-admission.store.ts:333 and :608. The lifecycle wake catch treated only the narrower progress-change subclass as a handoff; the parent source-change rejection fell through to failed settlement (subagent-registry-lifecycle-wake.ts:529, fixed). It now yields without failing or writing a rejection notice for work belonging to the current owner, using the existing attempt-local cleanup.

The registry's restart classification required the old settle run's exact cohort/retry ID (subagent-registry-read.ts:213, fixed). Recovery can change that ID while retaining the same requester obligation. Classification now recognizes the registry-owned wake after fresh custody recovery, so the existing startup path clears the marker instead of admitting a competing old operator turn. Recovery remains owned by the registry; the Gateway admission and delivery classifier are unchanged.

The observed several-minute spacing cannot be uniquely attributed without the retired rows' deadlines. Existing terminal-descendant delivery grace is five minutes (subagent-announce.requester-settle-descendants.ts:65-75), retry backoff caps at five minutes (subagent-registry-helpers.ts:41-54), and restored preparation permits two concurrent admissions (subagent-registry-lifecycle.ts:82,410-429). This change leaves those budgets and timers intact.

Evidence

The native SQLite/lifecycle regression reopens restored completion state, changes execution ownership, and exercises a coherent overlapping cohort. On the original production code, the refused attempt marks owed delivery failed or tries to settle its successor's cohort. With the fix, both obligations remain pending until the current owner delivers them; already-delivered bookkeeping still survives cleanup.

The real subprocess Gateway regression interrupts a subagent wait during drain, restores an idle requester with an obsolete settle marker whose operator source is unavailable, receives the actual child result, and verifies another restart does not replay that marker. On base it enters principal admission and emits Queued operator authority cannot be recovered; the fixed case passes without that competing turn.

  • Ownership regression: pnpm test src/agents/subagents/completion/subagent-completion-admission.requester-wake.test.ts --maxWorkers=1 -t 'retains restored completion custody': base 2 failed, 1 passed (expected 'failed' to be 'pending' and the native owner rejection), fix 3 passed (34.22s red / 33.06s green wall time). The unfiltered final suite is green: 43 passed, 198.8s wall time including cold compilation, about 59s test time. The existing file proves native commit/reopen, receipt reconciliation, and lifecycle ownership through actual SQLite workers.
  • Real restart regression: the filtered pnpm test test/gateway-subagent-completion-restart.e2e.test.ts --maxWorkers=1 -t stale-settle-requester is red on base. The fixed case passed within the full ten-case file run (16.4 seconds test time). Full file wall time was 353.1s including the runtime build; Vitest took 213.2s.
  • Full restart file: 8 passed, 2 failed. Both existing announcing and announcing-crash failures reproduce with both production files restored to base e1e108c7e4711959b287aff7acab1ac085ea2533: the shutdown checkpoint observes already-consumed delivery instead of pending, and committed public-input replay reports Input completion retry conflicts with the committed input. They remain investigated failures, not passing proof; the latter's underlying replay defect is unresolved here.
  • Restart-resume admission, custody, yield, and recovery consumers: 46 passed across 4 files.
  • Full pnpm build passed (3m42s build phases); targeted core/root typechecks, lint, format, and line ratchets passed. pnpm test src/agents/subagents/ --maxWorkers=2: 2,366 passed, 1 existing skip; 166 files passed and 1 skipped across six shards (1,200.39s wall time).
  • Codex autoreview: scoped clean, no accepted findings. Production shrinks by 40 lines; test changes add 19 net lines for the distinct obsolete-marker process boundary. No budget ceiling changes.

The ownership test covers the native refusal and retained obligation; the subprocess test covers actual drain/recovery delivery. Neither asserts production's exact 35ms abort timing. The added process case needs startup, shutdown, database restore, actual requester delivery, and a second restart; those lifecycle boundaries cannot be proved by an admission helper test alone. Earlier-head CI run 44189485399, attempt 1, reports the same two existing restart cases in checks-node-changed-3 (630 seconds). Its tested merge is 1f43d30753f6dcd2a01185ee0b533af2918ce276 with baseline 807ecef42f00361361abd5e28fdf0fd20332225d. The two local baseline reproductions qualify these failures for native inherited-failure review under the scoped landing instruction; CI remains failed. The fixture adds the new variant, but the original announcing branches and native completion store/replay guard are unchanged. That run also found a PR-caused stale session-identity allowlist count after the deleted failure path (3 actual references became 2); the native prune operation shrank that entry and its ratchet passes. A new push must complete current-head CI. Review, security, and protected-writer checks stay required.

Final-head CI 44194338092, attempt 1, completed all 64 jobs: the corrected baseline ratchet and security check pass. Its only independent failure is checks-node-changed-3 (621s), containing exactly the same two baseline restart cases; the new stale-settle-requester case passes in 23.919s. CI tested merge 84dabb64361951a9a1ab0333d639ca13f8327a10 against baseline 93d84036cc7d7f7ead065a1f1eeaa6ef56735ff7. Native inherited-failure evidence retains the actual checkout, both baseline reproductions, unchanged native completion/replay source objects, and the disclosed fixture diff. CI is failed; these two existing defects are not claimed fixed here.

@clawsweeper

clawsweeper Bot commented Nov 17, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T22:25:43.791721Z cf78d76 PR opened
ℹ️ 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: S labels Nov 17, 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 Nov 17, 2026
@steipete
steipete enabled auto-merge (squash) November 17, 2026 22:37
@steipete
steipete disabled auto-merge November 17, 2026 22:45
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves owed subagent results after ownership changes and lets the registry recover obsolete requester-settle restart markers.

Example: The requester agent:main:dashboard:restart-hub restarts with the marker announce:requester-settle:main:retired-cohort:yield-1 and a captured child result.

  • Before: Startup can attempt a competing continuation and report “Queued operator authority cannot be recovered.”
  • After: Startup clears the obsolete marker and leaves delivery to the registry’s recovered continuation.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation has no identified defect, but supplied proof remains automated and current-head CI retains two reported baseline failures.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A finished child result can disappear from the requester's continuation after a Gateway restart.
Reason: Preserving owed results restores the existing delivery contract, and the maintainer-authored direction reuses established owners without adding configuration or APIs.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR addresses two restart handoff failures still present on main, and no introduced correctness defect was identified.

Priority: P1
Reviewed head: 2f06b5a0dc6e289ca8ac8689d1573d0c6ffda2ed

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted logs or terminal capture from an isolated Gateway with a real agent and model showing the affected restart handoff delivers the retained result once and does not replay the obsolete continuation after another restart.
Agent review details

How this fits together

The subagent registry retains child results and completion wakes; Gateway startup restores custody before the lifecycle owner delivers those results to requester sessions.

flowchart TD
  A[Finished child result] --> B[Persisted subagent registry]
  C[Gateway restart] --> D[Fresh requester custody]
  B --> D
  D --> E[Registry completion wake]
  E --> F[Requester conversation]
Loading

Technical review

Best possible solution:

Keep recovery in the existing registry owner, preserve successor-owned obligations, and suppress duplicate restart continuations.

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

Current-main source exposes both failure paths, and the PR reports red-on-base regressions for native ownership turnover and obsolete-marker startup; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch is the smallest complete repair found: extend the existing ownership-handoff catch, delete its obsolete failure path, and classify registry-owned restart continuations without exact old cohort matching.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Rejected requester-wake settlement and notice changes intended behavior with a stated reason (6671f14: End rejected wakes and record failure instead of retrying indefinitely after completion ownership changes.)
  • Exact requester-settle identity during restart changes intended behavior with a stated reason (18e257d: Recognize a retained completion input so startup does not launch a duplicate recovery turn.)
  • Restart subprocess fixture keeps the original intent (22f4042: Recover captured results for settled requesters whose restart markers are absent.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 18e257d adds src/agents/subagents/registry/subagent-registry-read.ts:230 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 18e257d38139; files: src/agents/subagents/registry/subagent-registry-read.ts)
  • Ayaan Zaidi: Raw commit 3b61a7c adds src/agents/subagents/registry/subagent-registry-lifecycle-wake.ts:558 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 3b61a7c39c85; files: src/agents/subagents/registry/subagent-registry-lifecycle-wake.ts)

PR surface

Source -40, Tests +19, Docs 0, Other 0. Total -21 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 8 48 -40
Tests 2 76 57 +19
Docs 1 6 6 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 6 91 112 -21

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test delta Production +8/-48; tests +76/-57 The repair removes obsolete failure handling while extending existing coverage for ownership turnover and the distinct process-restart boundary.

Labels

Label changes:

  • add P1: Gateway restarts can lose finished delegated results or prevent their requester continuation, breaking an active agent workflow.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: Gateway restarts can lose finished delegated results or prevent their requester continuation, breaking an active agent workflow.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • 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 November 17, 2026, 6:08 PM ET / 23:08 UTC.

@steipete
steipete merged commit 66273da into main Nov 17, 2026
137 of 142 checks passed
@steipete
steipete deleted the codex/subagent-restart-settle-wake branch November 17, 2026 23:18
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
)

* fix: keep subagent results owed after a Gateway restart

* chore: shrink settled wake identity allowance
RomneyDa added a commit that referenced this pull request Nov 19, 2026
Backport #200823 to the temporary beta preparation target.

(cherry picked from commit 66273da)

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit a9614c5480d00481dc132e62b7f217598a2964db)
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 P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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