Repository navigation
fix(state): retire successor readers before upgrade swap - #200656
Conversation
- Config admission reads plugin metadata from the shadow state database through a read worker, which retains that connection. - The swap renamed the shadow inode live while the reader kept the shadow pathname; after the first writer re-enabled WAL, its next read failed with SQLITE_IOERR_FSTAT (disk I/O error). - Close the shadow shared-state path right after config admission, before refusal cleanup or rename.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. What this changesThis PR closes shadow shared-state database readers after config admission and before upgrade publication or cleanup. Example: The first Gateway start upgrades 2026.11.4 state and config admission reads plugin metadata.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenanceRegression provenance — verified: source commit Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this maintainer-authored PR fixes a concrete reader-lifecycle defect still present on main; no introduced code defect was found. Priority: P1 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherGateway startup copies outdated state into a shadow directory, runs migrations and config admission, then publishes the upgraded files; shared-state workers must release shadow connections before those files move. flowchart TD
A[Gateway startup] --> B[Copy and migrate shadow state]
B --> C[Admit shadow config]
C --> D[Retire shadow readers]
D --> E[Publish upgrade files]
E --> F[Open live state workers]
Technical reviewBest possible solution: Retire shadow readers through the existing cleanup owner before publication, and coordinate with #200596 so one repair lands. Do we have a high-confidence way to reproduce the issue? The production admission callback can retain metadata readers, the reader cache follows physical identity across rename, and the added regression reproduces that sequence; no target code was executed during this read-only review. Is this the best way to solve the issue? This is the smallest complete lifecycle repair: it reuses the existing path-close owner, covers admission success and failure, and adds no parallel state or recovery mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 20248a9ec7c3. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +8, Tests +72. Total +80 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 17, 2026, 10:29 AM ET / 15:29 UTC. |
|
Landed as f8038cd.
|
…0656) ## Problem When a Gateway upgrades existing state at startup (copy-and-swap from openclaw#198389), a later read through the shared-state read worker can fail with `disk I/O error` (`ERR_SQLITE_ERROR`, errcode 1802 = `SQLITE_IOERR_FSTAT`). The failing component depends on which reader runs next: - secret activation: `Startup failed: required secrets are unavailable ... disk I/O error`. The Gateway does not start. - host-link repair: `Could not repair OpenClaw host links: Error: disk I/O error`. Warning only. Fresh state (no upgrade) does not fail. ## Cause 1. Before the swap, `admitConfig` validates the shadow config. That reads plugin metadata from the **shadow** `state/openclaw.sqlite` through a read worker, which retains the connection (keyed by physical identity). 2. `beforeSwap` closes only the predecessor (live) identity, so the shadow reader survives. 3. The swap renames the shadow inode into the live path. The retained reader still records the shadow pathname. 4. The upgrade left the database in rollback-journal mode; startup's first writer switches it back to WAL. The retained reader then looks for WAL/SHM at the vanished shadow pathname and fails. ## Fix In `upgradeStateDirectory`, close the shadow shared-state path through the existing `closeOpenClawStateDatabaseByPathAsync` in a `finally` right after config admission, before refusal cleanup or rename. ## Evidence - Regression test `state-upgrade.test.ts` › "reopens shared-state workers after the copy-and-swap upgrade": old-schema state, lock inspection, shadow metadata read in `admitConfig`, real predecessor close in `beforeSwap`, swap, first writer WAL transition, then a worker read of the newly written row. - Red on merge base `44ee25b8`: `Error: disk I/O error`, `{ code: 'ERR_SQLITE_ERROR', errcode: 1802 }`. - Green with the fix (12/12 in the file). - End to end (Gateway from source): state written by released `[email protected]`, then the same pristine copy started on the merge base and on this branch. Both run the state upgrade. Merge base: 1 `disk I/O` error after the upgrade. This branch: 0. - `tsgo:core`, oxfmt, oxlint on changed files: pass. Co-authored-by: Ayaan Zaidi <[email protected]>
## Problem When a Gateway upgrades existing state at startup (copy-and-swap from #198389), a later read through the shared-state read worker can fail with `disk I/O error` (`ERR_SQLITE_ERROR`, errcode 1802 = `SQLITE_IOERR_FSTAT`). The failing component depends on which reader runs next: - secret activation: `Startup failed: required secrets are unavailable ... disk I/O error`. The Gateway does not start. - host-link repair: `Could not repair OpenClaw host links: Error: disk I/O error`. Warning only. Fresh state (no upgrade) does not fail. ## Cause 1. Before the swap, `admitConfig` validates the shadow config. That reads plugin metadata from the **shadow** `state/openclaw.sqlite` through a read worker, which retains the connection (keyed by physical identity). 2. `beforeSwap` closes only the predecessor (live) identity, so the shadow reader survives. 3. The swap renames the shadow inode into the live path. The retained reader still records the shadow pathname. 4. The upgrade left the database in rollback-journal mode; startup's first writer switches it back to WAL. The retained reader then looks for WAL/SHM at the vanished shadow pathname and fails. ## Fix In `upgradeStateDirectory`, close the shadow shared-state path through the existing `closeOpenClawStateDatabaseByPathAsync` in a `finally` right after config admission, before refusal cleanup or rename. ## Evidence - Regression test `state-upgrade.test.ts` › "reopens shared-state workers after the copy-and-swap upgrade": old-schema state, lock inspection, shadow metadata read in `admitConfig`, real predecessor close in `beforeSwap`, swap, first writer WAL transition, then a worker read of the newly written row. - Red on merge base `1f75f9ce`: `Error: disk I/O error`, `{ code: 'ERR_SQLITE_ERROR', errcode: 1802 }`. - Green with the fix (12/12 in the file). - End to end (Gateway from source): state written by released `[email protected]`, then the same pristine copy started on the merge base and on this branch. Both run the state upgrade. Merge base: 1 `disk I/O` error after the upgrade. This branch: 0. - `tsgo:core`, oxfmt, oxlint on changed files: pass. Co-authored-by: Ayaan Zaidi <[email protected]> Release adaptation retains existing broader deletion tests; adds only the new reader-replacement regression. (cherry picked from commit f8038cd) Co-authored-by: RomneyDa <[email protected]>
Problem
When a Gateway upgrades existing state at startup (copy-and-swap from #198389), a later read through the shared-state read worker can fail with
disk I/O error(ERR_SQLITE_ERROR, errcode 1802 =SQLITE_IOERR_FSTAT).The failing component depends on which reader runs next:
Startup failed: required secrets are unavailable ... disk I/O error. The Gateway does not start.Could not repair OpenClaw host links: Error: disk I/O error. Warning only.Fresh state (no upgrade) does not fail.
Cause
admitConfigvalidates the shadow config. That reads plugin metadata from the shadowstate/openclaw.sqlitethrough a read worker, which retains the connection (keyed by physical identity).beforeSwapcloses only the predecessor (live) identity, so the shadow reader survives.Fix
In
upgradeStateDirectory, close the shadow shared-state path through the existingcloseOpenClawStateDatabaseByPathAsyncin afinallyright after config admission, before refusal cleanup or rename.Evidence
state-upgrade.test.ts› "reopens shared-state workers after the copy-and-swap upgrade": old-schema state, lock inspection, shadow metadata read inadmitConfig, real predecessor close inbeforeSwap, swap, first writer WAL transition, then a worker read of the newly written row.1f75f9ce:Error: disk I/O error,{ code: 'ERR_SQLITE_ERROR', errcode: 1802 }.[email protected], then the same pristine copy started on the merge base and on this branch. Both run the state upgrade. Merge base: 1disk I/Oerror after the upgrade. This branch: 0.tsgo:core, oxfmt, oxlint on changed files: pass.