Skip to content

fix(sqlite): prevent plugin metadata reads from mutating state - #106103

Merged
vincentkoc merged 1 commit into
mainfrom
fix/sqlite-state-ownership
Jul 13, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/sqlite-state-ownership

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

Related: #101290

What Problem This Solves

Fixes an issue where CLI/config/plugin metadata reads could join the shared state's writable lifecycle while a live Gateway owned the database. A nominal read could repair canonical indexes, configure WAL maintenance, checkpoint, or mutate file permissions.

Why This Change Was Made

Plugin index reads now use a short-lived DatabaseSync handle opened with readOnly: true. The helper preserves state-path resolution, busy timeout, newer-schema rejection, and deterministic close behavior while leaving schema repair and WAL lifecycle work to writable owners.

Both persisted plugin-index read paths moved to the read-only helper. Writable refreshes still use the existing state transaction path.

User Impact

CLI and configuration flows that inspect installed plugin metadata no longer mutate or repair the shared state database. This reduces cross-process SQLite ownership overlap while a Gateway is running without changing plugin-index results.

Evidence

  • Red proof before the implementation: the new regression test failed because reading the plugin index recreated a deliberately removed canonical index. Blacksmith Testbox Actions run 29227894730.
  • Exact-head focused proof on Blacksmith Testbox tbx_01kxd2m9558776fyy9p4btxt3s: 77 tests passed across shared-state and plugin-index suites.
  • The full core/core-test pnpm check:changed lane passed on the same Testbox, including typechecks, lint, import-cycle checks, database-first guards, and formatting. Current main independently regenerates a different Plugin SDK API hash; that hash was reconciled only inside the disposable Testbox worktree so the unrelated remaining gates could run, and no generated file is part of this PR.
  • Fresh pre-commit autoreview: clean, no accepted or actionable findings.
  • Upstream Node source inspection confirmed DatabaseSync(path, { readOnly: true }) opens SQLite with SQLITE_OPEN_READONLY; the default constructor uses writable/create flags.

@vincentkoc vincentkoc self-assigned this Jul 13, 2026
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: S maintainer Maintainer-authored PR labels Jul 13, 2026
@vincentkoc
vincentkoc force-pushed the fix/sqlite-state-ownership branch from 68c4d94 to 04a2a82 Compare July 13, 2026 06:25
@openclaw-barnacle openclaw-barnacle Bot removed the scripts Repository scripts label Jul 13, 2026
@vincentkoc
vincentkoc force-pushed the fix/sqlite-state-ownership branch from 04a2a82 to 77338bc Compare July 13, 2026 06:28
@vincentkoc
vincentkoc marked this pull request as ready for review July 13, 2026 06:37
@vincentkoc

Copy link
Copy Markdown
Member Author

Land-ready proof for 77338bcbe16ddf8ad5dafeaca66ef669b49e7635:

  • Before fix: the new regression test failed because a metadata-only plugin-index read recreated a deliberately removed canonical index. Actions run: https://github.com/openclaw/openclaw/actions/runs/29227894730
  • Focused exact-head proof: Blacksmith Testbox tbx_01kxd2m9558776fyy9p4btxt3s passed 77 tests across:
    • src/plugins/installed-plugin-index-store.test.ts
    • src/plugins/installed-plugin-index-records.test.ts
    • src/state/openclaw-state-db.test.ts
  • Changed gate on the same Testbox passed the full core/core-test lane: typechecks, oxlint, formatting, import cycles, database-first guards, and supporting policy checks.
  • Current main independently regenerates a different Plugin SDK API hash. That hash was reconciled only inside the disposable Testbox worktree to continue unrelated gates; no generated artifact is included here.
  • Fresh branch autoreview: clean, no accepted/actionable findings.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 106103: passed in hosted_exact_or_recent_rebase mode and verified the remote PR head tree matches the prepared head.

Known gap: the production corruption interleave from #101290 remains nondeterministic. This PR removes the writable lifecycle from the two installed-plugin metadata read paths; doctor, migration, plugin-state diagnostics, and external maintenance ownership remain follow-up work, so #101290 should stay open.

@vincentkoc
vincentkoc merged commit 4ea758d into main Jul 13, 2026
112 of 113 checks passed
@vincentkoc
vincentkoc deleted the fix/sqlite-state-ownership branch July 13, 2026 06:37
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

@steipete

Copy link
Copy Markdown
Contributor

Post-merge CI regression: check:architecture now fails on current main because the new read-only helper opens raw node:sqlite at src/state/openclaw-state-db-readonly.ts:47, while scripts/check-kysely-guardrails.mjs has no explicit classification for that path.

Evidence: https://github.com/openclaw/openclaw/actions/runs/29229631573/job/86750928288

The helper appears to be a narrowly justified read-only SQLite bootstrap. Please either add it to the raw SQLite allowlist under a named read-only shared-state reason, or route it through an already allowed Kysely boundary. This inherited main failure is currently blocking unrelated PR preparation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants