Repository navigation
fix: prevent agent database reopen loops during shutdown - #188976
Merged
Merged
Conversation
Fence optional session-row transcript backfill with existing process drain and cleanup signals before writer and native worker admission. Queued previews can be rebuilt after restart; accepted work retains the existing database drain. Extend the existing process regression to reject backfill after clean close. Preserve restart markers, held finalizers, queued inputs, and watchdog budgets.
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
steipete
marked this pull request as ready for review
October 31, 2026 02:26
Contributor
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Oct 31, 2026
…penclaw#188976) On the Team stop of 2026-10-31 00:12Z the roboclaw agent database was reopened and closed 205 times (every ~370 ms) after the close steps had finished, keeping the process alive with "pending close steps: none" until the hard-exit watchdog SIGKILLed it. The caller was the session-row projection backfill queue (session-row-projection-backfill.ts -> session-row-transcript-backfill.ts), which had no Gateway-close fence and reopened the agent database for each queued row. The backfill now observes the existing restart-drain and shutdown-cleanup signals: it stops scheduling, skips applying results, and passes the abort signal into the worker execution so an in-flight row ends instead of reopening the database. The plugin shared-state fence and shutdown-invalidation retry classification are follow-ups.
tideclaw-bot
added a commit
that referenced
this pull request
Nov 5, 2026
Backport accepted fixes onto 2026.11.5-beta.2. Base: bc061f9 Canonical source tree before commit: e6c0c39 These are adapted/squashed backports; do not claim each is an exact Git cherry-pick. Source provenance (selected verified commits; other cohorts use their frozen patch/adoption manifests): runtime-B: b20a0cc fix(macos): connect with configured credentials despite stale app environment (#191468) c4c0942 fix(update): failed updates from 10.7–10.9 crash in automatic migration recovery (#189713) 6aae408 fix(update): preserve recovery errors and async triage callbacks (#191495) 8910654 fix(macos): prevent first-launch Gateway failures after upgrades (#191436) 00b2ff4 fix: parent sessions miss child approvals with a custom session store (#189827) c6142a8 fix: avoid copying managed plugin binaries during Gateway startup (#187865) e72b356 fix(anthropic): avoid token profile collisions (#187875) 807075d fix(anthropic): set API workspace at login (#186976) bafe92f fix(exec): preserve no-timeout results from macOS app nodes (#190729) 9b05a64 fix(imessage): use a PostgreSQL-safe recovery cursor key (#184919) 6ba197f fix: session search on PostgreSQL scans every transcript row instead of using the text index (#187909) 4f49aa5 fix(sessions): PostgreSQL session search scans every transcript row again after the 5th search on a connection (#188979) de3936c fix(macos): Mac tab shows a blank or stale page when a load fails (#185432) e977080 fix(macos): prevent duplicate voice sends and false sent feedback (#186271) provider-compaction: 1b43c2e fix(compaction): preserve active request provenance (#180214) 7b0cfe3 fix(google): restore tool calls with Python keyword parameters (#191561) 9039ceb fix(ci): keep compaction attribution helpers internal d6a1327 feat(google): use the Interactions API for Gemini Flash models (#189395) fe0f8d1 fix(google): Gemini models ignore configured topP (#190695) history: c51d733 fix(sessions): stop expanding archive reads from exhausting memory (#190690) 3c8bd4d fix(sessions): page oversized earlier history instead of failing at 8 MiB (#188450) b195f61 fix(sessions): page oversized transcript history in both directions (#188483) b65482e fix(gateway): preserve older history across hidden message gaps (#188557) 3d4fc94 fix(sessions): avoid oversized listing and imported-history reads (#189284) 33e7baf fix(sessions): bound active accounting without blocking writers (#190182) 682ade7 fix: preserve chat history continuation metadata (#188612) runtime-C: 7e005b0 fix(macos): keep secrets when a Gateway config save fails (#187734) 15cf738 fix(macos): keep Gateway auth when Tailscale exposure is turned off (#187664) b53a06b perf(update): read candidate state inventory without copying the shared database (#187921) 970fc4e fix: restore CLI message sends with agent tool policies (#188058) 73ad731 fix: stop model fallback when session capability metadata changes (#179312) 32305db fix: subagent turns fail after session metadata changes (#183501) d13bd0f fix(codex): include relay conversation instructions in trajectory (#189005) e375530 fix: replies after a plugin reload from Control UI go to the session's last external chat (#190982) 9346376 fix: reasoning-only retry is refused by Anthropic as reasoning_extraction (#184434) direct-auth-state: 1b15408 fix(models): keep the model list when one plugin-owned provider lacks a credential (#189014) 7d8dc60 fix: recover startup migration with retained worker index (#189023) capacity: 41772e3 fix(worktrees): settle completed disk debt on refused postchecks (#188727) command-once-189369: 8269137 fix(plugins): plugin commands that continue the agent run three times on native command turns (#189369) pg-board-189564: 7232a8d fix(boards): publish widgets with PostgreSQL storage (#189564) queued-edit-189869: 92b32ca fix: hold queued messages through inline edits (#189869) Preserve source attribution from original commits. For a genuinely exact individual pick only, use the conventional (cherry picked from commit <sha>) line. Full file-level provenance: coverage-manifest.json; reviewed patch hashes: artifact-registry.json. No held136/native82 content adopted by this work. No release or full-candidate qualification claim. Additional original-source identities (exact adapted hunk scope is in frozen artifacts): release-guides-185258: 39c37e6 docs(release): define ledger-first hotfix routing (#185258) UI-history: 10a6e4f fix(ui): scope provider-add discovery warning to its own provider (#188541), 3d7b4c4 fix(ui): never fail loading earlier chat history without a boundary (#188372) obsolete-cache-188203: 90d82c2 fix: preserve completed reasoning and refill chat snapshots (#188203) webhook-169778: b1f643f fix(startup): keep webhook decisions startup recorded for channels Doctor left pending (#169778) schema-lease-188391: ba6cfcd fix(state): keep lease renewal independent of parent admission (#188391) backfill-188976: c75a8a8 fix(gateway): stop session row backfill once the Gateway is closing (#188976) canonical-disable-188846: 88b56ee fix(config): auto-enable reads and writes mixed-case plugin policy under the canonical id (#188846) matrix-177272: 5a6d22c fix(matrix): stop seeding new thread sessions from the room transcript (#177272) provider-hook-189059: 0588f51 fix(models): isolate every per-provider catalog failure (#189059) unicode-189868: 87396e7 fix(oc-path): avoid reading and editing a different Unicode key (#189868) replay-cohort: 2031044 fix(sessions): acknowledge committed input retries without duplicate turns (#188527), 9114431 fix: resume configured fallback after interrupted attempts (#188672) Co-authored-by: RomneyDa <[email protected]>
obviyus
added a commit
that referenced
this pull request
Nov 24, 2026
…r closes (#204544) ## Problem During a Gateway restart or stop, a run that ends after the agent database's clean-close receipt can reopen the sealed store. `test/gateway-restart-resume.e2e.test.ts` ("restart markers survive graceful shutdown (blocked store: false)") catches it: a `session.rowTranscript.backfill` reservation starts after the clean-close (`expected true to be false` at the `[close-backfill-proof]` check). No scheduled CI lane runs this file. Cause: #204281 added `readVisibleSessionActivityAt`. Every run end calls it, and it uses `backfillSessionRowTranscriptFields` with no signal. #188976 fenced only the session-row projection queue. Shutdown aborts the active runs, those runs end, and each run end then opens the store again. ## Solution The drain and shutdown fence moves into `backfillSessionRowTranscriptFields`, the function that opens the store. Every caller gets it, including the run-end read. The `signal` parameter is removed, because its only caller (the projection queue) passed the same two signals. ## Impact - A run that ends while the Gateway drains or closes does not advance unread. The run-end read already treats a failure as "unread unchanged". Accepted edge case: a visible reply that lands during shutdown does not light the unread dot. - No change outside shutdown. - Production: +16 / −11 lines in 2 files. ## Evidence - Base (`main`), the same filtered case: the `[close-backfill-proof]` check fails in cycle 1. - Head: cycle 1 passes the check (a run free of a local port probe that sends `GET /` to new listeners and breaks the fixture's JSON parse). Unit tests `session-row-transcript-backfill.test.ts` (16) and `session-accessor.sqlite-maintenance-read.test.ts` (8) pass. `pnpm tsgo:core` passes. - The e2e case is still red on head, at a later step: in cycle 2, a queued input is cancelled at restart (`HANDLED_QUEUED_BEFORE_RESTART_2_1`). That failure also occurs on `57dd84bd`, before #204281, so it has a separate cause. It is tracked separately. Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot
pushed a commit
that referenced
this pull request
Nov 25, 2026
…r closes (#204544) ## Problem During a Gateway restart or stop, a run that ends after the agent database's clean-close receipt can reopen the sealed store. `test/gateway-restart-resume.e2e.test.ts` ("restart markers survive graceful shutdown (blocked store: false)") catches it: a `session.rowTranscript.backfill` reservation starts after the clean-close (`expected true to be false` at the `[close-backfill-proof]` check). No scheduled CI lane runs this file. Cause: #204281 added `readVisibleSessionActivityAt`. Every run end calls it, and it uses `backfillSessionRowTranscriptFields` with no signal. #188976 fenced only the session-row projection queue. Shutdown aborts the active runs, those runs end, and each run end then opens the store again. ## Solution The drain and shutdown fence moves into `backfillSessionRowTranscriptFields`, the function that opens the store. Every caller gets it, including the run-end read. The `signal` parameter is removed, because its only caller (the projection queue) passed the same two signals. ## Impact - A run that ends while the Gateway drains or closes does not advance unread. The run-end read already treats a failure as "unread unchanged". Accepted edge case: a visible reply that lands during shutdown does not light the unread dot. - No change outside shutdown. - Production: +16 / −11 lines in 2 files. ## Evidence - Base (`main`), the same filtered case: the `[close-backfill-proof]` check fails in cycle 1. - Head: cycle 1 passes the check (a run free of a local port probe that sends `GET /` to new listeners and breaks the fixture's JSON parse). Unit tests `session-row-transcript-backfill.test.ts` (16) and `session-accessor.sqlite-maintenance-read.test.ts` (8) pass. `pnpm tsgo:core` passes. - The e2e case is still red on head, at a later step: in cycle 2, a queued input is cancelled at restart (`HANDLED_QUEUED_BEFORE_RESTART_2_1`). That failure also occurs on `57dd84bd`, before #204281, so it has a separate cause. It is tracked separately. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 76e2021) Co-authored-by: RomneyDa <[email protected]>
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Nov 25, 2026
…r closes (openclaw#204544) ## Problem During a Gateway restart or stop, a run that ends after the agent database's clean-close receipt can reopen the sealed store. `test/gateway-restart-resume.e2e.test.ts` ("restart markers survive graceful shutdown (blocked store: false)") catches it: a `session.rowTranscript.backfill` reservation starts after the clean-close (`expected true to be false` at the `[close-backfill-proof]` check). No scheduled CI lane runs this file. Cause: openclaw#204281 added `readVisibleSessionActivityAt`. Every run end calls it, and it uses `backfillSessionRowTranscriptFields` with no signal. openclaw#188976 fenced only the session-row projection queue. Shutdown aborts the active runs, those runs end, and each run end then opens the store again. ## Solution The drain and shutdown fence moves into `backfillSessionRowTranscriptFields`, the function that opens the store. Every caller gets it, including the run-end read. The `signal` parameter is removed, because its only caller (the projection queue) passed the same two signals. ## Impact - A run that ends while the Gateway drains or closes does not advance unread. The run-end read already treats a failure as "unread unchanged". Accepted edge case: a visible reply that lands during shutdown does not light the unread dot. - No change outside shutdown. - Production: +16 / −11 lines in 2 files. ## Evidence - Base (`main`), the same filtered case: the `[close-backfill-proof]` check fails in cycle 1. - Head: cycle 1 passes the check (a run free of a local port probe that sends `GET /` to new listeners and breaks the fixture's JSON parse). Unit tests `session-row-transcript-backfill.test.ts` (16) and `session-accessor.sqlite-maintenance-read.test.ts` (8) pass. `pnpm tsgo:core` passes. - The e2e case is still red on head, at a later step: in cycle 2, a queued input is cancelled at restart (`HANDLED_QUEUED_BEFORE_RESTART_2_1`). That failure also occurs on `c28cebe5`, before openclaw#204281, so it has a separate cause. It is tracked separately. Co-authored-by: Ayaan Zaidi <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Fixes Gateway shutdown repeatedly reopening agent databases for optional session previews after clean close, keeping the process alive until the watchdog kills it.
Related: #188402, #188496, #188920.
User Impact
Shutdown stops optional preview work when restart drain begins. Queued previews can be dropped and rebuilt by the next Gateway; already-admitted database work keeps its existing settlement and drain. Marker-first persistence, snapshot abort, retirement order, required joins, and watchdog budgets stay intact.
Why This Change Was Made
The projection backfill queue outlived the close boundary. On the base,
src/gateway/session-row-projection-backfill.ts:79calls writable execution atsrc/gateway/session-row-transcript-backfill.ts:69; every queued row can acquire and release the database again.The queue now consumes the existing process drain/cleanup signals, stops scheduling, and checks cancellation after its readiness waits. That same signal reaches writer admission and the existing worker execution authority callback. The existing database drain owns accepted work. No lifecycle plumbing, plugin fence, retry change, new deadline, config, schema, or dependency is added. All three previously capped files are unchanged.
Evidence
The reported r250 stop on 2026-10-31 UTC finished its close steps around 00:12:09.6, then wrote 205 clean-close receipts between 00:12:13.096 and 00:13:29.846, roughly every 350–400 ms, until watchdog SIGKILL. The independent plugin shared-state refusals failed fast and were not the process-retention cause.
The existing isolated held-finalizer scenario naturally reproduces queued projection work, without seeding a fake queue. Reservation diagnostics identify
session.rowTranscript.backfill: first clean-close at 02:06:13.957Z, successful backfills at 02:06:14.395Z and .456Z, and another clean-close at .508Z. This proves the caller mechanism; it does not claim to reproduce all 205 production cycles.a825acc286e01fab2722471336f1a9523b12e28f: the retained reopen assertion inrestart markers survive graceful shutdown (suspend/reopen and blocked store: false)was red under Node 26.12.1 and pinned Bun 1.4.4 (expected true to be falsefor post-clean-close backfill).OPENCLAW_VITEST_RUNTIME=node node scripts/prepare-vitest-runtime.mjs --with-ai-packagepassed, including the CLI bootstrap import guard (3m25.8s).node scripts/run-vitest.mjs src/gateway/session-row-projection.backfill.test.ts src/gateway/session-row-transcript-backfill.test.ts --maxWorkers=1passed 33 tests in two shards (92.94s including compilation; test files 36.75s and 23.65s).git diff --checkpassed.Full process regression command (each run uses its own ignored FS module cache):
Both passed 2/2 tests, including existing restart, held-finalizer, queued-input, blocked-store and crash cases, with no backfill operation after first clean-close. Node: 84.229s test time, 116.55s wrapper; shutdowns 2.377s (suspend/reopen), 6.725s (SIGTERM), 1.510s (managed). Bun: 61.67s total file time; shutdowns 1.508s, 6.895s, 1.072s respectively. All three measured close modes exited 0 under each runtime. Exact-head CI run 41160058115 passed: 41 successful jobs, 27 skipped, no failures; all observed required
openclaw/ci-gateentries are SUCCESS. The successful-job envelope was 542 seconds; aggregate successful-job time was 6369 seconds. The exact-head watcher reported GREEN, ignoring 81 superseded aliases behind GitHub’s stale rollup. No CI reruns or repair pushes were needed.Whole change: four files, production net +25 LOC, test net -18 LOC, docs +5 LOC. The only new machinery is cancellation at the existing optional-work owner; the wider proposed shutdown plumbing was removed.
Deferred follow-up
Plugin shared-state admission remains separate: the SDK resource host's
track/drainWork(src/plugins/legacy-sdk-resource-host.ts:59–61,129) does not currently fence all cached/worker state paths, andsrc/state/openclaw-state-worker-owner.ts:364reports retirement refusal. The earlier process-test variant's late plugin lookup was accepted after close; its red test wasrestart markers survive graceful shutdown (suspend/reopen and blocked store: false). That assertion and the shared-state patch are preserved locally, outside this PR.Retry classification is also deferred:
src/infra/retry-policy.ts:16–33treatsclosed/unavailableas transient, and Nostr's stop atextensions/nostr/src/nostr-bus.ts:491awaits the unconditional recovery loop atnostr-cursor.ts:140–151. Red tests werekeeps OpenClaw state database read admission is closed terminal despite a transient wrapper,keeps Shared-state worker is retiring while its actor is in use; close its leases first terminal despite a transient wrapper(three attempts instead of one),does not retry terminal outcome STATE_DATABASE_READ_ADMISSION_INVALIDATED, andretries safety writes unless admission is closed (true)(incorrectly recovered after four writes). Their fixes and tests are preserved in.local/v2-followup.patchand are not included here.