Repository navigation
refactor(cli): read-only database access for pure-read commands - #110732
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d1413f985
ℹ️ 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".
| @@ -122,7 +122,8 @@ export async function exportTrajectoryCommand( | |||
| const storePath = resolvedOpts.store | |||
| ? resolveStorePath(resolvedOpts.store, { agentId: targetAgentId }) | |||
| : resolveStorePath(getRuntimeConfig().session?.store, { agentId: targetAgentId }); | |||
| const entry = loadSessionEntry({ | |||
| // CLI reads must not join the Gateway's writable SQLite lifecycle (#101290). | |||
| const entry = loadSessionEntryReadOnly({ | |||
There was a problem hiding this comment.
Finish making trajectory export read-only
When exporting a SQLite-backed trajectory, this read-only lookup is followed by exportTrajectoryForCommand, whose SQLite path calls loadTranscriptEvents (src/trajectory/export.ts:202) and loadSqliteTrajectoryRuntimeEvents (src/trajectory/export.ts:366); those still reach openOpenClawAgentDatabase in src/config/sessions/session-accessor.sqlite-read.ts:45 and src/trajectory/runtime-store.sqlite.ts:98, which registers the agent DB and joins the writable lifecycle. So openclaw sessions export-trajectory still mutates agent_databases/takes write-side SQLite setup in the exact corruption-avoidance scenario this comment claims is converted; either keep this command out of the read-only tranche or add read-only transcript/runtime readers before switching it.
Useful? React with 👍 / 👎.
4d1413f to
45ae836
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 45ae83668d
ℹ️ 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".
| const sqlite = requireNodeSqlite(); | ||
| const db = new sqlite.DatabaseSync(pathname, { readOnly: true }); |
There was a problem hiding this comment.
Refuse quarantined agent DBs before read-only opens
When an agent DB has already been quarantined by integrity verification, this helper still opens it read-only and executes the caller's SELECTs; unlike openOpenClawAgentDatabase (src/state/openclaw-agent-db.ts:166) it never consults readOpenClawDatabaseQuarantine, and verification persists those rows in src/state/openclaw-database-verify.impl.ts:167. The converted loadSessionEntryReadOnly commands can therefore export/explain data from a known corrupt database instead of failing closed with doctor guidance; add the same quarantine gate before constructing the read-only handle.
Useful? React with 👍 / 👎.
| return []; | ||
| } | ||
| // CLI reads must not join the Gateway's writable SQLite lifecycle (#101290). | ||
| return withOpenClawStateDatabaseReadOnly( |
There was a problem hiding this comment.
Keep state quarantine on read-only fleet reads
After this conversion, fleet list/status/doctor reaches the shared DB through withOpenClawStateDatabaseReadOnly; that helper opens the file directly, so a shared-state quarantine row that openOpenClawStateDatabase would refuse at src/state/openclaw-state-db.ts:339 is bypassed. In the scenario where verification has quarantined state/openclaw.sqlite, these read commands still query a known corrupt DB and can report bogus cells; gate the read-only state path on the persisted quarantine before querying.
Useful? React with 👍 / 👎.
|
Merged via squash.
|
What Problem This Solves
Corruption incident #101290 was triggered by CLI one-shot processes opening the live databases writable alongside the running gateway - and a survey showed how broad that surface is: even pure-read commands join the full writable lifecycle (journal recovery, WAL setup, permissions repair, and a shared-DB
agent_databasesregistration on every agent open). There was a read-only helper for the state DB but none for agent DBs.Why This Change Was Made
First, deliberately narrow tranche of the read-only program - pure reads only, zero product-behavior change:
withOpenClawAgentDatabaseReadOnly(src/state/openclaw-agent-db-readonly.ts): read-only connection, newer-schema gate, owner check, typed not-found for missing databases; never creates, registers, migrates, or repairs. Aligned with the just-landed agent-db module split (imports its schema helpers rather than duplicating).sessions export-trajectoryandsandbox explainsession loads,fleet list/status/doctor,onboard recommendations, separablesandbox listregistry reads, and the TUI remembered-session startup read (its writer is untouched).agent_databaseswithout a new row.Deliberately out of scope (maintainer product decisions, documented in the survey): status/health aggregation via RPC, config-health observation defaults, maintenance-on-read commands (
pairing list,commitments list,worktrees list), and cache-writing list commands (promotions, model catalog, marketplace).User Impact
Read-only commands no longer take write locks or mutate shared state as a side effect - fresh installs and concurrent-gateway scenarios behave identically, with less exposure to the #101290 corruption class.
Evidence
pnpm check:test-types,git diff --check: green.