Skip to content

fix(sessions): wait for subagent restoration before restart recovery - #174134

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-r138-restart-recovery-20260919
Oct 16, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-r138-restart-recovery-20260919

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Main-session restart recovery could attempt a requester continuation before the subagent registry installed its current Gateway binding and restored completion authority. Startup also materialized archived and settled session rows before deciding to skip them.

User Impact

Requester recovery now waits for subagent restoration to settle. Discovery excludes archived sessions, recovery tombstones, and rows without remaining obligations before target preparation; completed sessions with pending delivery or recovery custody still settle. Existing authority and exact-target retry checks remain intact.

Historical records without restorable original operator evidence still require a fresh authenticated continuation. Restarting again cannot manufacture that evidence. There is no schema, retention, configuration, or permission change.

Why This Change Was Made

The startup owner retains its original cutoff and cancellation handle, then joins the existing subagent recovery operation before its first scan. The session worker selects potential recovery owners and applies the existing claim predicate before transferring rows to the Gateway. Separate reader, delivery, and registry startup spans make the previous umbrella timing diagnosable.

Related: #173873, #173878.

Evidence

Metadata-only restart investigation, counting the initial three startup passes:

Class Events Finding
Gateway binding unavailable 10 Ten historical requester sessions ran before registry binding; fixed startup ordering.
Completion authority inactive 20 Same ten sessions on two later passes; original operator-source restoration was rejected for their historical cohorts.
Missing original cohort/operator 3 One historical session repeated three times; the same failure existed on earlier boots.
Archived 273 91 unique rows across three passes, versus 61 across one earlier pass. The prior 61 recur plus 30 additional rows.
Endpoint replaced 11 No input IDs in warnings, so not evidence of stale-consumed recovery. Existing source checks consumed/deleted inputs before endpoints; regression covers both representations.

Every failed requester cohort has execution sightings before the deployment that introduced durable operator evidence. Exact original admission timestamps and the precise missing/mismatched stored field are not available from the journal.

Measurement: recovery umbrella 13.562 s before versus 24.360 s after the investigated deployment, not before/after this patch. It includes history preparation, saved deliveries, and registry activation. A 16.201 s gap before an inactive recovery observation is not partitioned by existing logs; repeat candidate passes took 823 ms and 733 ms. No elapsed-time speedup is claimed. The synthetic worker regression reduces transferred rows from 10 to 5 while retaining every pending-obligation variant.

Focused validation: 157 distinct tests passed across seven files:

  • session-entry-recovery.worker.test.ts and main-session-restart-recovery-admission.test.ts: 25/25, 67.16 s including 20.05 s cold worker compilation. The new selection case took 571 ms; the old reader fails with 10 rows instead of 5.
  • server-startup-post-attach.test.ts and server-startup-observers.test.ts: 91/91, 27.18 s. Both restoration-order cases fail with the old waitForStart gate and pass after the fix; restoration failure and shutdown remain covered.
  • session-send-recovery.test.ts: 21/21, 23.28 s, including removed and retained consumed inputs. An initial run stopped before collection because a source file changed during worker compilation; the frozen-source rerun passed.

Final reader simplification: the five worker cases and four existing memory-reader cases passed (9/9, 30.88 s including 18.61 s cold compilation); the unchanged disk-admission and startup proof above is reused.

Production delta: +57 lines (+83/-26). This correctness repair adds schema-free worker selection, excludes non-durable incognito recovery, and joins the existing startup recovery lifetime; the main-thread claim filter is removed. Timing spans expose the unresolved startup cost. No cache, fallback authority, new scheduler, or speculative speedup is introduced.

Broad gates belong to PR CI; no Testbox/Crabbox lease, heavy benchmark, production restart, or live-state mutation was performed. No full process-restart or live deployment proof was run locally.

Changed-file formatting and lint passed. Fresh independent autoreview is scoped-clean at P0–P2 on the final diff; no actionable findings remain. The reader simplification was re-reviewed after resolving the existing file line limit.

CI follow-up

The initial exact-head CI run found two stale skipped-count expectations in main-session-startup-recovery.test.ts: archived rows now disappear during worker discovery, so they no longer count as skipped candidates or emit archived-candidate diagnostics. Those expectations are corrected; stored-entry, transcript, live-owner, newer-turn, and dispatch assertions remain intact. The single failing file passes all 16 cases locally (18.16 s), with changed-file lint and fresh independent P0–P2 review clean. The correction is test-only; no manual CI rerun was requested.

Final validation: PR CI run 38891592916 and the required CI/security gate passed on a3e307f4101f355a7db11fb01b2267e71911f54e. Merged as b4ce369de7e8d0047365e7410145321d654eaf51 after both required gate records reported success.

Join restored Gateway bindings before admitting requester continuations. Filter archived, tombstoned, and custody-free recovery rows in the session worker while retaining pending terminal settlements. Split startup recovery timings and cover both consumed delivery representations.
@clawsweeper

clawsweeper Bot commented Oct 16, 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 16, 2026 10:58
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 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-16T11:06:33.302114Z 8e657f1 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 gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 16, 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. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR delays main-session recovery until subagent restoration settles and filters unnecessary recovery rows inside the session worker.

Example: Gateway restarts while agent:main:main has an interrupted requester continuation.

  • Before: Recovery can attempt the continuation before its subagent Gateway binding and completion authority are restored.
  • After: The first startup recovery scan waits for restoration to settle, then uses the existing authorization checks.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A useful, focused repair with meaningful boundary regressions and no identified correctness defect; supplied execution evidence remains in process.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; supplied evidence exercises the real session worker and mocked startup dependencies, with no claimed full process-restart demonstration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An interrupted requester continuation can fail recovery because startup attempts it before its subagent binding and completion authority are restored.
Reason: The maintainer-authored direction addresses an evidenced ordering failure and avoids preparing rows that existing recovery policy already excludes.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR fixes a concrete startup-ordering defect still present on main. No actionable introduced defect was found.

Priority: P2
Reviewed head: a3e307f4101f355a7db11fb01b2267e71911f54e

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not exercise an isolated Gateway process restart through requester continuation; its reported base-failing regressions cover worker selection and startup ordering.
Agent review details

How this fits together

Gateway startup coordinates subagent restoration and main-session recovery; the session reader worker supplies durable recovery candidates to the existing admission and dispatch owners.

flowchart TD
  A[Gateway startup] --> B[Post-ready recovery observers]
  B --> C[Subagent restoration settles]
  C --> D[Main-session recovery scheduler]
  D --> E[Session worker selects obligations]
  E --> F[Existing admission and dispatch]
Loading

Technical review

Best possible solution:

Join the existing restoration lifetime before startup recovery while preserving current authorization, cancellation, and pending-delivery ownership.

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

Current-main source permits recovery after post-ready release while subagent restoration is still pending; the supplied ordering regressions reportedly fail on that behavior, but no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch fixes ordering at the startup owner and reuses the existing worker and claim predicate, avoiding a competing recovery scheduler or authorization fallback.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Post-ready startup barrier keeps the original intent (65f3e42: Give probes and clients an initial I/O window before readiness-neutral background work begins.)
  • Recovery preparation and custody keeps the original intent (134631a: Keep recovery preparation sequential while allowing execution to proceed independently and retaining deferred-store recovery.)
  • Memory-only incognito reads keeps the original intent (3de654b: Keep incognito state in its memory owner, with no durable fallback or survival across process exit.)
  • Archived and terminal recovery policy keeps the original intent (4754d39: Resume legitimate interrupted sessions while preventing archived sessions from repeatedly appearing as blocked recovery work.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 6ffbf91 adds src/gateway/server-startup-observers.ts:106 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6ffbf9102e59; files: src/gateway/server-startup-observers.ts)

PR surface

Source +57, Tests +78, Docs +7. Total +142 across 12 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 83 26 +57
Tests 5 130 52 +78
Docs 1 8 1 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 221 79 +142

Review metrics

Metric Value Why it matters
Production versus test growth Production +57 net lines; tests +78 net lines. The worker selector and existing-lifetime join explain the production growth; tests cover selection, restoration ordering, and consumed-input representations.

Labels

Label changes:

  • add P2: A focused correction to restart recovery for interrupted requester sessions, without evidence of a broader runtime outage.
  • 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:

  • P2: A focused correction to restart recovery for interrupted requester sessions, without evidence of a broader runtime outage.
  • 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 16, 2026, 7:22 AM ET / 11:22 UTC.

@steipete
steipete merged commit b4ce369 into main Oct 16, 2026
146 of 147 checks passed
@steipete
steipete deleted the steipete/perf-micro-r138-restart-recovery-20260919 branch October 16, 2026 11:24
steipete added a commit that referenced this pull request Oct 16, 2026
Reconcile orphaned receiver custody through the existing recovery owner before
agent admission touches the session row. Retain exact-session, live-writer,
worker-placement and command-claim checks, plus the restored registry gate.

Main 9215eac reproduces all five lost deliveries; the parent of #174134
passes the unchanged cold-restart regression. All 66 focused tests pass with
maxWorkers=1 (227.07s wrapper, including runtime build; native case 40.20s).
Core types, targeted lint/format and independent P2 review pass.

Release-note context: accepted peer updates recover across startup ordering
without manual resend; cancelled/reset/revoked sources remain blocked.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
…penclaw#174134)

* fix(sessions): wait for subagent restoration before restart recovery

Join restored Gateway bindings before admitting requester continuations. Filter archived, tombstoned, and custody-free recovery rows in the session worker while retaining pending terminal settlements. Split startup recovery timings and cover both consumed delivery representations.

* test(sessions): align startup counts with worker recovery filtering
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
…w#174203)

Reconcile orphaned receiver custody through the existing recovery owner before
agent admission touches the session row. Retain exact-session, live-writer,
worker-placement and command-claim checks, plus the restored registry gate.

Main 78c0e92 reproduces all five lost deliveries; the parent of openclaw#174134
passes the unchanged cold-restart regression. All 66 focused tests pass with
maxWorkers=1 (227.07s wrapper, including runtime build; native case 40.20s).
Core types, targeted lint/format and independent P2 review pass.

Release-note context: accepted peer updates recover across startup ordering
without manual resend; cancelled/reset/revoked sources remain blocked.
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 P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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