Skip to content

fix: continue updates when initial SQLite capture is stale - #200328

Merged
RomneyDa merged 6 commits into
mainfrom
openclaw/fresh-shrimp-2
Nov 17, 2026
Merged

RomneyDa merged 6 commits into
mainfrom
openclaw/fresh-shrimp-2

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Related: #200260

What Problem This Solves

Fixes updates aborting with SQLite migration source changed after update capture: credentials.sqlite when normal credential activity changes a database between the updater's snapshot and Doctor's initial admission.

User Impact

Updates can migrate the current database instead of failing solely because the original capture is stale. Automatic database restoration remains unavailable for that update, so a later failure cannot overwrite newer data with the stale backup. Existing integrity, maintenance-ownership, and post-admission writer checks remain in place.

Why This Change Was Made

Separate initial migration admission from rollback eligibility: adopt the observed generations at first admission while preserving the sticky unchanged=false receipt. This generalizes the existing WAL-index workaround and deletes its special-case helper. PostgreSQL migration wrappers and post-admission checks are unchanged.

Evidence

  • Reproduced the stale-credential failure before the fix at the actual SQLite migration guard.
  • Earlier revision: four focused suites passed 123 tests, with 3 PostgreSQL cases skipped (client-credential-update, update-doctor-migration-attribution, update-doctor-result, and update-database-generations).
  • Current repair: 74 tests passed across the complete migration-attribution and Windows-lifecycle suites on pinned Bun. The final fixture revision separately passed all 4 legacy-inventory cases.
  • Integrated main through d6493b6011bd to include fix: resource broker startup fails when parent and child disagree on the socket directory #200453's resource-broker startup fix. Removed the retired session-identity allowance. The legacy same-content fixture now retains commit evidence after close without relying on timestamp resolution.
  • Preserved fix(update): preserve successful startup writes for the next Doctor #200260's successful-boot write attribution. Real SQLite capture → Doctor credential migration → attempted public rollback verifies the newer synthetic token survives, the credential source is retired correctly, and stale restoration is refused.
  • Existing post-admission foreign-writer checks remain passing; legacy capture variants migrate while retaining rollback refusal.
  • Current repair: infra and services TypeScript checks, session-identity ratchet, targeted type-aware lint, formatting, and staged/unstaged git diff --check passed.
  • Self-review and simplification completed. Remote ClawSweeper is the only requested independent review; its earlier successful-boot finding was addressed. No clean review of the current head is claimed.

Validation gaps: no full installed-version npm upgrade with a real Gateway/model was run; local PostgreSQL tests requiring a service were skipped. This is a forward-admission change, not removal of all update integrity checks. Fresh remote CI remains the broad proof for the current head.

RomneyDa and others added 2 commits November 17, 2026 00:31
Keep stale capture detection as a permanent rollback refusal instead of blocking initial Doctor admission. Preserve post-admission checks and remove the WAL-only workaround.

Co-authored-by: RomneyDa <[email protected]>
OpenClaw-Publication: a1906828-fd49-4cb8-a96d-00888ad71d06
@clawsweeper

clawsweeper Bot commented Nov 17, 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 size: M labels Nov 17, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 17, 2026
Merge current main, retaining successful-boot write attribution from #200260. Resolve the shared test imports and assert that pre-admission changes still migrate while disabling stale rollback.

Co-authored-by: RomneyDa <[email protected]>
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 17, 2026
OpenClaw-Publication: 0151e769-6f48-4ac9-a9dc-bd950a327d43
@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR lets Doctor migrate current database state when the updater’s initial capture is stale, while disabling automatic restoration for that update.

Example: After capture, a credential token changes from synthetic-original-token to synthetic-foreign-token.

  • Before: Doctor aborts migration with “SQLite migration source changed after update capture.”
  • After: Doctor migrates the newer token, warns that automatic restoration is unavailable, and refuses restoration of the stale backup.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Focused implementation with no discrete introduced defect found; required installed-upgrade behavior is supported only by test-level evidence.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An update can abort when normal credential activity makes its initial database capture stale before Doctor begins migration.
Reason: The maintainer-authored direction addresses a concrete update failure with less production machinery and explicitly preserves protection against stale restoration.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: current main still rejects ordinary credential changes before Doctor admission, and this PR provides a focused repair while preserving stale-backup restoration refusal.

Priority: P2
Reviewed head: 723889a93b3baefdf524419441d931df2a2c2a94

Before merge

  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted terminal output or logs for a v2026.11.4-to-candidate update with credentials changed between capture and admission, showing successful Gateway startup, preserved settings and newer credentials, and rollback remaining disabled; redact API keys, IPs, phone numbers, and non-public endpoints.
Agent review details

How this fits together

The updater supplies captured database generations to candidate Doctor; Doctor admits migrations under maintenance custody and returns write receipts that determine automatic rollback eligibility.

flowchart TD
  A[Updater captures databases] --> B[Doctor observes current generations]
  B --> C[Initial migration admission]
  C --> D[Migrate under maintenance custody]
  D --> E[Publish write receipt]
  E --> F[Updater checks rollback eligibility]
Loading

Technical review

Best possible solution:

Keep initial admission in the existing Doctor capture owner, adopt current state once, and preserve permanent stale-restoration refusal and subsequent migration checks.

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

Current-main admission retains the old generation after an ordinary credential commit, and the migration owner then rejects the mismatch; the revised real-SQLite regression exercises this path, but no reproduction was executed during this read-only review.

Is this the best way to solve the issue?

The implementation is the smallest complete repair at the existing admission owner: it separates migration eligibility from restoration eligibility, removes the specialized WAL helper, and retains maintenance custody and later-write checks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4c61c20fb1a7.

Provenance checked

  • Initial Doctor admission and removed WAL-specific helper changes intended behavior with a stated reason (8697342: Allow forward migration after a rebuilt WAL index without authorizing restoration over changed state; other pre-admission changes deliberately remained rejected.)
  • Successful-startup regression changes intended behavior with a stated reason (5597108: Attribute successful startup credential writes so the next Doctor can proceed, retaining independent detection of earlier changes.)
  • Legacy physical-generation inventory tests keeps the original intent (ad1b598: Support published extended-stable capture formats while refusing restoration after intervening writes or file replacement.)
  • Credential migration and rollback test keeps the original intent (8f62210: Move local client credentials through the existing custody and receipt owners without changing credential authority.)
  • Update documentation changes intended behavior with a stated reason (237fdc6: Document candidate-side admission tolerance for non-writing SQLite probes while preserving restoration safety.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 8697342 adds src/infra/update-doctor-result.ts:332 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 869734209368; files: src/infra/update-doctor-result.ts)
  • Jason (Json): Raw commit 27aa074 adds src/infra/update-doctor-result.ts:278 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 27aa0742fc28; files: src/infra/update-doctor-result.ts)

PR surface

Source -29, Tests +62, Docs +3, Other -1. Total +35 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 7 36 -29
Tests 3 140 78 +62
Docs 1 9 6 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 7 156 121 +35

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: Repairs an update failure caused by credential activity during a bounded capture-to-Doctor interval.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.

Rank-up moves

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

  • Supply the installed-upgrade evidence described in the proof assessment.

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 execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-17T00:46:46.644Z sha 92e016d :: blocked before merge. :: [P2] Update the successful-boot regression for the new admission contract

Reviewed November 17, 2026, 3:52 AM ET / 08:52 UTC (Revision 2).

@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 17, 2026
RomneyDa and others added 2 commits November 17, 2026 08:47
Merge main for the resource broker startup fix. Keep same-content commit evidence after the legacy fixture writer closes and remove the retired session-identity allowance.

Co-authored-by: RomneyDa <[email protected]>
OpenClaw-Publication: 699b1a51-1724-47c1-9f4f-a9328ee3ea06
@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 17, 2026
@RomneyDa
RomneyDa merged commit 74020ea into main Nov 17, 2026
153 of 154 checks passed
@RomneyDa
RomneyDa deleted the openclaw/fresh-shrimp-2 branch November 17, 2026 09:16
RomneyDa added a commit that referenced this pull request Nov 17, 2026
Backport-of: 74020ea

Keep the initial rollback refusal permanent while admitting current state.
Preserve post-admission generation checks and remove the WAL-only exception.
Adapt credential proof to the stable inline fixture and private directory modes.

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
…200328)

* fix: continue updates when initial SQLite capture is stale

Keep stale capture detection as a permanent rollback refusal instead of blocking initial Doctor admission. Preserve post-admission checks and remove the WAL-only workaround.

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

* fix: continue updates when initial SQLite capture is stale

OpenClaw-Publication: a1906828-fd49-4cb8-a96d-00888ad71d06

* Publish openclaw/fresh-shrimp-2

OpenClaw-Publication: 0151e769-6f48-4ac9-a9dc-bd950a327d43

* Publish openclaw/fresh-shrimp-2

OpenClaw-Publication: 699b1a51-1724-47c1-9f4f-a9328ee3ea06

---------

Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 18, 2026
…Claw process is writing (#200742)

* fix(state): keep lease release waiting through ordinary SQLite writer contention

A state lease's release gave up after 2 s of SQLite lock contention and,
for worker-cleanup leases, threw the raw lock error. Doctor maintenance
steps that had already committed their work (media persistence, plugin
session repair, transcript directives) then failed with a bare
"database is locked", leaving updates post-update-failed and sometimes
the Gateway stopped. The unreleased lease also blocked the next acquirer
until its stored expiry.

Lock contention during release now waits the same 5 s busy bound every
shared-state writer uses, and a release that still loses to a writer is
retried in the background like offline-maintenance contention.

Refs #197083

* test(state): restore the renewal test close after rebase

Co-authored-by: Peter Steinberger <[email protected]>

(cherry picked from commit b1ec281)

Release adaptation: keep the maintenance-line native/worker lease owner and
existing-schema admission behavior; import only its existing busy-timeout constant.
Resolve the append-only contention-test conflict without unrelated renewal tests.
Retain the branch native best-effort fallback; exact-worker failed cleanup remains
with the existing resource owner. No schema, SDK, config, or dependency changes.

Companion audit: no later same-path commits or PR-number follow-ups for #200742
through main 74e5127. #200328 is already
implemented at cef3501, with predecessor-stop
custody retained; do not duplicate it or the separately owned #200659/#200805.
The 97-line allocation covers two distinct real-SQLite regressions: completed
work survives ordinary contention and failed release cannot strand its lease.

Proof: both new regressions fail on 0678cec; all 19 selected lease tests
pass after repair. The four #200328 owner suites pass 94 tests (3 skipped).
Formatting and git diff --check pass. Targeted lint/type wrappers refuse shared
symlinked dependencies; final isolated checks and full release validation remain
with the release owner. No live Gateway or installed state was modified.

Co-authored-by: RomneyDa <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 19, 2026
* fix: continue updates when initial SQLite capture is stale

Keep stale capture detection as a permanent rollback refusal instead of blocking initial Doctor admission. Preserve post-admission checks and remove the WAL-only workaround.

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

* fix: continue updates when initial SQLite capture is stale

OpenClaw-Publication: a1906828-fd49-4cb8-a96d-00888ad71d06

* Publish openclaw/fresh-shrimp-2

OpenClaw-Publication: 0151e769-6f48-4ac9-a9dc-bd950a327d43

* Publish openclaw/fresh-shrimp-2

OpenClaw-Publication: 699b1a51-1724-47c1-9f4f-a9328ee3ea06

---------

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 74020ea)

Release adaptation: omit session identity allowlist bookkeeping, since that later ratchet file does not exist on the release baseline. Production and regression tests unchanged. Companion #200569 follows for predecessor-stop admission.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit b5c3ee23034ad6814af021acac13587af731708e)
RomneyDa added a commit that referenced this pull request Nov 19, 2026
Release adaptation: Regenerate the shrink-only ratchet after composing #200328 with #200191 and #200314. Only the obsolete update-doctor-result allowance is removed.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit cfcd57db7ed4758d2a6013f8f66fe1a84e13d015)
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
…aw#194058)

Failed-update triage now captures the operator's environment before managed candidate admission, so a coding agent installed only on the operator's PATH is still offered when the Gateway service's PATH differs. Restores the operator-environment contract from openclaw#134490 and keeps the launch confirmation from openclaw#143139.

Proof: shipped CLI on isolated Linux (Crabbox) with a running systemd Gateway: accept launches the operator-only agent, decline starts nothing, base 18bee8e reports no agent found; published 2026.11.1 upgrades to the fix with settings intact.

Co-authored-by: TorstenW <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: steipete <[email protected]>

(cherry picked from commit 7c702c3)

Release adaptation: Capture invoking operator env before candidate admission, forward to interactive triage only; preserve latest target selectors, confirmation and lease cleanup ordering. Exact three authorized production paths plus real lifecycle regression.

Follow-up dispositions: ad4863d fix: preserve the running installation when an agent updates its Gateway (openclaw#201570); dc73ec0 fix: let updates finish when another tool briefly reads OpenClaw's databases (openclaw#202541); d07b530 fix: clarify PostgreSQL schema upgrades for Git installs (openclaw#202098); e60ea9f test(update): add a Git release upgrade-survivor scenario (openclaw#201956); 2ef6f7b fix(update): build and serve Git releases outside node_modules (openclaw#201917); dbc1aa0 fix: keep the openclaw command and Gateway working after updating a pnpm install (openclaw#201735); f5e7641 fix: Git checkout updates across a schema change no longer end as post-update-failed after the new release starts (openclaw#201600); 2183caf fix: Git checkout updates no longer fail before the new release starts on a schema change or a busy database (openclaw#201463); 47e8649 fix: explain why Doctor cannot restore a scheduled job’s account (openclaw#201550); 8f2cfd4 fix: remove updater-only restrictions from agent maintenance guidance; cb5cfb2 fix: keep a doubtful killed-update recovery on the repair path (openclaw#201361); 24cb734 fix: keep carried-over scheduled jobs running after updates (openclaw#200653); d1276e1 feat(doctor): check OpenClaw ID member roles and honor an optional roles default (openclaw#197785); 0a39956 fix: finish updates when another tool reads OpenClaw's databases during the update (openclaw#201330); ea1c9d5 fix(update): settle remounted package publications before admission (openclaw#201336); 66b5212 fix(update): isolate malformed retained-install markers (openclaw#201199); 7e79c83 fix: let the next update finish a killed source checkout update (openclaw#201009); d905d8a fix: let the next update finish a killed update after the machine restarted (openclaw#200994); fdf0c95 fix: let the next update finish a killed update that had already installed the new version (openclaw#200866); 0c19bcd chore(release): close out 2026.11.5 on main (openclaw#200577); a1940e0 fix(matrix): keep explicit recovery available during deferred migration (openclaw#200805); 18b4776 improve: explain package baseline drift during updates (openclaw#200802); 1ad4cad fix(doctor): reclaim macOS updater runtimes blocked by non-updater processes (openclaw#200732); 427c857 fix: keep one missing archived transcript from blocking every update (openclaw#200733); 802e3f7 fix(update): keep valid cold archives from blocking updates (openclaw#200659); 23fca1a fix: let the next update continue after a killed update when nothing is left to repair (openclaw#200680); 3afe212 fix: let Doctor publish unchanged plugin migrations in any order (openclaw#200658); f65e4db fix(doctor): reclaim runtimes blocked by unrelated Linux processes (openclaw#200657); dab086c fix(update): let candidate Doctor read plugin dependencies from the staged package (openclaw#200595); 3447bee fix(update): keep updates going when the predecessor writes during its stop (openclaw#200569); 0ce9c77 fix: let the next update settle a package publication that a killed update left behind (openclaw#200550); ae31ea3 fix(update): repair handoffs in the journal-pinned lease store (openclaw#200532); 74020ea fix: continue updates when initial SQLite capture is stale (openclaw#200328); 6747b1e feat(update): run Git checkout installs from releases behind the release link (openclaw#199706); e3f8a67 fix(state): keep completed retained agent stores out of startup upgrade (openclaw#200284); 3c512c5 fix(gateway): move managed update lease operations off the main thread (openclaw#200169); ea69fcb chore(release): close out 2026.11.4 on main (openclaw#199956); 618bf31 fix(state): bound startup upgrade copies and pruning to owned state (openclaw#199929); e4a3093 perf(update): replace the candidate canary with a runtime contract check (openclaw#198268); 5dbf569 fix(update): plugin failures never fail an update or Gateway health; 764761e fix(update): refuse missing host prerequisites in one line and record a cause per attempt; 4c4fef4 fix(ui): update dialog claims installation before progress is confirmed (openclaw#199254); 136e1f6 fix(update): retrying an update from a dev checkout is refused after a killed update (openclaw#198673); 3bd03da fix(update): avoid duplicate database copies while the Gateway is stopped (openclaw#198148); 68a839b fix: isolate held agent databases until explicit restoration (openclaw#198180); e333f7e chore(ci): drop retired test-lines allocation records (3/3) (openclaw#197657); fd6fa47 fix: converge Gateway updates with environment-only service overrides (openclaw#196371); 7cf5e75 fix: clarify split-install updates and blocked Doctor repairs (openclaw#196342); 6ff8c86 fix(update): retain lazy sqlite catalog generation (openclaw#197095); 930e1f7 fix: keep stable updates and recovery free of premature migrations (openclaw#196474); a15f737 fix: preserve external plugin data during update rehearsal (openclaw#196301); 92798ae fix: updates survive interrupted heartbeat runs (openclaw#195656); c1e55e2 fix(update): restore LaunchAgent registration after repair contention (openclaw#195406); 715c610 fix(doctor): repair retained ISO session end timestamps (openclaw#194685); 689cfc8 fix(update): reclaim dead closing triage repair leases (openclaw#194503); 86bc89e fix(doctor): keep standing Codex parameter advice out of retirement blockers (openclaw#193650); 691bc8d fix(backup): read the backup engine without copying the live database (openclaw#194234); 000542f fix(backup): backups and updates fail on slow storage when a header probe batch misses its deadline (openclaw#194239); 31a65d5 fix(update): skip --no-lazy-fetch on Git versions without it (openclaw#194198); e45e99d fix(update): preserve dev update sources in tag-only Git clones (openclaw#193109)

Validation: Baseline2 intended operator-agent failures/32 controls passed; candidate34/34passed (194058-green.log). Accept launches synthetic operator-only CLI with expected env, decline starts nothing. Isolated updater flow, not live systemd/upgrade qualification.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 6689fd575ada8fe40a9593784deac18ec73041cd)
(cherry picked from commit 92e7a9fa223b0dc35801f25f70be90b472d9a6b7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant