Repository navigation
fix(plugin-state): treat missing plugin-state table as empty on read-only fresh stores - #117257
Conversation
…only fresh stores Startup leases create state/openclaw.sqlite before the first plugin-state write, so legacy-state migration detection read the file through a read-only connection and failed on the missing plugin_state_entries table, blocking fresh-state-dir gateway boots from reaching ready. Fixes #117249
|
Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 2:44 AM ET / 06:44 UTC. ClawSweeper reviewWhat this changesThe PR makes read-only plugin-state queries report empty results for a fresh startup-checkpoint SQLite database that has not yet created its lazy plugin-state table, while retaining errors for initialized damaged stores. Merge readinessThe latest head addresses the prior corruption-boundary finding: it returns empty state only when the database has the startup checkpoint’s two tables and keeps a missing plugin-state table visible as an error once any other state table exists. No additional actionable patch defect was found; this remains the viable fix candidate for the linked open bug and needs normal exact-head CI plus maintainer merge review. Priority: P0 Review scores
Verification
How this fits togetherGateway startup first creates a minimal shared SQLite checkpoint database for migration leasing, then runs legacy-state detectors that read plugin state. Those detector outcomes determine whether startup migrations complete and whether the gateway reports ready. flowchart LR
A[Fresh state directory] --> B[Startup migration lease]
B --> C[Checkpoint SQLite database]
C --> D[Read-only legacy-state detectors]
D --> E{Plugin-state table missing?}
E -->|Checkpoint tables only| F[Report empty legacy state]
E -->|Other state tables exist| G[Return storage error]
F --> H[Gateway can become ready]
G --> I[Migration warning blocks ready]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +29, Tests +159. Total +188 across 3 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the two-table checkpoint discriminator and its paired fresh-store and damaged-schema tests, then merge only after the exact current head has completed normal CI and maintainer review. Do we have a high-confidence way to reproduce the issue? Yes, with high confidence from source: the startup lease creates the two-table checkpoint before migration detection, while read-only plugin-state queries require the lazy table. The supplied live main-based before/after run corroborates that path, although this read-only review did not execute it. Is this the best way to solve the issue? Yes. The refined PR fixes the owner boundary at the read-only plugin-state helper, does not create schema from a read path, and explicitly preserves failure behavior for initialized stores missing their canonical table. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 78486e27511c. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Merged via squash.
|
…only fresh stores (openclaw#117257) * fix(plugin-state): treat missing plugin-state table as empty on read-only fresh stores Startup leases create state/openclaw.sqlite before the first plugin-state write, so legacy-state migration detection read the file through a read-only connection and failed on the missing plugin_state_entries table, blocking fresh-state-dir gateway boots from reaching ready. Fixes openclaw#117249 * test(plugin-state): split fresh-store read coverage into focused file * fix(plugin-state): distinguish fresh stores from damaged schemas
What Problem This Solves
Fixes #117249. Booting the gateway against a fresh, empty
OPENCLAW_STATE_DIRexits code 7 — "startup migrations did not complete cleanly; refusing to report the gateway ready" — because legacy-state migration detection errors on a store that simply has no data yet. The startup lease system createsstate/openclaw.sqlitefirst (onlyschema_meta+state_leases), then detection reads plugin state through a read-only connection that cannot run the lazy table ensure:SELECTfails withno such table: plugin_state_entries, wrapped asPluginStateStoreError, surfacing as "Failed detecting …" warnings for the Matrix/Reef/Workboard detectors, which block ready. First-run out-of-box path broken; the workaround was a manualopenclaw doctor --fix.Why This Change Was Made
The read-only helper already returns
undefinedwhen the DB file is missing — the benign "no legacy state" answer. This fix extends the same semantics to the missing-table case at one narrow point (withPluginStateDatabaseReadOnly): a matcher requiringERR_SQLITE_ERRORand the exact messageno such table: plugin_state_entriesreturnsundefined; every other SQLite failure still throws wrapped. No table creation from read paths, no schema-version change, no startup reordering — this is the additive lazy-ensure storage model working as designed: reads before the first write mean an empty store.User Impact
A brand-new install reaches gateway-ready without a doctor step. No behavior change for populated stores; genuine corruption still fails loudly.
Evidence
readyz=200in 7s,{"ready":true,"failing":[]}, zero detection warnings, detectors complete ("Recorded Matrix inbound dedupe migration completion (0 SQLite roots, 0 JSON roots scanned)"), 13 plugins loaded in 1.1s.src/infra/state-migrations.test.ts).main: 14 macOS-local failures instate-migrations.workspace-setup-sandbox.test.ts(/varvs/private/varcanonicalization) — reproduced identically on a checkout without this change; Linux CI is authoritative there. Follow-up filed separately.code: ERR_SQLITE_ERROR,message: no such table: plugin_state_entries.🤖 Generated with Claude Code
Review refinement (accepted finding)
The empty-state fallback is now gated on the genuine lease-bootstrap shape: a read-only schema discriminator (
SELECT 1 FROM sqlite_schema WHERE type='table' AND name NOT IN ('schema_meta','state_leases') LIMIT 1, run on the already-open handle) returns empty only for true fresh checkpoints; any store initialized beyond the checkpoint keeps failing loudly (PLUGIN_STATE_READ_FAILED) so a damaged canonical schema can never masquerade as empty. New corruption-case test covers exactly that; fresh-case fixture now uses the real startup-checkpoint bootstrap. Suites: fresh-store 2/2, plugin-state 77/77, migration regression 75/75; autoreview clean.