Skip to content

fix(gateway): planned restarts fail while finalizers release state - #195902

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-shutdown-lease-release-after-state-close-20260919
Nov 9, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-shutdown-lease-release-after-state-close-20260919

Conversation

@steipete

@steipete steipete commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes planned Gateway restarts exiting with failure and printing “Gateway failed to start” when accepted plugin-origin work still needs to release a worktree lease or persist subagent completion.

User Impact

Accepted finalizers can finish their state writes during shutdown. Genuine cleanup failures still fail and are reported as shutdown failures. No configuration, schema, timeout, retry, or recovery-data changes.

Why This Change Was Made

The close plan already joins received connection work and run-end custody before draining the SDK host. The host additionally fenced state access on the earlier restart and scheduler cancellation signals, closing the store's admission underneath those finalizers. Remove those premature checks; the SDK host's existing drain/close remains the canonical fence and joins accepted state operations before retirement.

Final shared-state cleanup errors now pass through the run loop's existing shutdown classifier. Actual startup failures still propagate with their cleanup errors. Retained or uncertain lease custody is not silently reported as a successful release.

Production LOC is net −1. The regressions add 109 net test lines, allocated specifically for real lease/Git custody, plugin-origin subagent settle persistence, and CLI cleanup error classification; the subagent proof extends its existing cohort fixture. No UI-imported modules changed.

Evidence

  • Red before / green after: real worktree lease held by received connection work across restart and scheduler cancellation; plugin-origin subagent settle writes; final singleton cleanup failure after SIGTERM.
  • 246 focused tests passed; one PostgreSQL-only case skipped locally. Worktree file: 20 tests / 46.63 s; subagent file: 23 / 43.92 s; CLI run-loop plus timeline: 178 / 56.17 s; adjacent plugin-state/shutdown files: 25 / 33.19 s. Times are Vitest wall times; CI timing pending.
  • Codex autoreview through P2: scoped-clean, no actionable findings; the test cleanup follow-up also received a clean independent review.
  • pnpm check:changed --base 35523ba3e4ff: completed all planned checks. Two local findings (line-cap growth and an async test cleanup callback) were repaired; focused line-cap/lint rechecks and the affected regression pass. Core/test typechecks, state ratchets, format, dead-export scans, and other planned gates passed. The unrelated changelog-attribution failure reproduces with the exact parent's changelog bytes and identical checker (20 identical violations), introduced by 266a7aa0fe69 / fix(release): align attribution gate with human credit policy #194364. It remains an unresolved main regression.

Synthetic Linux/btrfs owner proof used 5,000 session rows, a 35.11 GiB admitted agent database, and 62,000 workspace files / 1.1 GB. Five serial AB/BA pairs with the same 300 ms hold:

Measurement Before After
Clean close 0/5 5/5
Retained lease rows / Git locks 5 / 5 0 / 0
Close median (p95) 419.966 (421.570) ms 336.085 (338.247) ms
Process CPU median 33.319 ms 40.659 ms
Main heap delta median 2,078,400 B 2,206,680 B
Sampled allocation controls 1,615,400 / 1,589,872 B 2,331,768 / 2,249,144 B

Baseline A/A wall: 394.197 / 426.351 ms; CPU: 22.358 / 42.246 ms. The candidate does the durable delete and Git unlock refused by the baseline; additional CPU/allocation pays for successful cleanup. This is correctness proof, not a general performance claim.

Limits: real owner composition, no whole-Gateway/model/systemd test. Database size includes fixture-only zero-BLOB padding; 140 sessions contain transcript payloads. The large agent DB was open, while lease cleanup touched shared SQLite and a small linked checkout; the 62k-file inventory was present but unscanned. btrfs ran in a Linux VM over an APFS-backed loop, not a production block device. CPU includes worker threads but excludes child Git; allocation covers the main isolate. Setup/admission were outside timing. No real user data was copied. Task container, loop, and large fixture were removed.

Let the SDK host drain own the shared-state fence after received work and custody settle. Preserve terminal cleanup failures as shutdown failures rather than sending them through startup recovery. No retry, timeout, schema, or configuration changes.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes agents Agent runtime and tooling plugin: file-transfer size: S labels Nov 9, 2026
@steipete
steipete marked this pull request as ready for review November 9, 2026 10:38
@clawsweeper

clawsweeper Bot commented Nov 9, 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 9, 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-09T10:40:36.486949Z 285a3ea 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.

@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 9, 2026
@steipete

steipete commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Landing note (maintainer review): Team r300's planned shutdown at 2026-11-09 10:03Z exited 1 because an accepted connection finalizer settled after the restart-drain signal had already closed plugin shared-state admission. Its worktree run lease release failed three times ("plugin shared-state admission is closed"), custody was retained, and the failure surfaced through the startup error path ("Gateway failed to start"). The SDK resource host now fences shared-state work only when its own close runs, after ingress/scheduler cancellation and accepted finalizers have drained. Terminal cleanup failures are classified as shutdown failures, not startup failures. Production −1 line; synthetic trials 0/5 → 5/5 clean closes; exact-head CI green.

@steipete
steipete merged commit cd48b39 into main Nov 9, 2026
212 of 220 checks passed
@steipete
steipete deleted the steipete/perf-micro-shutdown-lease-release-after-state-close-20260919 branch November 9, 2026 10:55
steipete added a commit that referenced this pull request Nov 9, 2026
…ners

Signal discovery completion from the Workshop startup mock. Expect accepted finalizers to retain state access during drain, matching the documented change in #195902, while preserving terminal refusal and shutdown timing checks. Extend the exact per-change test allocation by the three added mock lines.
steipete added a commit that referenced this pull request Nov 9, 2026
* fix(gateway): serve startup reads while sessions resume

Install per-session recovery admission before readiness unlock so fresh turns preserve resume and retained-input ordering without holding unrelated sessions. Let catalog reads use owner readiness and remove the agent-wide recovery rejection. Include synthetic restart benchmarking and real Gateway ordering regressions.

* test(gateway): use graceful shutdown for retained-input restart proof

The signed-in restart fixture introduced in #192444 canceled process-tree custody while expecting a clean Gateway exit. Select the existing bounded graceful-stop path so the unchanged exit, marker, authority and FIFO assertions exercise restart recovery. The original failure reproduces on parent 7c78826; the corrected full flow passes.

* chore(gateway): complete startup admission proof inventories

Include the two session-key modules reached by startup admission in the materialized PR wrapper. Allocate exactly 312 regression-test lines for distinct Gateway readiness/FIFO, session-ID hydration, and shared-store admission contracts; leave the shared test budget scalar unchanged.

* test(gateway): align startup and finalizer fixtures with lifecycle owners

Signal discovery completion from the Workshop startup mock. Expect accepted finalizers to retain state access during drain, matching the documented change in #195902, while preserving terminal refusal and shutdown timing checks. Extend the exact per-change test allocation by the three added mock lines.

* fix(gateway): canonicalize session keys before recovery admission

* fix(gateway): keep canonical session routing wrapper closure complete
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 10, 2026
…penclaw#195902)

* fix(gateway): preserve state admission through shutdown finalizers

Let the SDK host drain own the shared-state fence after received work and custody settle. Preserve terminal cleanup failures as shutdown failures rather than sending them through startup recovery. No retry, timeout, schema, or configuration changes.

* test(gateway): await shutdown fixture cleanup directly
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 10, 2026
)

* fix(gateway): serve startup reads while sessions resume

Install per-session recovery admission before readiness unlock so fresh turns preserve resume and retained-input ordering without holding unrelated sessions. Let catalog reads use owner readiness and remove the agent-wide recovery rejection. Include synthetic restart benchmarking and real Gateway ordering regressions.

* test(gateway): use graceful shutdown for retained-input restart proof

The signed-in restart fixture introduced in openclaw#192444 canceled process-tree custody while expecting a clean Gateway exit. Select the existing bounded graceful-stop path so the unchanged exit, marker, authority and FIFO assertions exercise restart recovery. The original failure reproduces on parent 0d97c79; the corrected full flow passes.

* chore(gateway): complete startup admission proof inventories

Include the two session-key modules reached by startup admission in the materialized PR wrapper. Allocate exactly 312 regression-test lines for distinct Gateway readiness/FIFO, session-ID hydration, and shared-store admission contracts; leave the shared test budget scalar unchanged.

* test(gateway): align startup and finalizer fixtures with lifecycle owners

Signal discovery completion from the Workshop startup mock. Expect accepted finalizers to retain state access during drain, matching the documented change in openclaw#195902, while preserving terminal refusal and shutdown timing checks. Extend the exact per-change test allocation by the three added mock lines.

* fix(gateway): canonicalize session keys before recovery admission

* fix(gateway): keep canonical session routing wrapper closure complete
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. cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime plugin: file-transfer size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant