Skip to content

fix(plugin-state): avoid shared SQLite corruption when CLI starts during gateway runtime - #113204

Merged
vincentkoc merged 4 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/ocpr-issue-101290-20260724
Jul 31, 2026
Merged

vincentkoc merged 4 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/ocpr-issue-101290-20260724

Conversation

@zhangguiping-xydt

@zhangguiping-xydt zhangguiping-xydt commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Related to #101290

What Problem This Solves

CLI startup and preflight plugin-state reads could open the shared SQLite database through the writable lifecycle while the Gateway was running. That let read-only callers re-enter permission, WAL, schema, and repair work owned by the writer.

Why This Change Was Made

Plugin-state reads now use the canonical state-owner read accessor. It reuses a safe process-held handle or opens an existing database physically read-only without schema, WAL, or permission mutation.

Fresh opens preserve process-local and persisted quarantine checks. Missing files remain empty, non-missing filesystem failures remain actionable, and writes stay on the canonical writable transaction path. The follow-up commits keep the internal open guard module-private and preserve process-held handle reuse before any fresh filesystem probe.

User Impact

CLI startup and runtime plugin-state lookups no longer enter writable shared-state maintenance. Missing state remains empty. Damaged, quarantined, incompatible, or inaccessible state fails closed, while a safe process-held handle remains reusable.

This is a bounded repair for the plugin-state read owner boundary. The broader production-validation issue #101290 remains open.

Evidence

  • Frozen base: 6d339763186adbd9312114904ffb6af5c93baf1f

  • Exact PR head: caf9cac456aa05a8aa3eb86b67d37352f97a3eb9

  • The contributor's three commits remain patch-identical after the rebase; author credit is preserved.

  • The four touched files are byte-identical on current main to the original merge base, and the old contributor head has a clean three-way merge.

  • Focused regression proof: 75 passed, 1 Windows-only test skipped. Coverage includes the four read APIs, missing databases, process-local and persisted quarantine, newer schemas, inaccessible directories, process-held handle reuse, and the current schema-migration-required sibling.

  • A byte-identical pre-rebase head passed the changed gate: format, plugin boundaries, both Knip scans, core and core-test tsgo, oxlint, schema guards, database-first storage checks, and import-cycle checks: https://github.com/openclaw/openclaw/actions/runs/30660036355

  • Fresh exact-head autoreview returned no actionable findings at 0.98 confidence.

  • Concurrent runtime proof on the byte-identical four-file patch passed with a real ephemeral Gateway:

    Separate-process plugin-state read calls:   2,748
    Reader writable-lifecycle assertions:         690
    Gateway-owned cron writes:                      40
    Gateway health checks:                         2/2
    PRAGMA quick_check:                              ok
    PRAGMA integrity_check:                          ok
    Reader plugin/shared writable caches:         false
    

    Run: https://github.com/openclaw/openclaw/actions/runs/30658395411

  • Final delegated verification matched the frozen base, exact changed-file set, and all four expected blob hashes. The concurrent proof validates the corrected ownership boundary and database health; it does not claim a deterministic reproduction of the timing-sensitive corruption.

@zhangguiping-xydt
zhangguiping-xydt marked this pull request as ready for review July 24, 2026 02:45
@zhangguiping-xydt
zhangguiping-xydt force-pushed the fix/ocpr-issue-101290-20260724 branch from e7d2552 to d2271db Compare July 29, 2026 17:03
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 29, 2026
@clawsweeper

clawsweeper Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 4:12 PM ET / 20:12 UTC.

ClawSweeper review

What this changes

The PR routes plugin-state lookup, enumeration, key-range, and live-entry-count reads through a read-only shared-state accessor so CLI/runtime readers do not run the Gateway-owned writable SQLite lifecycle.

Merge readiness

⚠️ Needs maintainer review before merge - 3 items remain

Keep this PR open for maintainer review. The current-main source confirms the reported owner-boundary hazard, and the PR provides strong concurrent runtime proof, but this partial checkout cannot materialize the exact PR blobs because its promisor remote cannot resolve GitHub; a direct diff/correctness verdict would be unsafe. Likely related people: Vincent Koc (recent shared-state contributor; medium confidence).

Priority: P0
Reviewed head: caf9cac456aa05a8aa3eb86b67d37352f97a3eb9
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The runtime proof is strong, but the exact final implementation could not be independently materialized from this checkout.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body documents an after-fix concurrent ephemeral-Gateway run with separate-process plugin-state reads, Gateway writes, health checks, and successful SQLite quick and integrity checks.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body documents an after-fix concurrent ephemeral-Gateway run with separate-process plugin-state reads, Gateway writes, health checks, and successful SQLite quick and integrity checks.
Evidence reviewed 6 items Current owner-boundary hazard: On current main, plugin-state lookup opens its database through openPluginStateDatabase, whose uncached path calls the canonical writable state opener; this establishes the reported read-versus-writer lifecycle overlap as a real source-level concern.
Writable lifecycle performs maintenance: The current writable state opener performs permission handling, SQLite pragma configuration, integrity/schema checks, and schema setup before caching the database, so it is not an appropriate owner path for a read-only CLI lookup concurrent with a Gateway writer.
Existing read-only abstraction: Current main already has a dedicated read-only shared-state accessor that reuses an open non-transactional handle or opens SQLite with readOnly enabled, demonstrating the intended separation from the writable lifecycle.
Findings None None.
Security None None.

How this fits together

Plugin-state persists plugin-owned records in OpenClaw’s shared SQLite state database. CLI and runtime readers query that database while the Gateway owns schema setup, WAL configuration, permission changes, transactions, and writes; this boundary decides whether a read can mutate shared-state lifecycle.

flowchart LR
  CLI[CLI and runtime reads] --> PluginState[Plugin-state read APIs]
  PluginState --> ReadAccessor[Read-only state accessor]
  Gateway[Gateway process] --> WriteLifecycle[Writable state lifecycle]
  ReadAccessor --> StateDB[(Shared SQLite state)]
  WriteLifecycle --> StateDB
  StateDB --> Result[Plugin-state results]
Loading

Decision needed

Question Recommendation
Should this PR wait for an independently materialized exact-head source review, or may its supplied runtime proof and prior delegated verification be accepted as sufficient to merge a shared-state lifecycle change? Re-run exact-head source review: Restore access to the PR blobs, inspect the four-file diff and regression tests, then decide using the completed source evidence.

Why: The supplied concurrent Gateway proof is strong, but the local checkout cannot read the exact proposed blobs, so automation cannot safely verify the final code path or its upgrade-sensitive behavior.

Before merge

  • Resolve merge risk (P1) - The exact PR source blobs and complete four-file diff could not be read because the checkout’s promisor fetch failed DNS resolution; the proposed compatibility behavior for missing databases, quarantine, cached handles, and newer schemas remains unverified from source.
  • Resolve merge risk (P1) - This changes persisted shared-state access semantics. A divergence from the stated read-only path could affect plugin-state visibility or make CLI/runtime reads fail while the Gateway is live.
Agent review details

Security

None.

PR surface

Source +121, Tests +165. Total +286 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 207 86 +121
Tests 1 167 2 +165
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 374 88 +286

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/state/openclaw-state-db-readonly.ts, serialized state: src/state/openclaw-state-db.ts, unknown-data-model-change: src/state/openclaw-state-db-readonly.ts, unknown-data-model-change: src/state/openclaw-state-db.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Pause for exact-head review (recommended)
    Wait until a reviewer can materialize the four changed blobs and verify the read-only path, cached-handle reuse, and quarantine/schema behavior against the final commit.
  2. Accept the recorded proof
    A maintainer may merge using the documented concurrent Gateway proof and prior blob verification, while accepting the remaining independent-source-review gap.

Technical review

Best possible solution:

Materialize and review the exact head, then merge only if all plugin-state read APIs use the existing-state read-only path while writes remain on the canonical writable transaction owner and the stated missing/quarantine/schema behavior is covered.

Do we have a high-confidence way to reproduce the issue?

No deterministic corruption reproduction was established in this checkout. Source inspection does show that current plugin-state read APIs enter the writable state lifecycle, while the PR body supplies a real concurrent Gateway/CLI after-fix run with passing integrity checks.

Is this the best way to solve the issue?

Unclear: moving read APIs to the established read-only state-owner boundary is the right architectural direction, but the exact final implementation could not be inspected because the PR blobs are unavailable locally.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 6d339763186a.

Labels

Label justifications:

  • P0: The PR addresses a reported path in which normal CLI activity may corrupt or make unusable the shared runtime state database.
  • merge-risk: 🚨 session-state: It changes the access path for persisted plugin state stored in OpenClaw’s shared SQLite database.
  • merge-risk: 🚨 availability: An error in the new read accessor could make CLI and runtime plugin-state reads fail while the Gateway is active.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body documents an after-fix concurrent ephemeral-Gateway run with separate-process plugin-state reads, Gateway writes, health checks, and successful SQLite quick and integrity checks.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body documents an after-fix concurrent ephemeral-Gateway run with separate-process plugin-state reads, Gateway writes, health checks, and successful SQLite quick and integrity checks.

Evidence

What I checked:

  • Current owner-boundary hazard: On current main, plugin-state lookup opens its database through openPluginStateDatabase, whose uncached path calls the canonical writable state opener; this establishes the reported read-versus-writer lifecycle overlap as a real source-level concern. (src/plugin-state/plugin-state-store.sqlite.ts:370, 6d339763186a)
  • Writable lifecycle performs maintenance: The current writable state opener performs permission handling, SQLite pragma configuration, integrity/schema checks, and schema setup before caching the database, so it is not an appropriate owner path for a read-only CLI lookup concurrent with a Gateway writer. (src/state/openclaw-state-db.ts:542, 6d339763186a)
  • Existing read-only abstraction: Current main already has a dedicated read-only shared-state accessor that reuses an open non-transactional handle or opens SQLite with readOnly enabled, demonstrating the intended separation from the writable lifecycle. (src/state/openclaw-state-db-readonly.ts:31, 6d339763186a)
  • Current-main provenance: Blame attributes the current plugin-state read paths to Vincent Koc’s recent shared-state work, providing the strongest available routing signal for the central owner boundary. (src/plugin-state/plugin-state-store.sqlite.ts:1027, 89e4ef2ab721)
  • Exact-head inspection blocked: The PR commit object and four-file tree are present, but both its read-only accessor blob and plugin-state blob are promisor objects; Git attempted a fetch and failed because github.com could not resolve. Therefore the exact proposed source and diff could not be independently read in this checkout. (src/state/openclaw-state-db-readonly.ts, caf9cac456aa)
  • PR provenance: The PR head is four commits ahead of the frozen base. Its final commit adds newer read-only-schema coverage and is authored by Vincent Koc; the three preceding commits implement the proposed read-owner changes. (src/plugin-state/plugin-state-store.test.ts, caf9cac456aa)

Likely related people:

  • Vincent Koc: Current-main blame ties the central plugin-state read paths to Vincent Koc, and the PR’s final coverage commit is also authored by him. (role: recent shared-state contributor; confidence: medium; commits: 89e4ef2ab721, caf9cac456aa; files: src/plugin-state/plugin-state-store.sqlite.ts, src/state/openclaw-state-db-readonly.ts, src/state/openclaw-state-db.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Re-run review where the exact four changed blobs can be read.
  • Confirm the final read-only accessor preserves missing-file, quarantine, cached-handle, and newer-schema behavior before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-07-29T17:08:50.762Z sha d2271dba359491eefca16273c335e54527cb4754 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-30T06:08:23.304Z sha 74ac73fe597c21ff306f5f793f16278655303a74 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-30T10:27:54.185Z sha 3bdc6a4392471ca4650a8d4b1c9af20ee788f7ac :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T19:56:57.681Z sha 1325647c99884cb56c851c6e922012214ebe055d :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 30, 2026
@zhangguiping-xydt
zhangguiping-xydt force-pushed the fix/ocpr-issue-101290-20260724 branch from 74ac73f to 3bdc6a4 Compare July 30, 2026 10:22
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 30, 2026
@vincentkoc vincentkoc self-assigned this Jul 31, 2026
@vincentkoc
vincentkoc force-pushed the fix/ocpr-issue-101290-20260724 branch from 3bdc6a4 to 1325647 Compare July 31, 2026 19:50
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 31, 2026
@vincentkoc
vincentkoc force-pushed the fix/ocpr-issue-101290-20260724 branch from 1325647 to caf9cac Compare July 31, 2026 20:06
@vincentkoc

Copy link
Copy Markdown
Member

Maintainer disposition for the current exact head caf9cac456aa05a8aa3eb86b67d37352f97a3eb9:

This satisfies the two ClawSweeper Rank-up moves. The PR remains a bounded repair related to #101290; the broader issue must stay open.

@vincentkoc

vincentkoc commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

Maintainer disposition for caf9cac456aa05a8aa3eb86b67d37352f97a3eb9:

  • ClawSweeper’s exact-source gap is satisfied. The complete four-file diff and every changed blob were materialized and reviewed from a verified full clone. The read-only accessor preserves missing-file, quarantine, cached-handle, and newer-schema behavior; plugin-state writes remain on the canonical writable transaction owner.
  • Live main is b9dadca579e00cd26e2e3a752caf10ea498e254c. Its two post-base commits are unrelated, all four PR base blobs are unchanged, and git merge-tree --write-tree is clean.
  • Focused proof is green: 75 passed / 1 Windows-only skipped; the concurrent Gateway proof completed 2,748 read calls plus 40 real Gateway writes with healthy SQLite integrity; exact-head autoreview returned no actionable findings (0.98 confidence).
  • Exact-head hosted CI is terminal success: https://github.com/openclaw/openclaw/actions/runs/30661662854
  • There are zero unresolved review threads.

Both Rank-up moves are addressed. This bounded PR is ready to merge. It remains only related to #101290; the broader issue must stay open.

@vincentkoc
vincentkoc merged commit 6883176 into openclaw:main Jul 31, 2026
193 of 197 checks passed
vincentkoc added a commit that referenced this pull request Jul 31, 2026
* origin/main: (22 commits)
  fix(cron): preserve lazy ownership and bounded notification lifetimes (#117018)
  fix: live updater no-op restarts healthy gateways (#117038)
  fix(bedrock): release streaming clients (#117039)
  fix(google): restore canonical Gemini and Vertex provider invariants (#117042)
  fix(channels): preserve accepted LINE and Mattermost delivery (#117024)
  fix(feishu): unify truthful delivery and media ownership (#117023)
  fix(ui): isolate gateway observer lifecycles (#117017)
  fix(tui): keep reset transitions isolated from stale input (#116873)
  fix(gateway): centralize streamed media descriptor ownership (#117000)
  feat(plugins): externalize OpenCode provider (#117035)
  fix(onboarding): restore skill dependency consent (#116644)
  fix(streaming): preserve incomplete bracket tails in final replies (#116983)
  fix: allow slower gateway readiness after updates (#117032)
  fix(plugin-state): avoid shared SQLite corruption when CLI starts during gateway runtime (#113204)
  fix(cli): keep config file output raw under JSON logging (#116968)
  fix(ai): malformed Anthropic stream frames expose raw event payloads (#116938)
  fix(qa): authenticate actual scenario execution evidence (#117004)
  feat(plugins): externalize NovitaAI provider (#117007)
  fix(text): preserve fenced tool markers in visible-text sanitizer (#116939) (#116971)
  fix(channels): reset metadata memos with plugin lifecycle (#117005)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
…ing gateway runtime (openclaw#113204)

* fix(plugin-state): keep reads outside writable state lifecycle

* fix(state): keep open guard private

* fix(state): preserve cached read-only handles

* test(plugin-state): cover newer read-only schemas

---------

Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants