Skip to content

fix: keep doctor lint from migrating shared state - #124110

Merged
fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:codex/openclaw-doctor-lint-readonly-20260815
Aug 15, 2026
Merged

fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:codex/openclaw-doctor-lint-readonly-20260815

Conversation

@fuller-stack-dev

Copy link
Copy Markdown
Member

Related: #119583

What Problem This Solves

Fixes an issue where operators running openclaw doctor --lint --all --json against an existing environment could have the supposedly read-only command open the shared SQLite database through writable owners and migrate it. During a candidate-runtime preflight, that can make the still-running older gateway unable to read its own durable state.

Why This Change Was Made

Every lint check now reads existing state through its owning non-creating, non-migrating SQLite seam: heartbeat scratch, exec approvals, workspace setup, task/task-flow status, and device pairing. Ordinary runtime and explicit repair paths retain their existing writable migration behavior. A process-wide write switch or post-hoc rollback was rejected because either can expose partially migrated state or turn diagnostics into hidden write failures.

User Impact

Operators can run the documented read-only doctor lint flow on older shared-state schemas without advancing the schema, creating a database, or adding WAL/SHM artifacts. Normal gateway startup, repair, pairing, approvals, and workspace/task persistence continue to migrate and write as before.

Evidence

  • Red on the exact schema-7 parent (72e67904be8b17985b18893ece68fccaea50cb59): heartbeat-only and full --all lint advanced PRAGMA user_version from 7 to 8 and changed the database digest.
  • Green on exact head a620205caa18c09559efbe16800c6328074ed0cf: full --lint --all --json returned parseable JSON while schema version, seeded rows, database SHA-256, and state-directory inventory remained identical; no WAL/SHM appeared (98.1s check execution).
  • Absent-database regressions cover heartbeat scratch, exec approvals, workspace setup/bootstrap, task registry, task-flow registry, and device pairing.
  • Focused owner/runtime suites: 94 tests passed; task/task-flow registry suites: 53 passed; CLI policy/registration/lint suites: 68 passed; device pairing: 9 passed; workspace status: 12 passed.
  • Existing writable repair/runtime tests remain green as negative controls.
  • oxlint for all changed files: 0 warnings/errors. oxfmt --check and git diff --check: passed.
  • Source-blind behavior contract: passed against a copied schema-7 environment.
  • Autoreview (Codex, high reasoning) and TruffleHog: clean on the exact patch.

Production LOC: +226/-43 (net +183). This growth is the explicit owner boundary needed to preserve diagnostic output across five independent stores without changing ordinary writable callers. Tests: +176/-5.

AI-assisted: yes. I reviewed the owner paths, reproduction, generated diff, and validation results.

@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.

@fuller-stack-dev
fuller-stack-dev marked this pull request as ready for review August 15, 2026 08:40
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Aug 15, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: needs maintainer review before merge. Reviewed August 15, 2026, 4:45 AM ET / 08:45 UTC.

ClawSweeper review

What this changes

This PR changes doctor lint checks to read existing shared SQLite state without creating or migrating it, while leaving runtime and repair writes unchanged.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for maintainer review and exact-head CI. The patch uses the existing read-only SQLite lifecycle at each affected owner boundary; no blocking correctness or security defect was found.

Priority: P1
Reviewed head: a620205caa18c09559efbe16800c6328074ed0cf
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has coherent owner-boundary coverage and strong submitted terminal proof, with exact-head CI and protected maintainer review still pending.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: This MEMBER-authored PR is not subject to the external contributor proof gate; its body nevertheless includes exact-head terminal evidence for the schema-7 no-migration behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored PR is not subject to the external contributor proof gate; its body nevertheless includes exact-head terminal evidence for the schema-7 no-migration behavior.
Evidence reviewed 6 items Current-main affected path: Current main's heartbeat migration detector calls the writable scratch reader, whereas the PR changes that diagnostic path to the read-only reader.
Canonical read-only owner boundary: The existing helper opens only an existing database read-only and explicitly avoids schema repair, journal setup, checkpoints, and permission mutation.
PR applies the boundary across lint owners: The PR routes bootstrap, heartbeat, approvals, task/task-flow recovery, and local pairing diagnostics through store-specific read-only seams with safe absent-database results.
Findings None None.
Security None None.

How this fits together

Doctor lint collects health findings from Gateway-owned shared state such as heartbeat, task, pairing, approval, and workspace records. Its diagnostics feed terminal or JSON output and must not contend with or migrate a live Gateway database.

flowchart LR
  A[Doctor lint request] --> B[Health check selection]
  B --> C[State-owning diagnostic readers]
  C --> D{Database exists?}
  D -->|Yes| E[Read-only SQLite snapshot]
  D -->|No| F[Safe empty diagnostic state]
  E --> G[Health findings JSON]
  F --> G
Loading

Decision needed

Question Recommendation
Does the shared-state owner approve these five diagnostic readers as the canonical no-migration lint boundary once exact-head CI is green? Approve the read-only lint boundary: Retain the owner-specific readers and merge after the exact PR head has green required checks.

Why: The protected maintainer label covers a cross-cutting shared-state lifecycle change whose final ownership and landing scope require human sign-off.

Before merge

  • Resolve merge risk (P1) - This compatibility-sensitive change adds five owner-specific non-migrating read paths; exact-head CI should confirm that older supported state still yields useful lint findings rather than diagnostics failures.
  • Complete next step (P2) - The protected maintainer label and shared-state lifecycle impact require owner review after exact-head CI; no repair worker action is indicated.
Agent review details

Security

None.

PR surface

Source +183, Tests +171. Total +354 across 24 files.

View PR surface stats
Area Files Added Removed Net
Source 16 226 43 +183
Tests 8 176 5 +171
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 24 402 48 +354

Review metrics

Metric Value Why it matters
Production versus test LOC production +226/-43 (net +183); tests +176/-5 The production growth creates owner-specific read-only adapters and fallbacks across independent state stores; test growth covers their no-create and no-migrate contracts.

Stored data model

Persistent data-model change detected: database schema: src/commands/doctor-heartbeat-task-migration.test.ts, database schema: src/infra/exec-approvals-store.test.ts, migration/backfill/repair: src/commands/doctor-device-pairing.test.ts, migration/backfill/repair: src/commands/doctor-heartbeat-task-migration.test.ts, migration/backfill/repair: src/commands/doctor-heartbeat-task-migration.ts, migration/backfill/repair: src/commands/doctor-workspace-status.test.ts, and 11 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #119583
Summary: This PR is a candidate repair for the doctor-lint portion of the linked shared-state writer-contention issue.

Members:

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

Merge-risk options

Maintainer options:

  1. Require current-head upgrade proof (recommended)
    Before merge, retain the copied schema-7 full-lint verification and wait for required checks on the exact head to confirm diagnostics remain compatible without migration.

Technical review

Best possible solution:

Keep the store-specific read-only seams and existing writable runtime/repair paths, then merge only after exact-head CI and the documented schema-7 full-lint proof remain valid.

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

Yes: current main’s heartbeat detector calls the writable reader, and the PR body supplies a concrete schema-7 before/after command path; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes: routing each diagnostic through its owning read-only state seam uses the existing lifecycle contract and avoids a process-wide write switch or rollback workaround.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5d601233df88.

Labels

Label changes:

  • add P1: The linked report describes doctor diagnostics contending with a live Gateway's shared SQLite writer and causing operator-visible stalls.
  • add merge-risk: 🚨 compatibility: The PR changes how existing and older shared-state databases are opened during documented diagnostics.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored PR is not subject to the external contributor proof gate; its body nevertheless includes exact-head terminal evidence for the schema-7 no-migration behavior.

Label justifications:

  • P1: The linked report describes doctor diagnostics contending with a live Gateway's shared SQLite writer and causing operator-visible stalls.
  • merge-risk: 🚨 compatibility: The PR changes how existing and older shared-state databases are opened during documented diagnostics.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored PR is not subject to the external contributor proof gate; its body nevertheless includes exact-head terminal evidence for the schema-7 no-migration behavior.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Blame attributes the existing shared-state read-only helper used by this PR to this commit; that helper defines the central lifecycle contract. (role: introduced shared read-only lifecycle helper; confidence: high; commits: f8fcc7f99b8a; files: src/state/openclaw-state-db-readonly.ts)

Rank-up moves

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

  • Complete required checks on the exact PR head.
  • Obtain shared-state owner sign-off for the diagnostic lifecycle boundary.

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.

@fuller-stack-dev fuller-stack-dev self-assigned this Aug 15, 2026
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Maintainer owner review complete at a620205caa18c09559efbe16800c6328074ed0cf.

ClawSweeper rank-up moves are satisfied: exact-head required CI is green, and the five owner-specific non-migrating readers are approved as the canonical diagnostic boundary. The copied schema-7 behavior proof remains unchanged: full doctor --lint --all --json returned parseable JSON without changing the database digest, schema version, rows, state inventory, or creating WAL/SHM files. Ordinary writable runtime and repair paths remain covered as negative controls.

@fuller-stack-dev
fuller-stack-dev merged commit b1b06d1 into openclaw:main Aug 15, 2026
272 of 282 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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.

1 participant