Skip to content

fix(state): give one actionable answer for state written by a newer release and keep status reads read-only - #166963

Merged
steipete merged 3 commits into
mainfrom
upd/upd-newer-schema-one-answer
Oct 8, 2026
Merged

steipete merged 3 commits into
mainfrom
upd/upd-newer-schema-one-answer

Conversation

@steipete

@steipete steipete commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes contradictory repair advice and SQLite sidecar creation when an older OpenClaw build inspects state written by a newer release. Related: #166906 and #166857.

User Impact

Doctor, Gateway startup, update status, and offline database preflight consistently recommend a compatible newer build or restoration of the backup matching the older build. They preserve the newer database's bytes, mtimes, and SQLite sidecars. No schema, migration, configuration option, CLI option, or dependency changes.

Why This Change Was Made

Reuse the existing newer-schema classification and artifact-preserving reader. Doctor omits the generic repair tail; fleet preflight stops interpreting an unsupported registry; offline preflight checks the version before integrity. Update status also prepares its Gateway probe's device identity through the diagnostic reader, because the default asynchronous identity lookup opens a shared actor even for existing-only reads.

The explicit-file preflight implementation moves to a focused sibling to keep the owning module within its line cap. Its existing export remains available, and the native wrapper inventory includes the new module.

Evidence

  • Negative controls reproduce all four defects, including WAL/SHM creation through the real Gateway probe. Assertions compare database bytes, nanosecond mtimes, and sidecar sets.
  • Touched suites ran three times: Doctor maintenance (46 tests), explicit-file/Gateway preflight (7 tests), and real-probe status artifact preservation (2 tests). The original status suite remains unchanged and passes with its importers.
  • All runnable tests in the 69-importer selection and six repository closure guards passed. Status importers and the affected closure/routing guards passed again after the identity-read fix. Existing platform skips remain unchanged.
  • node scripts/check-changed.mjs --base f0258248b3e0a1fc5a09bd4060a2f494c35b42c9 passed, including full core/test typechecks, full core lint, script lint, ratchets, and import-cycle/closure checks.
  • Independent P1 review was attempted through Codex, but both attempts returned HTTP 401 and produced no verdict. Maintainer review of this head is still required. Auto-merge is off.

Fresh isolated copies of released [email protected] state used shared-state user_version 19 → 21 and the unreadable Workshop index mutation; this build supports schema 20. All five real CLI cases passed on the final build, preserving every SQLite-family file hash, nanosecond mtime, and file-set membership. No service or listener remained active.

Command Exit Result
doctor --json 2 Newer-schema guidance; files unchanged
doctor --fix --non-interactive 1 No repair tail; files unchanged
gateway run --bind loopback --auth none 78 No secondary registry-repair advice; files unchanged
update status --json 0 Partial status with compatible-build/backup guidance; no WAL/SHM creation
database preflight <copied-file> --json 1 incompatible, foundVersion: 21, actionable reason; files unchanged

Local one-worker wall times: Doctor 212.22 / 112.31 / 94.83 seconds; preflight 9.31 / 6.10 / 6.05 seconds; status artifacts 46.11 / 36.52 / 22.91 seconds. The status artifact suite spent 10.39 / 17.96 / 13.86 seconds in tests; its real SQLite readers and RPC identity boundary are necessary to expose the sidecar mutation that a mocked probe misses. Doctor's existing maintenance/service-custody matrix accounts for its longer runtime. The broad importer/guard run took 1,221.82 seconds including shared runtime preparation; the final status importer/guard run took 183.60 seconds. Hosted CI seconds are pending at the authoring handoff.

Delta: production +169/-125 (net +44, including the preflight relocation); tests/support +198/-5; tooling +2/-0; docs +6/-0.

Pre-existing slow cases were recorded without increasing timeouts or changing assertions: native wrapper provisioning spent 343.76 seconds in tests (including 98.80 seconds for its cold/warm/sparse checkout sequence), and the original-capture Doctor flow took 46.55 seconds while exercising real custody, backup capture, and repeated repair admission. These inherited costs are unchanged; no timeouts, retries, or assertions were altered.

Keep compatible-build or matching-backup guidance through Doctor and Gateway admission, and report offline schema incompatibility before integrity checks. Route update status through artifact-preserving state reads so newer databases keep their bytes, mtimes, and SQLite sidecars unchanged. No schema or migration changes.

Regression evidence covers all four reported paths. Independent P1 review was attempted but returned HTTP 401; campaign lead review remains required.
Prepare the channel-status RPC identity through the existing artifact-preserving reader. The default asynchronous existing-only lookup opens the shared actor and can create WAL/SHM files before refusing a newer schema.

Exercise the real Gateway probe on the host-broker test lane, with byte and nanosecond-mtime assertions. The negative control reproduces sidecar creation without this fix. P1 autoreview again returned HTTP 401; campaign lead review is required.
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes scripts Repository scripts commands Command implementations size: M labels Oct 8, 2026
@steipete
steipete marked this pull request as ready for review October 8, 2026 04:14
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. 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. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed October 8, 2026, 12:46 AM ET / 04:46 UTC (Revision 2).

ClawSweeper review

What this changes

The branch prioritizes compatible-build or matching-backup guidance for newer databases and preserves SQLite files during update-status inspection.

Example: Run update status --json against shared-state schema 21 with a build supporting schema 20.

  • Before: Status inspection can create WAL/SHM files beside the unsupported database.
  • After: Status returns partial information with compatible-build or matching-backup guidance while preserving database files and modification times.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong CLI preservation proof supports the repair, but an unchanged status-probe regression still blocks merge.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The reported final-build Doctor, Gateway startup, update-status, and explicit-file CLI runs exercise the changed production paths against isolated released-state copies with schema 21 and record preserved hashes, mtimes, and sidecar membership. The unresolved shared-secret compatibility finding is separate. Inspection confirms no stored-format or migration change.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes
User problem: Operators inspecting state from a newer release receive contradictory repair advice, and update status can change SQLite sidecar files.
Reason: Consistent recovery guidance and non-mutating inspection protect an established state-management contract. Prior merged area work supports this direction without adding configuration or public API surface.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Needs changes before merge - 2 items remain

This PR has useful real CLI proof, but the previously reported P2 status-probe regression remains unresolved on the current head.

Priority: P2
Reviewed head: 4f6e36490e8fb45acac9fb0c897bceaf8644c04f

Before merge

  • Preserve deferred identity selection for shared-secret probes (P2) - With a loopback Gateway authenticated by its configured token or password, resolveGatewayCallDeviceAuth normally skips identity storage. This unconditional load runs before that decision: an invalid persisted identity or unreadable local state throws, and the surrounding catch returns [], silently removing channel warnings even though the Gateway could authenticate the probe. Preserve the authentication owner's omission decision and apply artifact-preserving reads only when identity is required. This previously reported finding remains unchanged on the current head.
  • Complete next step (P2) - Preserve deferred identity selection for status probes and verify token/password channel warnings with invalid local identity state.

Findings

  • [P2] Preserve deferred identity selection for shared-secret probes — src/cli/update-cli/status.ts:92-93

Tests

  • Missing end-to-end proof: The remaining compatibility case is a real loopback token/password Gateway returning channel issues while local identity state is invalid; prove warnings remain visible and newer-schema inspection still preserves SQLite artifacts. This read-only review did not execute a base/head regression.
Agent review details

How this fits together

OpenClaw stores shared runtime state in SQLite databases. Doctor, Gateway startup, update status, and offline preflight inspect these databases to report compatibility and recovery guidance.

flowchart TD
  A[Doctor, startup, or status command] --> B[Shared SQLite state]
  B --> C[Artifact-preserving inspection]
  C --> D{Schema supported?}
  D -->|No| E[Compatible build or matching backup guidance]
  D -->|Yes| F[Normal integrity and status checks]
Loading

Technical review

Best possible solution:

Keep identity selection with the Gateway authentication owner and use artifact-preserving reads only when that owner requires identity.

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

Yes, source establishes the remaining regression: a loopback token/password probe with an invalid persisted identity throws before RPC and returns no channel issues. No reviewer-side execution was performed.

Is this the best way to solve the issue?

No, the eager identity override bypasses an existing authentication decision. The narrower solution preserves deferred selection while changing the required identity read to preserve artifacts.

Full review comments:

  • [P2] Preserve deferred identity selection for shared-secret probes — src/cli/update-cli/status.ts:92-93
    With a loopback Gateway authenticated by its configured token or password, resolveGatewayCallDeviceAuth normally skips identity storage. This unconditional load runs before that decision: an invalid persisted identity or unreadable local state throws, and the surrounding catch returns [], silently removing channel warnings even though the Gateway could authenticate the probe. Preserve the authentication owner's omission decision and apply artifact-preserving reads only when identity is required. This previously reported finding remains unchanged on the current head.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1eb5970ff972.

Provenance checked

Testing

Proof path: shipped entry point. Added test files: 3.

Security

None.

Evidence

Acceptance criteria:

  • [P1] pnpm test src/cli/update-cli/status.test.ts src/cli/update-cli/status.readonly.test.ts --maxWorkers=1.
  • [P1] pnpm test src/gateway/call.test.ts src/gateway/call-device-auth.worker.test.ts --maxWorkers=1.
  • [P1] Verify a real loopback token/password Gateway preserves channel warnings with invalid local identity state.
  • [P1] Verify newer-schema update-status inspection preserves database bytes, nanosecond mtimes, and sidecar membership.
  • [P1] Run the repository changed-file gate and record focused test wall time and CI cost.

What I checked:

  • Unresolved prior finding: The introduced status probe calls loadDeviceIdentityIfPresent before callGateway. Its catch returns an empty issue list if identity loading throws, preventing an otherwise valid shared-secret probe. (src/cli/update-cli/status.ts:93, 4f6e36490e8f)
  • Existing authentication contract: The Gateway authentication owner omits device identity for loopback CLI calls authenticated with the configured token or password and loads identity only when that omission does not apply. (src/gateway/call-device-auth.ts:173, 4f6e36490e8f)
  • Concrete throwing identity path: Persisted identity validation rejects invalid key material; the read-only identity loader propagates that error. This establishes the failure trigger without executing contributor code. (src/infra/device-identity-store.ts:321, 4f6e36490e8f)
  • Re-review continuity: status.ts has the identical blob 57430a4f0ff7ea73701d31a3eacb14f8450ea363 at the earlier reviewed head and current head. The prior finding and rank-up request therefore remain applicable. (src/cli/update-cli/status.ts:93, 692b7ddffcea)
  • Real CLI preservation proof: The complete supplied PR body, sourceRevision 8c9c15a15b3d90c947961f3f742138c9412822ed07073420d3ca8ad66f89ca5d, reports five final-build CLI runs against isolated copies of released [email protected] state with schema raised from 19 to 21. Doctor JSON exited 2, Doctor repair 1, Gateway startup 78, update status 0, and explicit-file preflight 1; every SQLite-family hash, nanosecond mtime, and file-set membership was preserved. (4f6e36490e8f)
  • No stored-format migration: Explicit-file preflight retains immutable read-only opening and the existing result schema, while checking unsupported versions before integrity. The final helper substitution preserves busy timeout, query_only, and trusted_schema settings; no stored schema or migration changes are introduced. (src/state/openclaw-database-preflight-state-path.ts:75, 4f6e36490e8f)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

Source +45, Tests +194, Docs +6, Other +1. Total +246 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 4 170 125 +45
Tests 5 199 5 +194
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 11 376 130 +246

Stored data model

Persistent data-model change detected: database schema: src/state/openclaw-database-preflight-state-path.ts, migration/backfill/repair: src/commands/doctor-maintenance.ts, unknown-data-model-change: src/commands/doctor-maintenance.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded state-diagnostics repair with a status-warning regression, without evidence of an urgent runtime outage.
  • merge-risk: 🚨 auth-provider: Eager identity loading makes valid loopback token/password probes depend on local identity storage and can suppress channel diagnostics.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rank-up moves

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

  • Restore deferred identity selection and prove loopback token/password probes retain channel warnings with invalid identity state while newer-schema inspection preserves SQLite artifacts.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-08T04:21:28.231Z sha 692b7dd :: blocked before merge. :: [P2] Preserve deferred identity selection for shared-secret probes

Replace the copied preflight PRAGMA batch with the existing busy-timeout and read-only policy helpers. Preserve connection settings and version-first refusal without expanding the raw SQLite allowlist.
@steipete
steipete merged commit b7969ee into main Oct 8, 2026
142 checks passed
@steipete
steipete deleted the upd/upd-newer-schema-one-answer branch October 8, 2026 04:48
steipete added a commit that referenced this pull request Oct 8, 2026
…ry at the CLI boundary (#167035)

#166963 made the target-release schema preflight return before agent-store discovery; #161057 (cfee851) restored the production path concurrently. This adds a CLI-boundary regression so a downgrade target that cannot read the agent databases stays refused, and replaces a polling wait in the agent-database startup test with the inspection promise.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
…elease and keep status reads read-only (openclaw#166963)

Follow-up to openclaw#166906: Doctor --fix, Gateway startup, offline database preflight and update status now give one install-compatible-build / restore-backup answer for a database written by a newer release, and update status no longer creates SQLite sidecars.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
…ry at the CLI boundary (openclaw#167035)

openclaw#166963 made the target-release schema preflight return before agent-store discovery; openclaw#161057 (1991553) restored the production path concurrently. This adds a CLI-boundary regression so a downgrade target that cannot read the agent databases stays refused, and replaces a polling wait in the agent-database startup test with the inspection promise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L 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.

1 participant