Skip to content

fix(update): refuse automatic restore after unattributed Doctor-time database writes - #160167

Merged
steipete merged 2 commits into
mainfrom
fix/r97-forward-15
Oct 1, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/r97-forward-15

Conversation

@steipete

@steipete steipete commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Decision (Peter, 2026-09-30): ship the conservative fix. "Updates should always work": never silently adopt a foreign SQLite write as Doctor-attributed rollback state. Consequence, stated explicitly: any database fingerprint change during Doctor maintenance makes the receipt ineligible for automatic database restoration, including Doctor's own schema migrations and the NOCOW physical rewrite (#160877). Updates and Doctor repairs still run; if a later failure needs database restoration, recovery is manual. Transaction-level attribution (the abandoned c3c20e0 approach) remains the follow-up if automatic DB rollback after migrations is needed again.

Rebase notes: resolved the settle() conflict by keeping main's fromGenerations while comparing against the admit-time baseline; aligned two newer receipt tests (NOCOW rewrite, legacy-root relocation schema upgrade) to the conservative policy. Focused suites pass (settlement 32, database-writes 2, update-doctor-result + rollback 35, worker 10, migration-refusal 21); Codex autoreview on the rebased branch: scoped-clean (0.93).

What Problem This Solves

Doctor's maintenance lock does not exclude independent SQLite connections. A foreign commit or creation during that interval was recorded as Doctor-attributed state, allowing a failed update to accept that state for automatic database restoration and displace the foreign data from its live path.

Summary

Keep the original database fingerprint baseline through Doctor settlement. Any changed fingerprint, including a file created at a formerly missing path, now marks the existing receipt as ineligible for automatic restoration. The existing updater consumer preserves current databases, retains snapshots, and reports state-migrated-no-rollback with candidate Doctor recovery instructions.

This is deliberately conservative: legitimate Doctor writes also disable automatic database restoration because the current owner cannot attribute individual transactions. Updates and Doctor repairs still run; manual recovery is required if a subsequent failure needs restoration. Unchanged fingerprints retain eligibility. No schema, dependency, receipt-format, or transaction-owner change is introduced. Production diff: 6 additions, 2 deletions in one existing owner.

Adapted from abandoned release-branch commit c3c20e0, without importing its transaction receipt infrastructure. The commit preserves the original human coauthor credit. Both recovery documentation paragraphs describe the conservative behavior.

Evidence

  • Red before production changes: node scripts/run-vitest.mjs run --maxWorkers=2 src/commands/doctor-maintenance.database-writes.test.ts — 2 failures on baseline 2d39f2f738a89c27e0852943486af5c3971c4098. Both during and missing-foreign failed expect(receipt?.unchanged).toBe(false) with expected true to be false. The affected capture/maintenance/consumer code matched origin/main at inspection.
  • Green after: node scripts/run-vitest.mjs run --maxWorkers=2 src/commands/doctor-maintenance.database-writes.test.ts src/commands/doctor-maintenance.settlement.test.ts src/infra/update-doctor-result.test.ts src/cli/update-cli/update-command-database-rollback.test.ts — 65 passed across 4 files (2 + 30 + 23 + 10), wrapper wall 524.70 s. The new cases use real isolated Doctor maintenance and a separate raw SQLite connection, consume the actual receipt, call the rollback refusal entry point, and verify the foreign row remains live with actionable guidance. Existing settlement coverage retains the unchanged positive case and unavailable-proof/cleanup checks.
  • Cost measurement: /usr/bin/time -p pnpm test src/commands/doctor-maintenance.database-writes.test.ts src/commands/doctor-maintenance.settlement.test.ts --maxWorkers=1 — 32 passed, wall 182.05 s. File durations were 95.42 s and 57.41 s, including transform/setup under host load; the two new real-maintenance cases spent 20.73 s in tests. Real maintenance admission and isolated fingerprint workers are needed to demonstrate that Gateway ownership does not reject the raw writer. CI timing is not yet available.
  • pnpm check:changed: production typecheck and preceding guards passed locally before the host-load time budget stopped it.
  • Independent review: autoreview --mode branch --base origin/main --engine codex --thinking high --codex-speed fast --max-priority P1 --dataset src/cli/update-cli/update-command-database-receipts.ts --prompt <task context> — scoped-clean, no accepted/actionable P0/P1 findings on commit 508b3d4400c4a.
  • git diff --check — passed.

The candidate uses the existing unchanged: false receipt contract already consumed by drivers supporting database write evidence. This does not retrofit older drivers without that contract. No full installed-package update, published-driver matrix, live Gateway, Windows, or Bun run was performed; proof is scoped to the current maintenance, receipt, and rollback boundaries.

@clawsweeper

clawsweeper Bot commented Sep 28, 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 commands Command implementations size: S labels Sep 28, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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. 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 Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 28, 2026, 1:43 AM ET / 05:43 UTC.

ClawSweeper review

What this changes

The branch makes Doctor's database write receipt refuse automatic restoration whenever a database fingerprint changes during maintenance, and adds recovery documentation and tests.

Regression provenance

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

Merge readiness

⛔ Blocked before merge - 5 items remain

Keep this draft open. Current main still has the foreign-write attribution gap, while the proposed safeguard needs an update-owner decision because it also removes automatic database recovery after Doctor's own migrations.

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

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The narrow patch has meaningful boundary evidence, but its unresolved loss of normal migration recovery prevents a merge-ready rating.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR reports an after-fix run of the real Doctor maintenance owner with an independent SQLite writer; the added test passes the resulting receipt through production rollback refusal and observes that the foreign row remains live. This supports the foreign-write safety claim, while a published-updater × candidate upgrade run is still missing as a separate repository gate. No stored-data format changes.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR reports an after-fix run of the real Doctor maintenance owner with an independent SQLite writer; the added test passes the resulting receipt through production rollback refusal and observes that the foreign row remains live. This supports the foreign-write safety claim, while a published-updater × candidate upgrade run is still missing as a separate repository gate. No stored-data format changes.
Evidence reviewed 9 items Current-main gap: Doctor settlement on the fetched main revision publishes the final generations without comparing them to the pre-Doctor baseline, so a write during maintenance can be treated as Doctor-attributed.
Introduced safeguard: The PR compares settled generations with the original captured baseline and marks every changed fingerprint ineligible for automatic restoration.
Recovery consequence: A false receipt sets restoreRefusal; the failed-update path then returns state-migrated-no-rollback before calling the database restore owner.
Findings 1 actionable finding [P1] Preserve rollback after Doctor-owned database migrations
Security None None.

How this fits together

The updater snapshots SQLite databases before a candidate version runs Doctor. Doctor returns write evidence to the updater, which uses it to decide whether a failed update may restore those snapshots or must preserve the current databases.

flowchart LR
A[Installed updater] --> B[Database snapshot]
B --> C[Candidate Doctor]
C --> D[Write fingerprint receipt]
D --> E{Restore eligible?}
E -->|Yes| F[Verified database restore]
E -->|No| G[Preserve current databases]
Loading

Decision needed

Question Recommendation
Should this update fix retain automatic database restoration after Doctor-owned migrations, or may a failed update require manual recovery whenever Doctor changes a database? Attribute Doctor writes: Require transaction-attributed receipts so foreign writes are rejected while Doctor-owned migration rollback remains available.

Why: The draft identifies a real data-integrity defect but deliberately trades away an existing update recovery path; source review cannot authorize that operator-impact choice.

Before merge

  • Preserve rollback after Doctor-owned database migrations (P1) - This comparison marks Doctor's own migration writes as unknown. The updater then sets restoreRefusal and cannot restore verified pre-migration snapshots if a later pre-start step fails, leaving an existing recovery path unavailable. Keep owner-attributed writes eligible or obtain explicit approval for that breaking recovery behavior.
  • Resolve merge risk (P1) - Doctor's legitimate SQLite migrations also make the receipt refuse automatic restoration. If a later pre-start update step fails, an existing user's Gateway can remain stopped with candidate databases and require manual recovery; the update owner has not accepted that tradeoff.
  • Resolve merge risk (P1) - The PR reports no published-updater × candidate run, so first-upgrade behavior from a shipped installation remains unverified under the repository's update proof contract.
  • Complete next step (P2) - Resolve the Doctor-owned migration rollback finding with the update owner, then provide a published-updater × candidate recovery run before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P1] Preserve rollback after Doctor-owned database migrations — src/infra/update-doctor-result.ts:221-223
Agent review details

Security

None.

PR surface

Source +4, Tests +107, Docs +7. Total +118 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 2 +4
Tests 2 116 9 +107
Docs 2 9 2 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 131 13 +118

Review metrics

Metric Value Why it matters
New boundary-test cost 95.42 s file duration; 20.73 s for 2 new scenarios The PR body reports a costly real-maintenance test and explains why a cheaper mocked layer would miss the foreign writer.

Merge-risk options

Maintainer options:

  1. Restore owned-write eligibility (recommended)
    Add trustworthy Doctor transaction attribution and prove that a normal migration can still restore its snapshot after a later pre-start failure.
  2. Own manual recovery
    Explicitly accept the lost automatic restore path and demonstrate the operator outcome with a published updater driving the candidate.
  3. Hold this approach
    Keep the draft open while the release-branch transaction-receipt design is assessed for a focused main-branch implementation.

Technical review

Best possible solution:

Attribute Doctor-owned SQLite transactions in the receipt owner, reject foreign writes, retain verified automatic restoration for normal pre-start migrations, and offer guided in-product recovery when restoration truly cannot be safe.

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

Yes. Current-main source shows that Doctor settlement adopts the final fingerprint without attributing intervening SQLite writes, and the PR supplies a production-maintenance test with a separate writer; this reviewer did not rerun it.

Is this the best way to solve the issue?

No, pending the update-owner choice. The guard blocks the foreign-write case, but it also removes automatic recovery for Doctor-owned migrations; transaction attribution is the narrower recovery-preserving direction.

Full review comments:

  • [P1] Preserve rollback after Doctor-owned database migrations — src/infra/update-doctor-result.ts:221-223
    This comparison marks Doctor's own migration writes as unknown. The updater then sets restoreRefusal and cannot restore verified pre-migration snapshots if a later pre-start step fails, leaving an existing recovery path unavailable. Keep owner-attributed writes eligible or obtain explicit approval for that breaking recovery behavior.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1ca6a5d0a801.

Labels

Label changes:

  • add P1: The PR addresses a current-main update data-integrity gap but could leave failed upgrades without automatic database recovery.
  • add merge-risk: 🚨 compatibility: The new default refuses snapshot restoration after Doctor's own migrations, changing an existing update recovery path.
  • add merge-risk: 🚨 availability: A later update failure after a legitimate migration can leave the Gateway stopped until an operator performs manual recovery.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR reports an after-fix run of the real Doctor maintenance owner with an independent SQLite writer; the added test passes the resulting receipt through production rollback refusal and observes that the foreign row remains live. This supports the foreign-write safety claim, while a published-updater × candidate upgrade run is still missing as a separate repository gate. No stored-data format changes.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR reports an after-fix run of the real Doctor maintenance owner with an independent SQLite writer; the added test passes the resulting receipt through production rollback refusal and observes that the foreign row remains live. This supports the foreign-write safety claim, while a published-updater × candidate upgrade run is still missing as a separate repository gate. No stored-data format changes.

Label justifications:

  • P1: The PR addresses a current-main update data-integrity gap but could leave failed upgrades without automatic database recovery.
  • merge-risk: 🚨 compatibility: The new default refuses snapshot restoration after Doctor's own migrations, changing an existing update recovery path.
  • merge-risk: 🚨 availability: A later update failure after a legitimate migration can leave the Gateway stopped until an operator performs manual recovery.
  • 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 reports an after-fix run of the real Doctor maintenance owner with an independent SQLite writer; the added test passes the resulting receipt through production rollback refusal and observes that the foreign row remains live. This supports the foreign-write safety claim, while a published-updater × candidate upgrade run is still missing as a separate repository gate. No stored-data format changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR reports an after-fix run of the real Doctor maintenance owner with an independent SQLite writer; the added test passes the resulting receipt through production rollback refusal and observes that the foreign row remains live. This supports the foreign-write safety claim, while a published-updater × candidate upgrade run is still missing as a separate repository gate. No stored-data format changes.

Evidence

What I checked:

Likely related people:

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

Rank-up moves

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

  • Resolve the Doctor-owned migration recovery finding with the update owner.
  • Show the chosen behavior in a published-updater × candidate run.

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.

steipete and others added 2 commits September 30, 2026 18:20
Keep the captured fingerprint baseline through Doctor settlement. Maintenance ownership does not exclude independent SQLite writers, so any observed change, including a new database, must refuse automatic restoration through the existing receipt contract. Preserve current databases and the existing actionable recovery guidance without adding schema or transaction receipt infrastructure.

Forward-port the conservative safety correction from c3c20e0 onto the current capture owner.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vyctorbrzezowski <[email protected]>
Co-authored-by: steipete <[email protected]>
Co-authored-by: jalehman <[email protected]>
… restore

Rebasing onto main surfaced two receipts that relied on interval-wide
attribution: the NOCOW physical replacement (#160877) and Doctor's own
schema upgrade during legacy-root relocation. Under the conservative
policy neither is attributable, so both receipts are ineligible for
automatic restoration.
@steipete
steipete force-pushed the fix/r97-forward-15 branch from 508b3d4 to 07bb6eb Compare October 1, 2026 01:34
@steipete
steipete marked this pull request as ready for review October 1, 2026 01:34
@steipete
steipete merged commit 65a3cce into main Oct 1, 2026
65 of 69 checks passed
@steipete
steipete deleted the fix/r97-forward-15 branch October 1, 2026 01:34
steipete added a commit that referenced this pull request Oct 1, 2026
Remove the assertion introduced by #160167 for a property that does not
exist on UpdateDatabaseBackup. Keep the restore refusal, failed automatic
restore, recovery guidance, and foreign-write preservation assertions.

The commands-doctor test-types shard reproduced:
src/commands/doctor-maintenance.database-writes.test.ts(71,25): error TS2339: Property 'postMigrationGenerations' does not exist on type 'UpdateDatabaseBackup'.

Proof:
- node scripts/run-tsgo-core-test-shards.mjs --ci-graphs-json '["core-test-commands-doctor"]'
- node scripts/run-vitest.mjs src/commands/doctor-maintenance.database-writes.test.ts
- node_modules/.bin/oxfmt --check src/commands/doctor-maintenance.database-writes.test.ts
- git diff --check
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 1, 2026
…database writes (openclaw#160167)

* fix(update): reject unattributed database writes during Doctor

Keep the captured fingerprint baseline through Doctor settlement. Maintenance ownership does not exclude independent SQLite writers, so any observed change, including a new database, must refuse automatic restoration through the existing receipt contract. Preserve current databases and the existing actionable recovery guidance without adding schema or transaction receipt infrastructure.

Forward-port the conservative safety correction from c3c20e0 onto the current capture owner.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vyctorbrzezowski <[email protected]>
Co-authored-by: steipete <[email protected]>
Co-authored-by: jalehman <[email protected]>

* test(update): expect Doctor-time writes to disable automatic database restore

Rebasing onto main surfaced two receipts that relied on interval-wide
attribution: the NOCOW physical replacement (openclaw#160877) and Doctor's own
schema upgrade during legacy-root relocation. Under the conservative
policy neither is attributable, so both receipts are ineligible for
automatic restoration.

---------

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vyctorbrzezowski <[email protected]>
Co-authored-by: steipete <[email protected]>
Co-authored-by: jalehman <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 1, 2026
Remove the assertion introduced by openclaw#160167 for a property that does not
exist on UpdateDatabaseBackup. Keep the restore refusal, failed automatic
restore, recovery guidance, and foreign-write preservation assertions.

The commands-doctor test-types shard reproduced:
src/commands/doctor-maintenance.database-writes.test.ts(71,25): error TS2339: Property 'postMigrationGenerations' does not exist on type 'UpdateDatabaseBackup'.

Proof:
- node scripts/run-tsgo-core-test-shards.mjs --ci-graphs-json '["core-test-commands-doctor"]'
- node scripts/run-vitest.mjs src/commands/doctor-maintenance.database-writes.test.ts
- node_modules/.bin/oxfmt --check src/commands/doctor-maintenance.database-writes.test.ts
- git diff --check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation 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. 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: S 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