Skip to content

fix(gateway): recover admitted turns across restart - #130491

Merged
vincentkoc merged 1 commit into
mainfrom
fix/release-runtime-restart-dispatch
Aug 27, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/release-runtime-restart-dispatch

Conversation

@jalehman

@jalehman jalehman commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #130485. A forced Gateway restart could miss an admitted in-flight turn after chat-run cleanup, so startup never dispatched the required restart-safe recovery.

Why This Change Was Made

Restart recovery now derives interrupted-session marking from the authoritative session-work admission owner instead of the narrower chat-run and recovery-candidate maps. Shutdown and maintenance callers share that canonical marking flow, and obsolete duplicate lifecycle plumbing is removed.

Production LOC: +55/-34 (net +21). Tests: +63/-2. The production growth records the missing owner-boundary state and removes the prior narrower path.

User Impact

In-flight channel turns survive forced Gateway restarts through the intended restart-safe recovery policy instead of silently missing the first recovery dispatch.

Evidence

AI-assisted: yes. No agent transcript is included.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Aug 26, 2026
@jalehman
jalehman marked this pull request as ready for review August 26, 2026 23:38
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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 Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 7:46 PM ET / 23:46 UTC.

ClawSweeper review

What this changes

The branch makes Gateway restart recovery find active session-work admissions after transient chat-run registrations have been cleaned up, then marks the durable session for restart-safe recovery.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this PR open: current main still has the empty-transient-map gates that miss an admitted turn, while the proposed owner-boundary repair and regression coverage are coherent. It needs maintainer review after a current-main rebase because it changes persisted restart-recovery state.

Priority: P1
Reviewed head: 1a1f271e7068308345f79d9da73f9731050ab5e0
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused, well-covered repair, with the remaining merge confidence depending on rebasing and validating the exact current-main head.
Proof confidence 🌊 off-meta tidepool Not applicable: This member-authored PR is outside the external-contributor proof gate; its body nevertheless links release-QA evidence for the reported lifecycle failure.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This member-authored PR is outside the external-contributor proof gate; its body nevertheless links release-QA evidence for the reported lifecycle failure.
Evidence reviewed 6 items Current-main gap: Current main returns from restart marking when transient session references are empty, before it can inspect admission ownership; the submitted branch removes that gate.
Canonical owner path: The branch groups active admissions by their authoritative store, includes those stores in restart marking, and matches the persisted session key or ID before marking it interrupted.
Caller alignment: Gateway chat-send admissions register the resolved store path together with the session key and backing session ID, matching the identities the restart marker now consults.
Findings None None.
Security None None.

Live Verification

Command: OPENCLAW_VITEST_MAX_WORKERS=1 pnpm test src/agents/main-session-recovery/main-session-restart-recovery.test.ts -t "marks an admitted channel turn when no chat run remains"

Result: FAIL (failed) — step 1 run OPENCLAW_VITEST_MAX_WORKERS=1 pnpm test src/agents/main-session-recovery/main-session-restart-recovery.test.ts -t "marks an admitted channel turn when no chat run remains": previous terminal command was still running after 30 seconds: "OPENCLAW_VITEST_MAX_WORKERS=1 pnpm test src/agents/main-session-recovery/main-session-restart-recovery.test.ts -t \"marks an admitted channel turn when no chat run remains\""

$ node --import tsx scripts/test-projects.mts src/agents/main-session-recovery/main-session-restart-recovery.test.ts -t 'marks an admitted channel turn when no
chat run remains'
[test] starting test/vitest/vitest.agents-support.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130491-HUTyDM/target

 ✓  agents-support  src/agents/main-session-recovery/main-session-restart-recovery.test.ts (172 tests | 171 skipped) 337ms
     ✓ marks an admitted channel turn when no chat run remains  332ms

 Test Files  1 passed (1)
      Tests  1 passed | 171 skipped (172)
   Start at  23:47:16
   Duration  16.72s (transform 13.14s, setup 1.02s, import 14.99s, tests 337ms, environment 0ms)

[test] passed 1 Vitest shard in 23.75s

Assertions:

  • FAIL expect_output: marks an admitted channel turn when no chat run remains

How this fits together

Gateway shutdown drains or interrupts active reply work before startup recovery resumes interrupted sessions. The session-work admission registry is the durable-work owner when transient chat-run maps no longer identify the turn.

flowchart LR
  A[Gateway restart] --> B[Shutdown reply drain]
  B --> C[Session-work admissions]
  C --> D[Restart session marker]
  D --> E[Durable session record]
  E --> F[Startup recovery dispatch]
Loading

Decision needed

Question Recommendation
After rebasing onto current main, should this admission-owner restart-recovery repair be accepted with focused lifecycle validation? Rebase and land: Preserve the admission-backed marker and land once the rebased head passes focused restart-recovery validation.

Why: The author is a repository member and the PR carries the protected maintainer label; automated cleanup must not close it, while the disconnected local history prevents independently proving the final merge result.

Before merge

  • Resolve merge risk (P1) - The branch is behind current main and the local PR commit is grafted, so an exact current-main merge result and focused restart-recovery validation are still needed before landing.
  • Resolve merge risk (P1) - This changes durable restart-recovery marking; a rebase must preserve the restriction to active, top-level session admissions.
Agent review details

Security

None.

PR surface

Source +21, Tests +61. Total +82 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 6 55 34 +21
Tests 2 63 2 +61
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 118 36 +82

Review metrics

Metric Value Why it matters
Production vs test delta production +21, tests +61 The added production code records admission-owned restart state; test growth covers the missing transient-map boundary.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/store-maintenance-preserve.ts, serialized state: src/sessions/session-lifecycle-admission.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #130485
Summary: This PR is the concrete candidate repair for the linked restart-recovery bug; it remains unmerged.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Validate the rebased recovery path (recommended)
    Rebase, confirm the active-admission marker still selects only the backing session store, and run the focused restart-recovery scenario before merge.

Technical review

Best possible solution:

Rebase onto current main and retain one admission-owner-derived marking path, with the focused restart-recovery scenario proving the resumed turn receives restart-safe tools.

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

Yes, source reproducibly shows current main returning before admission ownership is considered, and the added regression test models that exact empty-chat-run condition; this read-only review did not rerun it.

Is this the best way to solve the issue?

Yes, the repair moves discovery to the admission owner that remains live after chat-run cleanup instead of extending another transient-map fallback.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 0b450013ea0f.

Labels

Label changes:

  • add P1: A forced restart can otherwise leave an in-flight channel turn outside its intended restart-safe recovery lifecycle.
  • add merge-risk: 🚨 session-state: The PR changes which persisted sessions are marked interrupted and how startup selects their restart-safe recovery policy.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This member-authored PR is outside the external-contributor proof gate; its body nevertheless links release-QA evidence for the reported lifecycle failure.

Label justifications:

  • P1: A forced restart can otherwise leave an in-flight channel turn outside its intended restart-safe recovery lifecycle.
  • merge-risk: 🚨 session-state: The PR changes which persisted sessions are marked interrupted and how startup selects their restart-safe recovery policy.
  • 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: This member-authored PR is outside the external-contributor proof gate; its body nevertheless links release-QA evidence for the reported lifecycle failure.

Evidence

What I checked:

Likely related people:

  • steipete: Recent Gateway lifecycle and session-admission history includes the maintenance-lifecycle refactor, shutdown hardening, and offline-placement recovery. (role: recent area contributor; confidence: high; commits: 3dec4e3472b6, 0684f50136e7, bbbd70542b44; files: src/gateway/server-close.ts, src/gateway/server-lifecycle.ts, src/sessions/session-lifecycle-admission.ts)
  • Josh Avant: Previously repaired preservation of active session work during maintenance, an adjacent invariant to admission-backed restart recovery. (role: adjacent owner; confidence: medium; files: src/sessions/session-lifecycle-admission.ts, src/config/sessions/store-maintenance-preserve.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase onto current main and rerun the focused restart-recovery validation against the resulting head.

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.

@vincentkoc
vincentkoc merged commit 2c3a54f into main Aug 27, 2026
288 checks passed
@vincentkoc
vincentkoc deleted the fix/release-runtime-restart-dispatch branch August 27, 2026 05:41
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

vincentkoc pushed a commit that referenced this pull request Aug 27, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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.

[Bug]: Gateway restart misses admitted in-flight turns after chat cleanup

2 participants