Repository navigation
fix: avoid copying live state during read-only inspection - #202608
Conversation
|
🦞👀 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 Summary: ✅ CompletedThis 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. |
|
Codex review: needs changes before merge. What this changesThis PR avoids private SQLite copies for ordinary shared-state inspection when the database has a verified live owner. Example: Run
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 6 items remain This PR addresses a concrete inspection bottleneck that remains on main, but the broader direct-read selection introduces owner-verification, schema-refusal, and scoped-consistency regressions. Priority: P1 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherThe shared-state read owner selects cached connections, direct read-only connections, or private SQLite images for CLI, plugin, config, and Doctor readers. flowchart TD
A[CLI and Doctor inspection] --> B[Shared state read owner]
B --> C[Explicit frozen scope]
B --> D[Live owner verification]
C --> E[Private SQLite image]
D --> F[Direct read only connection]
D --> E
E --> G[Committed query results]
F --> G
Technical reviewBest possible solution: Keep direct reads in the existing owner while preserving unknown-owner fallback, current schema admission, and one committed view per explicit synchronous scope. Do we have a high-confidence way to reproduce the issue? The base selects private snapshots for ordinary artifact-preserving reads, and the supplied regression fails on that base; this review inspected source and recorded CI failures without executing target code. Is this the best way to solve the issue? Centralizing copy avoidance in the existing read owner is appropriate, but a verified live owner cannot replace fallback handling, supported-schema admission, or explicit scope consistency. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1129d4c0716c. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource -4, Tests -1, Docs +3. Total -2 across 4 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. LabelsLabel changes:
Label justifications:
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 20, 2026, 12:16 PM ET / 17:16 UTC. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3e110f112f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return undefined; | ||
| } | ||
| if (!snapshot && preserveArtifacts && !independentWarmSource) { | ||
| if (!snapshot && !independentWarmSource) { |
There was a problem hiding this comment.
Keep PostgreSQL reads out of the SQLite metadata fast path
When shared state uses PostgreSQL and a separate CLI process reads metadata beside a live Gateway, preserveArtifacts is false and native is undefined. Removing the former guard now lets currentMetadata become true because PostgreSQL Gateways also acquire the state-owner lock (src/infra/gateway-lock.ts). This routes the request through startupMetadata.readCurrent, whose implementation opens the SQLite anchor directly rather than the PostgreSQL connection. The anchor contains openclaw_engine_anchor, not the state tables, so config-health and plugin-metadata queries fail instead of reading PostgreSQL. Gate this fast path on the SQLite backend while retaining the new direct-read behavior for live SQLite owners.
Useful? React with 👍 / 👎.
|
Merged via squash.
|
Consume the owner lifecycle’s existing path admission instead of resolving and reading the owner sidecar on every live check. Keep persisted verification for offline and unadmitted readers. This fixes the host identity-read regression from #202608 while retaining its no-copy behavior.
…02608) * fix: avoid copying live state during read-only inspection * fix: preserve live metadata and unverified-owner inspection
Consume the owner lifecycle’s existing path admission instead of resolving and reading the owner sidecar on every live check. Keep persisted verification for offline and unadmitted readers. This fixes the host identity-read regression from openclaw#202608 while retaining its no-copy behavior.
* fix: avoid copying live state during read-only inspection * fix: preserve live metadata and unverified-owner inspection (cherry picked from commit 2225592) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 8d2642eff08844061a82af7ab5df6f4a7f775a9c) (cherry picked from commit 1a7533851a6c13c9fb913d7035bef6e8cc4bc2a1)
Consume the owner lifecycle’s existing path admission instead of resolving and reading the owner sidecar on every live check. Keep persisted verification for offline and unadmitted readers. This fixes the host identity-read regression from #202608 while retaining its no-copy behavior. (cherry picked from commit 9175df9) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 56fe38c7ed1ba774955b94ed0793c9927dee7f41) (cherry picked from commit 890454cafacfd2b7a11f8461b2193d53fa179bc8)
Baseline adaptation: Use the canonical owner path, matching live process identity and existing WAL/SHM sidecars to select the stable-line direct read path. Retain offline and explicit frozen snapshots; no newer state-read controller or store schema. (cherry picked from commit 2225592) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 03c531bae60afb99d8de7800e0ecd453ef8f6dfb)
What Problem This Solves
Running
openclaw plugins update better-prompt --dry-runbeside a live Gateway took 192 seconds against a 30.2 GB shared state database. In about 150 seconds, its snapshot child read 104.5 GB and wrote 107.2 GB (about 3.5 whole-file copies). Concurrent session commits stalled for 26.1 and 12.3 seconds, and the write-reservation queue reached 22.6 seconds.User Impact
Ordinary read-only inspection of a shared state database with a verified live owner now reads directly through a read-only connection, avoiding whole-file staging. This covers deferred plugin migrations and the shared-state reads used by config, templates, plugins, and Doctor. Offline inspection and unverifiable owner identities keep artifact-preserving private copies and its existing sidecar/lock guarantees.
Why This Change Was Made
At base
dacf5604e469,src/state/openclaw-state-db-readonly.ts:273selected a private copy for every ordinary artifact-preserving shared-state read without checking the live owner. The shared decision now uses the existing exact-database owner verification before selecting a copy, covering synchronous, awaited, async, and reusable-image paths.The existing metadata live-read path in
src/state/openclaw-state-read-operation.ts:329now remains independent of the private-copy decision. That preserves its fresh schema-version rejection when a live writer advances the header; it still reads directly without staging.Explicit frozen inspection scopes remain unchanged. In particular,
openclaw update status(src/cli/update-cli/status.ts:126, contract insrc/state/openclaw-state-inspection-snapshot.ts:7) still prepares one private image. Follow-up: a live-owned source could provide that frozen image through one transaction on a direct read-only connection, using WAL snapshot isolation instead of copying files. No copy-effect refusal or new transport option is introduced here.The reported 1,222 empty
sqlite-*namespace roots remain a follow-up:src/infra/sqlite-private-directory.ts:79creates them andsrc/infra/sqlite-snapshot-reclamation.ts:77skips namespace entries. Removing an empty root can race an allocator that has already resolved it but has not calledmkdtemp; safely changing that lifecycle exceeds this bounded repair.Release-note context: CLI inspection beside a live Gateway avoids copying the entire shared state database while retaining offline artifact preservation.
Evidence
The real deferred-migration reader runs against a database with a verified local SQLite owner. Ordinary reads prepare zero snapshots across sync, awaited, async, and reuse paths; an explicit frozen scope still prepares exactly one. Existing offline preservation tests remain covered. The new regression shares its fixture with the existing concurrent online-backup proof, and redundant availability/callback setup is folded together to keep net test lines nonpositive.
Red on base
dacf5604e46997f146e58b2f088bb3d3340b89fc(final regression, original production reader):Green with the fix (same regression plus its touched owner suite):
The four counters cover sync, async, awaited, and retained-async preparation entry points; delegated preparation calls overlap and are not distinct-copy counts. The frozen-scope assertion expects
[0, 0, 0, 1]after the zero-preparation reads.SIGTRAP. That exact case passed under the repository-supported Node test runtime (1 passed, 36 skipped). Passing replay does not repair the Bun probe; CI remains the broad proof.OPENCLAW_VITEST_RUNTIME=node.pnpm tsgo:core, the targeted state-logging test typecheck, targeted oxlint,pnpm format:check -- <four touched paths>, andgit diff --checkpassed.$autoreviewcompleted scoped-clean with no actionable P2-or-higher findings.44779074317exposed a real metadata consumer regression: its newer-schema assertion resolved instead of rejecting. Reproduced only that failed case locally; the bounded read-operation guard repair preserves the existing fresh metadata path. Only the failed metadata case was rerun after repair: 1 passed, 14 skipped. A second failed shard exposed seven Doctor cases whose predecessor file records omit process-start identity; the copy decision now treats that typed unknown-verification result as unverified and keeps the existing private-copy behavior. It never authorizes a direct read from an unknown identity. The failed-case replay passes all 8 selected cases (14 unrelated cases skipped). Follow-up autoreview caught a copy-permission assertion ordered before verification; that finding is fixed, and final autoreview is scoped-clean at P2. Replacement CI will verify the exact repair head.