Skip to content

fix: keep status read-only while gateway owns state - #124142

Merged
jalehman merged 2 commits into
mainfrom
find-the-local-openclaw-clone-update-e0d/status-read-only-state
Aug 15, 2026
Merged

jalehman merged 2 commits into
mainfrom
find-the-local-openclaw-clone-update-e0d/status-read-only-state

Conversation

@jalehman

Copy link
Copy Markdown
Contributor

Closes #124045

AI-assisted: Codex.

What Problem This Solves

Fixes an issue where operators running status commands while a gateway was active could cause the secondary CLI process to open the shared SQLite database writable and execute schema setup. This violated the gateway's write ownership, could block behind another writer, and preceded the physical database corruption reported in #124045.

Why This Change Was Made

Status inspection now reads persisted task, node-host, restart-sentinel, config-health, and exec-approval state through explicit read-only paths. It no longer initializes the process task registry or enters the schema-owning shared-state lifecycle. Runtime writers remain on their existing lifecycle, and the SQLite schema version does not change.

User Impact

openclaw status, status --json, status --all, and channels status --probe --json can inspect configured state without creating the shared database or joining its write lifecycle. JSON status can read committed task state while the gateway is running and another process holds BEGIN IMMEDIATE.

Evidence

  • Before the fix, the E2E reproduction created state/openclaw.sqlite from an offline status command. With a live gateway and held writer transaction, status --json exited 1 with Task registry restore failed: database is locked.
  • node scripts/run-vitest.mjs test/status-shared-state-readonly.e2e.test.ts: 5 tests passed. The harness exercises text, JSON, all, and channel-probe status modes, verifies the gateway stays alive under writer contention, and requires PRAGMA integrity_check = ok.
  • Focused owner and sibling validation: 202 tests passed across task registry, status, config validation, restart sentinel, exec approvals, and exec defaults.
  • node scripts/check-changed.mjs: passed all selected core, core-test, root-test, and tooling lanes. Crabbox had no ready provider, so the repository wrapper completed its documented local fallback.
  • git diff --check and the final changed-lane dry run passed after rebasing onto c9da900a961.
  • Production delta: +112/-46 lines. The added surface is the explicit read-only ownership boundary and the dependency injection needed to keep status off write-capable loaders. Test and test-support delta: +147/-12 lines.
  • Test audit: the regression protects command-level filesystem and cross-process behavior, failed on the pre-fix code for the reported lock path, and adds no test-only production seam.
  • Structured autoreview raised one repository-wide WAL/no--shm recovery concern in the pre-existing shared read-only helper. A local crash reproduction succeeded by reconstructing -shm; failure requires a non-writable source directory. That generic hardening remains a separate follow-up because this issue concerns a live gateway, where the WAL sidecars already exist.

@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Aug 15, 2026
@jalehman
jalehman marked this pull request as ready for review August 15, 2026 09:56
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 15, 2026, 9:56 AM ET / 13:56 UTC.

ClawSweeper review

What this changes

The PR routes CLI status, channel-status fallback, task summaries, restart state, node-host settings, and approval data through read-only shared-state access so status does not join the Gateway’s write lifecycle.

Regression provenance

Possible regression — probable (reproduction; reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Needs maintainer review before merge - 4 items remain

Keep this PR open: its read-only ownership repair is valuable and has credible multi-process proof, but the prior P1 remains on the unchanged head—older supported state schemas can reach current-column task queries and make offline status fail.

Priority: P1
Reviewed head: 7e922f267c9ee260962357f823fca046cb20ab2f

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The ownership repair and real-path evidence are useful, but the unaddressed legacy-schema P1 blocks merge readiness.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body documents an after-fix cross-process CLI/SQLite E2E run covering status modes, writer contention, Gateway survival, and integrity checking; the remaining gap is legacy-schema coverage, not real-behavior proof.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body documents an after-fix cross-process CLI/SQLite E2E run covering status modes, writer contention, Gateway survival, and integrity checking; the remaining gap is legacy-schema coverage, not real-behavior proof.
Evidence reviewed 6 items Current status entry point: The current status overview lazily invokes the aggregate status summary, whose current implementation initializes the task-registry maintenance runtime before inspecting tasks; the PR replaces that write-capable path with a read-only snapshot.
Read-only helper permits older schemas: The shared read-only helper rejects only schema versions newer than the current version; it permits versions below the current schema without a migration-required outcome.
Current task query requires current columns: The task snapshot selects current task columns including owner_key and scope_kind, while the writer path explicitly treats any lower user_version as migration-pending before it runs schema setup.
Findings 1 actionable finding [P1] Handle legacy schemas before reading task rows
Security None None.

How this fits together

Operator status commands aggregate configuration, task state, gateway diagnostics, and service metadata. They must inspect the shared SQLite database without performing the schema, WAL, or write-lifecycle work owned by the running Gateway.

flowchart LR
  A[Operator status command] --> B[Status overview]
  B --> C[Read-only state access]
  C --> D{Schema usable for read}
  D -->|Current| E[Task and service snapshots]
  D -->|Older schema| F[Doctor migration guidance]
  E --> G[Status output]
  F --> G
Loading

Before merge

  • Handle legacy schemas before reading task rows (P1) - withExistingOpenClawStateDatabaseReadOnly rejects only future schemas, while this new read-only snapshot immediately selects current task_runs columns. A valid v5–v7 database that would normally be migrated by the writer can therefore make offline status fail; detect it first and return a non-writing Doctor migration outcome. This remains from the prior review on the unchanged head.
  • Resolve merge risk (P1) - Existing v5–v7 databases can reach the new read-only task query because its helper accepts older schemas; status may then fail on current task columns instead of reporting the non-writing migration path.
  • Resolve merge risk (P1) - The bug fix adds production code (+66 net lines); the per-owner read-only accessors should remain limited to necessary ownership boundaries after the schema guard is added.
  • Complete next step (P2) - The remaining P1 is mechanically clear, but the protected maintainer label requires explicit maintainer handling before merge or repair dispatch.

Findings

  • [P1] Handle legacy schemas before reading task rows — src/tasks/task-registry.store.sqlite.ts:363
Agent review details

Security

None.

PR surface

Source +66, Tests +135. Total +201 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 11 112 46 +66
Tests 7 147 12 +135
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 259 58 +201

Review metrics

Metric Value Why it matters
Production versus test delta production +112/-46 (net +66); tests +147/-12 (net +135) The added read-only owner boundary is substantive bug-fix growth and needs the legacy-schema guard before its compatibility benefit is safe.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #124045
Summary: This PR is the candidate fix for the documented status-process shared-state ownership bug; it remains incomplete until legacy schemas are handled.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Handle older schemas before task reads (recommended)
    Detect a lower shared-state schema in the read-only path and preserve status output with explicit Doctor migration guidance before any current-column query.
  2. Accept offline-status breakage on old state
    Merge only if maintainers explicitly decide that status is unsupported until an operator migrates every pre-v8 database.

Technical review

Best possible solution:

Reject stale shared-state schemas before task reads and return a clear non-writing openclaw doctor --fix outcome, with regression coverage for an offline pre-v8 database and the current concurrent-Gateway path.

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

Yes, by source: use an existing v5–v7 shared-state database offline and invoke a status mode that loads the task summary; the read-only helper permits it before the current-column task query runs.

Is this the best way to solve the issue?

No: the ownership boundary is the right layer, but it must also reject or diagnose older schemas without writing before it queries current task data.

Full review comments:

  • [P1] Handle legacy schemas before reading task rows — src/tasks/task-registry.store.sqlite.ts:363
    withExistingOpenClawStateDatabaseReadOnly rejects only future schemas, while this new read-only snapshot immediately selects current task_runs columns. A valid v5–v7 database that would normally be migrated by the writer can therefore make offline status fail; detect it first and return a non-writing Doctor migration outcome. This remains from the prior review on the unchanged head.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3e471bd6e46a.

Labels

Label justifications:

  • P1: The unresolved defect can break routine status inspection for existing upgraded installations.
  • merge-risk: 🚨 compatibility: The new read-only path accepts older state schemas but queries current task columns.
  • merge-risk: 🚨 session-state: The changed status flow reads persisted task and approval state from the shared session-state database.
  • merge-risk: 🚨 availability: An older database can make offline status fail rather than provide the intended diagnostic output.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR body documents an after-fix cross-process CLI/SQLite E2E run covering status modes, writer contention, Gateway survival, and integrity checking; the remaining gap is legacy-schema coverage, not real-behavior proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body documents an after-fix cross-process CLI/SQLite E2E run covering status modes, writer contention, Gateway survival, and integrity checking; the remaining gap is legacy-schema coverage, not real-behavior proof.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Current blame ties both the read-only schema gate and status task initialization to the recent shared-state refactor. (role: recent shared-state and status contributor; confidence: high; commits: 4fc375654d34; files: src/state/openclaw-state-db-readonly.ts, src/status/summary.ts)
  • Jason (Json): The most recent history entry for the task-registry SQLite store is their state-safety work. (role: recent task-registry contributor; confidence: medium; commits: b1b06d12125b; files: src/tasks/task-registry.store.sqlite.ts)
  • xingzhou: Commit 6883176 introduced an earlier CLI-versus-Gateway shared-SQLite corruption hardening pass. (role: earlier shared-state hardening contributor; confidence: medium; commits: 688317628afe; files: src/state/openclaw-state-db-readonly.ts, src/tasks/task-registry.store.sqlite.ts)

Rank-up moves

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

  • Add a pre-v8 database regression that proves status gives Doctor guidance without creating, migrating, or querying unavailable task columns.

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 (2 earlier review cycles)
  • reviewed 2026-08-15T10:49:33.263Z sha 7e922f2 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-15T11:56:21.066Z sha 7e922f2 :: found issues before merge. :: [P1] Handle legacy schemas before reading task rows

@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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

The legacy-schema P1 does not reproduce with a canonical supported schema.

I compared the complete task_runs table definitions from the repository's v5, v6, v7, and current schema SQL. Every column selected by loadTaskRegistryStateFromSqliteReadOnly() exists in all four definitions. In particular, owner_key and scope_kind have existed since schema v1. The later selected columns were present by v2, before the v5-v7 range cited in the review.

I then created isolated databases from the exact historical schema files, set each database's PRAGMA user_version, and ran this PR's status --json against them:

Schema Historical ref Exit stderr Database modified
v5 509a5f03737^ 0 empty no
v6 b6548e509aa^ 0 empty no
v7 0a6b95a3df9^ 0 empty no

Each command returned the expected zero-valued task summary. SQLite prepares the full task query even with no rows, so a missing selected column would fail here.

As a negative control, I removed owner_key from a synthetic database marked v7. That command exited 1 with no such column: "owner_key", which confirms the harness detects the proposed failure. OpenClaw never shipped that table shape as v7.

The actionable P1 and its duplicate merge-risk items are therefore nonissues for valid v5-v7 databases. A general policy that blocks all lower user_version values would be a separate behavior change, not a repair for an unavailable task column.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@jalehman
jalehman merged commit 9663cc7 into main Aug 15, 2026
269 checks passed
@jalehman
jalehman deleted the find-the-local-openclaw-clone-update-e0d/status-read-only-state branch August 15, 2026 14:21
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
SemonCat pushed a commit to SemonCat/openclaw that referenced this pull request Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: current main CLI status runs state.schema.ensure beside live gateway before shared DB corruption

1 participant