Skip to content

fix: preserve queued ingress messages during gateway restart - #196923

Merged
joshavant merged 3 commits into
mainfrom
fix/queued-restart-shutdown
Nov 11, 2026
Merged

joshavant merged 3 commits into
mainfrom
fix/queued-restart-shutdown

Conversation

@joshavant

@joshavant joshavant commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes accepted queued app messages being silently cancelled when the Gateway shuts down for a restart.

User Impact

Queued ingress messages survive a graceful restart and continue under their original source limits and current permissions. New requests are refused as soon as shutdown begins. No schema, configuration, or migration change is required.

Why This Change Was Made

Close request admission and scheduled wakeups first, then retire retained authority after the existing marker and session-stop owners have recorded restart custody. This keeps shutdown from being mistaken for grant revocation while preserving live permission checks.

Evidence

The real compiled CLI reproduces the queue loss on base 5ef2ef59edee69d1597d7aedcc1ec12b08c6a2ff: SIGTERM exits cleanly, the distinct replacement becomes ready, but the accepted queued marker never reaches the model. The new Gateway/SQLite regression also fails on that base; its actual-revocation control passes. Both owner cases pass with this change, including immediate new-request/new-binding refusal and exact source/message/run preservation.

Compiled candidate 4646580a4953e6b600ca29624590ebe49f1446b5 was exercised through real owner login, invitation/People approval, member shell, app consent, normal SIGTERM, and a distinct normal CLI process with a fresh signed relay handshake:

Scenario Observed result
Valid replay Two exact queued writes complete in FIFO order; the second provider dispatch sees the first file.
Signed operator-to-viewer change after replay starts Held stream and member socket close; original run settles error/rpc; no queued write; fresh viewer can read and cannot write.
People removal after replay starts Recovered work is cancelled; no queued write; original app and fresh member are denied.
App revocation after replay starts New calls are denied; releasing the late tool response settles the original run error/rpc without writing. Separate member ID access remains usable.

Every successful scenario also verifies an independent owner app write, clean old/new Gateway exits, and no queued write-capable dispatch during old-process shutdown. Saved receipts, original run IDs, files and artifact hashes were independently checked. All 113,452 archived candidate files still match after execution; the separately built native binding is pinned independently. Build metadata names the base plus the pre-commit source snapshot; all 17 files from the compiled source snapshot match reviewed commit 4646580a4953e6b600ca29624590ebe49f1446b5. Subsequent CI corrections complete one integration fixture and move existing mention-inbox disposal into synchronous shutdown preparation. The latter is covered by the existing production Gateway lifecycle/SQLite regressions described below; the full compiled browser campaign was not repeated on the final head.

Remaining limits: revoking a recovered app does not eagerly close its already in-flight provider stream (a separate 60-second check failed); the next authority check refuses the late tool effect, as the distinct final-effect run proves. One earlier authorized control timed out in sessions.create before provider I/O; its cause remains unresolved, and the later pass is not claimed as a timeout fix. Two incorrect harness assertions were corrected against the current terminal/transport contracts; their failed runs are retained.

  • Focused Gateway, scheduler, ingress transport, plugin-service and scheduled-continuation tests pass. Core and affected test typechecks, targeted lint/format, test-line ratchet and runtime build pass. The first CI typecheck failure was a missing admissionSignal in the existing Control UI fixture; the same typecheck and all 10 integration cases pass after correction. The next CI run caught mention-inbox admission staying open during marker preparation; the unchanged public-close test reproduced the failure locally. Moving its existing disposal earlier restores immediate refusal while preserving accepted writes. All 12 focused Gateway kernel, accepted auth/mention close, and queued-ingress cases pass on the final source, as do production types and targeted lint/format. The final-head CI typecheck and previously failing Gateway shard both pass. PostgreSQL 17 conformance passed all three shards. The additional PostgreSQL 16 Gateway cron smoke remained incomplete when its parent job hit the confirmed 30-minute limit; its log showed passing tests and no failed assertion before cancellation. This remains a deferred validation blocker; no retry or timeout increase is claimed as a fix.
  • Final-head CI has an inherited seven-line test-budget failure: CI merge 9847ccca5d5f55fee61be1ca06bc4d8a62689dd3 counts 6,643,529 lines against a 6,643,522 ceiling. Its main parent 041c3b7164636b25d9e7bf9aa3c14058c507d408 already has 6,643,257 lines against a 6,643,250 ceiling. Exact Git LF comparison verifies this PR adds 272 lines and exactly 272 allocation credit, with the shared scalar unchanged. The overage is retained as a deferred blocker. The canonical classifier calls it new against an older passing scheduled main; this attribution uses the actual CI main parent.
  • New close suite: 27.42 seconds in Vitest, 35.75 seconds with wrapper. The separate 272-line regression allocation covers owner/persistence behavior plus scheduler and transport lifecycle contracts; the shared scalar is unchanged.
  • Canonical local autoreview of the final staged candidate against pinned base 5ef2ef59edee69d1597d7aedcc1ec12b08c6a2ff completed through P2 with no actionable findings. An earlier pass correctly flagged the unrepaired index version of the mention fence while accepting the working-tree correction; the fix was then staged and reviewed. Local ClawSweeper was unavailable. The completed hosted follow-up reviewed source head 4646580a4953e6b600ca29624590ebe49f1446b5, accepted the compiled runtime/final-effect proof, and reported no findings or before-merge requests. The final review additionally covers the later CI corrections in f872177f2befa67b68399502fc5e07e94009493b.

Runtime proof uses a separately source-built native transport and deterministic external mail, app and model services in an isolated Linux VM. It does not qualify npm distribution, a live model provider, or deployed services. Loader browser glue/WASM was reused from the retained fixture rather than rebuilt in this campaign. No live services were changed.

Sanitized compiled CLI runtime receipts

Each terminal is selected from the actual agent.wait response for the original queued run ID. File outcomes were checked independently in the retained workspace. External services are fixtures, with the limits described above.

{"scenario":"valid-replay","oldPid":996,"newPid":1416,"oldExit":{"code":0,"signal":null},"queuedRunIds":["c006cc69-a3c8-4d90-b635-2c049661bbda","fec3ea68-c821-4dab-ba8f-46f021f613f7"],"terminal":{"runId":"fec3ea68-c821-4dab-ba8f-46f021f613f7","status":"ok","stopReason":"stop"},"independentOwnerWrite":true,"exactQueuedFiles":2,"firstEffectPresentAtSecondDispatch":true}
{"scenario":"member-removal","oldPid":3812,"newPid":4240,"oldExit":{"code":0,"signal":null},"queuedRunIds":["a063478b-d79b-4be5-aa7d-1e436acf99de"],"terminal":{"runId":"a063478b-d79b-4be5-aa7d-1e436acf99de","status":"error","stopReason":"rpc"},"independentOwnerWrite":true,"queuedWritePresent":false,"originalAppDenial":"unavailable","providerClosedBeforeRelease":true,"freshRemovedMemberDenied":true}
{"scenario":"role-downgrade","oldPid":2395,"newPid":2819,"oldExit":{"code":0,"signal":null},"queuedRunIds":["2567acec-2829-4386-a6ba-3ad879850970"],"terminal":{"runId":"2567acec-2829-4386-a6ba-3ad879850970","status":"error","stopReason":"rpc"},"independentOwnerWrite":true,"queuedWritePresent":false,"originalAppDenial":"unavailable","providerClosedBeforeRelease":true,"freshViewerReadOnly":true}
{"scenario":"app-revocation","oldPid":99,"newPid":522,"oldExit":{"code":0,"signal":null},"queuedRunIds":["a1e4b477-d0de-4fe3-ad0b-84184932ba44"],"terminal":{"runId":"a1e4b477-d0de-4fe3-ad0b-84184932ba44","status":"error","stopReason":"rpc"},"independentOwnerWrite":true,"queuedWritePresent":false,"originalAppDenial":"grant_revoked","providerClosedBeforeRelease":false,"newCallDeniedBeforeRelease":true}

@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M labels Nov 11, 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. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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 Nov 11, 2026
@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR separates shutdown admission fencing from authority retirement so accepted ingress messages retain restart custody.

Example: Two accepted app messages await execution when the Gateway receives SIGTERM.

  • Before: Shutdown cancels their authority before restart markers capture them, so neither queued write resumes.
  • After: The replacement Gateway completes both writes in FIFO order, subject to the original limits and current permissions.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused owner-level repair with shipped CLI restart and forbidden-effect proof, meaningful persistence regressions, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The compiled CLI in an isolated Linux VM exercises normal shutdown and a distinct replacement process with fresh relay authentication: two queued writes complete in FIFO order, while role downgrade, People removal, and app revocation prevent late writes. The final head changes only a fixture and allocation. External services use deterministic fixtures; app revocation does not eagerly close an existing provider stream, but its late tool effect is refused.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An app reports a message accepted, but restarting the Gateway silently cancels it before recovery records it.
Reason: The maintainer-authored change restores the documented graceful-restart contract using existing owners and preserves current authorization.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR repairs a current shutdown-ordering bug that loses accepted queued messages. No actionable source defects remain; exact-head CI is still pending.

Priority: P2
Reviewed head: edb5215fe19524918581f59698d96af2f9738a51

Before merge

None.

Findings

None.

Agent review details

How this fits together

Trusted plugins bind principals to Gateway ingress; accepted inputs enter the session queue, shutdown records their existing recovery metadata, and startup restores them through current authorization.

flowchart TD
  A[App principal] --> B[Request admission]
  B --> C[Accepted session queue]
  C --> D[Restart custody marker]
  D --> E[Current authority checks]
  E --> F[Agent execution and effects]
Loading

Technical review

Best possible solution:

Keep admission fenced while existing session owners record restart custody, then retire retained authority without weakening live permission checks.

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

The supplied compiled CLI receipts establish the base failure, and current-main source exposes the premature authority-abort path; this read-only review executed no target code.

Is this the best way to solve the issue?

The patch repairs shutdown ordering at the existing lifecycle, request-entry, scheduler, and ingress owners, with no competing recovery implementation or unnecessary production layer.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Principal-bound ingress authority keeps the original intent (2444aae: Trusted plugins require principal-bound access under current roles and session visibility; later merged membership repairs retain the approving source.)
  • Request-entry lifetime keeps the original intent (3ed226a: Fence new preparation and join admitted work before tearing down dependencies; the added retained lifetime preserves this entry fence.)
  • Scheduler shutdown timing changes intended behavior with a stated reason (362cee1: One kernel scheduler synchronously fences timed work and joins running callbacks; the PR explains why cancellation must follow restart custody rather than coincide with fencing.)
  • Restart persistence and settlement ordering keeps the original intent (e051130: Persist restart markers before database cleanup and retain finalizer ownership; the repair extends that ordering to retained ingress authority.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current-main failure remains: Fetched main still calls scheduler.beginClose before marker persistence and binds ingress authority to the request-entry shutdown signal, allowing shutdown to trigger queued-run revocation prematurely. (src/gateway/server-lifecycle.ts:533, aa4ebbb626c4)
  • Ordering repair uses existing owners: Request admission and scheduled wakeups close immediately; retained ingress authority and scheduler cancellation retire only after restart markers and session-stop classification. (src/gateway/server-lifecycle.ts:560, edb5215fe195)
  • Compiled CLI and final-effect receipts: Josh Avant supplies compiled CLI base-failure and candidate receipts covering distinct-process restart, exact queued writes in FIFO order, role downgrade, People removal, and app revocation before late tool effects; independent owner writes remain usable. (4646580a4953)
  • Proof remains applicable: The subsequent commit adds admissionSignal to an integration-test fixture and changes its regression allocation from 271 to 272; production code is identical to the exercised candidate. (src/gateway/remote-control-ui-ingress.integration.test.ts:311, edb5215fe195)
  • Persistence and revocation regression: The Gateway/SQLite regression verifies queued message bytes, original run and source identity, immediate admission refusal, and cancellation when the actual grant is revoked. (src/gateway/server-close.queued-inputs.test.ts:26, edb5215fe195)
  • Related merged repair has distinct scope: fix: preserve queued send permissions across Gateway restarts #196540 preserves each queued input's source restrictions during replay; this PR repairs earlier shutdown cancellation that prevents those inputs from reaching replay. (67a327fc1a32)

PR surface

Source +33, Tests +272, Docs +7, Other +3. Total +315 across 18 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 8 48 15 +33
Tests 8 301 29 +272
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 1 3 0 +3
Total 18 359 44 +315

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 regression code Production +48/-15; tests/support +301/-29 The production growth separates admission and retained authority within existing owners; regression growth covers persistence, real revocation, transport lifetime, and scheduler joins.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: Accepted app messages can be silently lost during graceful restart, with impact limited to queued ingress work during shutdown.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-11T00:27:47.563Z sha 4646580 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-11T00:38:29.824Z sha 4646580 :: needs maintainer review before merge. :: none

Reviewed November 10, 2026, 7:49 PM ET / November 11, 2026, 00:49 UTC (Revision 3).

@joshavant
joshavant marked this pull request as ready for review November 11, 2026 00:33
@joshavant

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

The current Evidence section now includes completed compiled CLI restart traces and sanitized original-run terminal receipts for FIFO replay, role downgrade, People removal and app revocation at the tool boundary. It also records the separate eager-cancellation limitation and an unresolved pre-provider timeout. Source head is unchanged.

@clawsweeper

clawsweeper Bot commented Nov 11, 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 11, 2026
@clawsweeper clawsweeper Bot removed the clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. label Nov 11, 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 11, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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 11, 2026
@joshavant
joshavant merged commit 73a0ce1 into main Nov 11, 2026
153 of 158 checks passed
@joshavant
joshavant deleted the fix/queued-restart-shutdown branch November 11, 2026 01:47
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
…w#196923)

* fix: preserve queued ingress messages during gateway restart

* test: complete ingress host admission fixture

* fix: fence mention intake before restart preparation
roboclaw-bot added a commit that referenced this pull request Nov 11, 2026
…ent (#197213)

Preserve #196923 admission-first restart custody. Assert request entry closes while scheduler authority is fenced, then assert scheduler retirement after accepted fork and rewind finish. Keep persistence and late-request refusal checks; three affected tests pass.

Co-authored-by: obviyus <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 12, 2026
…ent (openclaw#197213)

Preserve openclaw#196923 admission-first restart custody. Assert request entry closes while scheduler authority is fenced, then assert scheduler retirement after accepted fork and rewind finish. Keep persistence and late-request refusal checks; three affected tests pass.

Co-authored-by: obviyus <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 12, 2026
Adapt admission fencing to canonical retained request authority and graceful
restart markers without restoring retired crash-principal reconstruction.

Independent local review omitted per release owner; scoped gates pass.

(cherry picked from commit 73a0ce1)

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. 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