Repository navigation
fix(update): refuse automatic restore after unattributed Doctor-time database writes - #160167
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 28, 2026, 1:43 AM ET / 05:43 UTC. ClawSweeper reviewWhat this changesThe branch makes Doctor's database write receipt refuse automatic restoration whenever a database fingerprint changes during maintenance, and adds recovery documentation and tests. Regression provenancePossible 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 Review scores
Verification
How this fits togetherThe 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]
Decision needed
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
Findings
Agent review detailsSecurityNone. PR surfaceSource +4, Tests +107, Docs +7. Total +118 across 5 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest 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:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 1ca6a5d0a801. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
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.
508b3d4 to
07bb6eb
Compare
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
…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]>
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
Rebase notes: resolved the
settle()conflict by keeping main'sfromGenerationswhile 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-rollbackwith 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
node scripts/run-vitest.mjs run --maxWorkers=2 src/commands/doctor-maintenance.database-writes.test.ts— 2 failures on baseline2d39f2f738a89c27e0852943486af5c3971c4098. Bothduringandmissing-foreignfailedexpect(receipt?.unchanged).toBe(false)withexpected true to be false. The affected capture/maintenance/consumer code matchedorigin/mainat inspection.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./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.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 commit508b3d4400c4a.git diff --check— passed.The candidate uses the existing
unchanged: falsereceipt 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.