Skip to content

fix(doctor): avoid stale migration checks when archiving retained sessions - #149964

Merged
steipete merged 1 commit into
mainfrom
upd/publication-guard-transaction
Sep 16, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/publication-guard-transaction

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Doctor accepting an old pending-plugin generation or rejecting the current one while archiving retained session migration inputs.

User Impact

Deferred-plugin completion checks the current publication transaction before removing original session files. Changed obligations still preserve those inputs and produce the existing repair warning. No configuration, CLI, dependency, schema, or public API change is required.

Why This Change Was Made

assertDeferredPluginMigrationsCurrent now delegates to the existing withDeferredPluginMigrationsCurrent owner. Its synchronous transaction rejoins the admitted connection and rereads authoritative pending rows. Ordinary discovery keeps its artifact-preserving committed-snapshot reader.

The old assertion called that discovery reader from inside publication. The reader deliberately skips a transaction-held writer at openclaw-state-db-readonly.ts:214 and prepares a private snapshot at openclaw-state-db-readonly.ts:260. That snapshot cannot see the transaction's current generation. The repair changes one production line, preserving the strict generation comparison and existing publication owner.

This is a candidate-side Doctor correction over existing migration records. Backup, rollback, retained-source recovery, and the installed updater contract are unchanged.

Evidence

  • Real SQLite regression, before the fix: 2 failed. The prior generation incorrectly passed; the current in-transaction generation incorrectly threw DeferredPluginMigrationConflictError.
  • After the fix: both strict regressions pass; 13/13 deferred-plugin migration tests pass, including absent/historical state, inherited discovery snapshots, and transaction nesting.
  • Full selected run: 348 passed, 1 failed. The sole failure was the existing public-import memory fixture's unchanged 180-second timeout. The A/B below measures that failure on both versions; the full run is not claimed green.
  • node scripts/check-changed.mjs: passed, including production/test typechecking, lint, export scans, database guards, and documentation checks.
  • pnpm build: passed in 33m 9s, including CLI bootstrap, Doctor closure, SDK export, and UI size checks; zero INEFFECTIVE_DYNAMIC_IMPORT diagnostics.
  • Codex review on the committed branch (--mode branch --base origin/main, P1): scoped-clean, with no accepted/actionable P0/P1 finding. The exact local patch also passed its pre-commit P1 review.
  • LOC: production +1/-1, tests +31/-0, documentation +2/-0.
Red/green regression log excerpts

Before the fix:

× checks the prior pending generation against its publication transaction
  → expected [Function check] to throw an error
× checks the current pending generation against its publication transaction
  → expected [Function check] to not throw an error but DeferredPluginMigrationConflictError was thrown
Tests  2 failed | 11 skipped (13)

After the fix:

✓ checks the prior pending generation against its publication transaction 452ms
✓ checks the current pending generation against its publication transaction 401ms
Tests  13 passed (13)

Serial import-memory A/B

Same host, source base 5e27c4e4302ea0167b4c32ece076f84f734aec9a, exact test, alternating PRE/POST/PRE/POST. The three-file patch was saved, removed for PRE, and byte-verified after restoration for POST. Every run used one worker; no timeout or assertion was changed.

OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/commands/doctor-session-sqlite.memory.test.ts -t 'imports public transcripts and completes branch projections under a 256 MiB heap'
Run Test seconds Total command seconds Starting load (1/5/15 min) Ending load (1/5/15 min) Result
PRE-1 150.874 229.315 87.82 / 95.18 / 106.00 66.50 / 84.38 / 98.99 Pass
POST-1 172.279 263.585 75.10 / 84.38 / 98.32 75.60 / 82.51 / 93.98 Pass
PRE-2 180.082 334.251 74.51 / 82.07 / 93.69 70.84 / 79.55 / 89.04 180 s timeout
POST-2 180.075 320.025 98.09 / 85.47 / 90.53 97.59 / 87.33 / 89.19 180 s timeout

UTC starts on 2026-09-16: 09:05:56, 09:10:24, 09:15:00, and 09:21:39. Total command time includes compilation, setup, and verified cleanup. Timeout values are censored observations, not completed import timings.

Each version passed once and timed out once. The successful POST test was 14.2% slower (14.9% total-command difference); the second pair both reached the same timeout, with POST taking less total command time. Under the agreed criterion of a repeatable >25% POST slowdown, these measurements classify the original timeout as host-load sensitive. No per-event workaround, retry, or timeout increase was added.

Sibling transaction audit

  • Transcript headers/labels, incognito repair, auth alias receipts, heartbeat migration, Telegram topic repair, and workspace receipts read their admitted database directly.
  • Skill Workshop relocation's readStoredProposal reopens its cached writer; it does not use a private snapshot.
  • Canonical session repair intentionally reads a separate source agent database while writing the destination.
  • Auth migration reads shared auth state only while writing a different agent database; a shared-target migration uses its admitted database.

No additional same-database stale-snapshot defect was found in these siblings, and no follow-up repair is proposed.

Volume cell — shipped-driver swap wall (classified)

Candidate 9223ec79e054f2e1fcba1e4c190433325ff0c6d5 is the unchanged publication-guard patch rebased onto 2ef2537cd0392bc825038936f244ecfc94457810, which includes #149956. git range-diff reports 1 = 1; no code edits were made. The earlier unit/A/B/review evidence above was recorded at original head 243fb59b1855c4a528400f8dedd88c3599a10790.

This attempt does not qualify as a completed live migration/publication cell. The published updater failed during package installation/swap, before the post-core boundary. This is not the later F1 legacy-index assertion: assert-automatic-migration was never reached.

  • Published baseline: [email protected], resolved and installed from npm; registry tarball URL and integrity retained in the artifacts.
  • Candidate: freshly rebuilt and package-validated tarball from the SHA above, with a matching four-package prepublish registry.
  • Tarball SHA-256: 25c26616786853411affb2af3b5d59089896b5712d1abec21fbb18161134256a.
  • Scenario: sqlite-volume; restart mode manual; command limit 1800s; Docker run limit 7200s. Image: openclaw-l448-cell.
  • One row ran on 2026-09-16, 11:10:54–11:17:18 UTC; exit 1, total wall time 384.270s. No internal timeout or fixture assertion was changed, and the row was not rerun.
Phase / step Result Evidence
Install published baseline Passed 2026.9.4; 51.896s
Baseline config, shared-state and volume seeding Passed Schema 17; 512 plugin-state rows; baseline assertions passed
Stage candidate package Exit 0 global update; 116.703s
Candidate migration rehearsal Doctor exit 0 doctor --fix --non-interactive --no-workspace-suggestions; 24.266s
Candidate Doctor lint Exit 0 doctor --lint --json --severity-min error; 14.115s
Candidate config validation / plugin resolution / continuation check All exit 0 2.900s / 2.367s / 2.011s
Candidate Gateway canary Exit 0 14.024s
Global install swap Exit 1 30.002s, rollback integrity verification failure
update-candidate overall Failed Updater JSON: status=error, reason=global-install-failed
Post-core Doctor and automatic-migration assertions Not reached / not observed Post-core and migration/archive diagnostics unavailable

The failing step reports:

Package rollback verification timed out
Package rollback verification failed: retained package tree changed
Installation recovery is unverified; inspect the installation and backups before restarting.

The before/after reported build IDs both identify the published baseline; the updater's final recovery object reports serviceRestartSafe=true. These observations are retained as reported, not treated as proof of successful activation. Maintainer classification: this is the shipped 2026.9.3/2026.9.4 driver’s 30-second verification wall inside package swap, tracked by #146394. The unreleased main fixes include #144758 (continue after incomplete baseline fingerprints) and #144925 (allow full baseline fingerprints more time on slow disks). Both fixes are ancestors of this candidate and absent from the published 2026.9.4 source build 3a9d69db306c. A candidate cannot retroactively change the installed driver’s first-hop budget. This volume-cell failure does not establish a defect in this PR’s publication guard.

Archival/publication outcome: no live retained-session archival/publication result was established. The successful Doctor steps were candidate rehearsal/lint; the run failed before a post-core Doctor result or live migration/archive receipts were available. The passing base cell below now provides the completed published-driver × candidate migration/publication proof.

Artifacts are under .local/l448-proof/cell/ in the author worktree: cell-result.json, row-execution.json, raw/summary.json, raw/phases.jsonl, raw/update.json, raw/update.err, diagnostics/*/failure.json, package/registry manifests, build/pack logs, and the unchanged range-diff. The completed volume row’s disposable npm installation was removed after classification; its summaries, receipts, diagnostics, logs, tarball, and registry evidence remain. The owned container and image were removed. The lowest observed host free-space reading was 16.764 GiB, above the required floor.

Base cell — passed: published driver × candidate migration/publication proof

Published [email protected] updated to the unchanged candidate 9223ec79e054f2e1fcba1e4c190433325ff0c6d5, using scenario base, restart mode manual, command limit 1800s, and Docker run limit 7200s. The same validated tarball (sha256:25c26616786853411affb2af3b5d59089896b5712d1abec21fbb18161134256a) and candidate registry were reused. No code edit, rebase, fixture/assertion change, or timeout increase was made for this cell.

Completed result: passed, exit 0, in 280.392s, on 2026-09-16 11:40:38–11:45:19 UTC. Updater JSON reports status=ok, updateOutcome=success; the installed build changed from the published 3a9d69db306c release to 9223ec79e054.

Phase / boundary Result Evidence
Published baseline installation, config and state seeding Passed Exact [email protected]; baseline assertions passed
Candidate staging Exit 0 29.925s
Global install swap Exit 0 34.187s aggregate step; candidate replaced the installed package
Updater-owned Doctor ok, exit 0 10.747s; three session rows and three transcript events imported and verified
Post-core plugin convergence ok, child exit 0 Codex, Discord and WhatsApp repaired; no convergence warnings/errors or integrity drifts
Post-plugin Doctor ok, exit 0 Captured Doctor receipt; pending Discord/WhatsApp migration warnings cleared; no failure facts
Automatic migration assertion Passed before standalone Doctor Original root sessions.json absent; all three canonical session identities, metadata and transcript history preserved
Standalone Doctor and survival assertions Passed No extra repair was needed to make the earlier automatic-migration assertion pass
Gateway startup / health / readiness / RPC status Passed Startup 18s; health, readiness and status each 1s

Retained-source publication outcome: the first live Doctor explicitly reported plugin_migration_source_retained for the imported index while Discord/WhatsApp work waited for the updating parent. Post-core convergence completed, a later Doctor receipt returned ok with no pending-plugin warnings, and the automatic-migration assertion then verified that the original index was retired while all three sessions and their transcripts survived. This exercises the retained-source settlement/publication flow through the published updater. The base harness verifies retirement and canonical data preservation; it does not separately export an archive-file listing.

Resource recovery: an earlier attempt of this same base cell was paused and resource-aborted during update-candidate when host free space fell below the required floor. It exited 137 with OOMKilled=false and produced no product verdict or completed migration proof. Its controller receipt, phase events and partial logs are preserved. Following scoped cleanup, free capacity recovered, and the identical cell was retried once. The completed attempt was not paused or resource-aborted; its minimum sampled free space was 33.97 GiB. Both attempts are disclosed here rather than treating the interrupted run as a pass.

Artifacts: .local/l448-proof/cell-base/completed-cell.json indexes the evidence. The passing run is under .local/l448-proof/cell-base/attempt-2/: native artifacts/summary.json, artifacts/phases.jsonl, artifacts/update.json, updater/Doctor observations, projected diagnostics, row.log, execution receipt and disk samples. The initial resource-aborted attempt remains at the cell-base/ root. Owned containers/images and disposable runtime/npm-prefix trees were removed; summaries, phases, diagnostics and logs remain.

@clawsweeper

clawsweeper Bot commented Sep 16, 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 gateway Gateway runtime size: XS maintainer Maintainer-authored PR labels Sep 16, 2026
@steipete
steipete marked this pull request as ready for review September 16, 2026 10:08
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 8:10 AM ET / 12:10 UTC (Revision 3).

ClawSweeper review

What this changes

Doctor checks pending plugin migrations through the active publication transaction before archiving retained session originals, with regression coverage and documentation.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix: current main still uses the stale discovery reader. No blocking defect was found, and the completed published-updater evidence resolves the previous review’s proof gap.

Priority: P2
Reviewed head: 9223ec79e054f2e1fcba1e4c190433325ff0c6d5

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A minimal owner-level repair has discriminating red/green regressions and completed upgrade evidence for the affected production flow.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The matching captured PR body records a completed published-2026.9.4-to-candidate Docker update through Doctor’s retained-source publication flow: pending warnings cleared, the original index retired, and all three sessions and transcripts survived. This resolves the previous proof request; the separate failed volume run is not counted as a pass.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The matching captured PR body records a completed published-2026.9.4-to-candidate Docker update through Doctor’s retained-source publication flow: pending warnings cleared, the original index retired, and all three sessions and transcripts survived. This resolves the previous proof request; the separate failed volume run is not counted as a pass.
Evidence reviewed 8 items Introduced repair: The complete pinned introduction changes the assertion to reuse the existing coordinated publication owner; generation comparison, record formats, and public APIs remain unchanged.
Current main still needs the correction: Fetched main still calls assertPendingGeneration with the artifact-preserving discovery reader. The latest supplied release predates this deferred-migration module; no merged replacement fixing this assertion is established.
Release boundary: The deferred-plugin migration module is absent from the supplied latest release commit, consistent with the feature arriving later on main.
Findings None None.
Security None None.

How this fits together

Doctor imports legacy session history into SQLite and retains original files while plugins still need them. Its publication guard checks pending migration obligations before those originals can be archived.

flowchart TD
  A[Legacy session history] --> B[Doctor import and verification]
  B --> C[Retained originals]
  D[Pending plugin migrations] --> E[Current transaction check]
  C --> E
  E -->|Unchanged obligations| F[Verified archival]
  E -->|Changed obligations| G[Preserve originals and warn]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source 0, Tests +31, Docs +2. Total +33 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 1 0
Tests 1 31 0 +31
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 34 1 +33

Review metrics

None.

Technical review

Best possible solution:

Keep discovery snapshots separate from publication checks, with archival decisions reading authoritative pending rows through the existing admitted transaction.

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

Yes, source inspection establishes the stale-read path: change pending obligations inside the publication transaction, then assert either the prior or current generation. The supplied regression output demonstrates both failures; this read-only review did not execute them.

Is this the best way to solve the issue?

Yes. Reusing the existing transaction owner fixes the consistency boundary without weakening discovery isolation or adding another migration implementation.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The matching captured PR body records a completed published-2026.9.4-to-candidate Docker update through Doctor’s retained-source publication flow: pending warnings cleared, the original index retired, and all three sessions and transcripts survived. This resolves the previous proof request; the separate failed volume run is not counted as a pass.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This repairs a bounded Doctor migration-consistency defect without changing configuration, schemas, or public APIs.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The matching captured PR body records a completed published-2026.9.4-to-candidate Docker update through Doctor’s retained-source publication flow: pending warnings cleared, the original index retired, and all three sessions and transcripts survived. This resolves the previous proof request; the separate failed volume run is not counted as a pass.
  • proof: sufficient: Contributor real behavior proof is sufficient. The matching captured PR body records a completed published-2026.9.4-to-candidate Docker update through Doctor’s retained-source publication flow: pending warnings cleared, the original index retired, and all three sessions and transcripts survived. This resolves the previous proof request; the separate failed volume run is not counted as a pass.

Evidence

What I checked:

  • Introduced repair: The complete pinned introduction changes the assertion to reuse the existing coordinated publication owner; generation comparison, record formats, and public APIs remain unchanged. (src/infra/deferred-plugin-migrations.ts:140, 9223ec79e054)
  • Current main still needs the correction: Fetched main still calls assertPendingGeneration with the artifact-preserving discovery reader. The latest supplied release predates this deferred-migration module; no merged replacement fixing this assertion is established. (src/infra/deferred-plugin-migrations.ts:140, cf6f6d926fd8)
  • Release boundary: The deferred-plugin migration module is absent from the supplied latest release commit, consistent with the feature arriving later on main. (src/infra/deferred-plugin-migrations.ts, 3a9d69db306c)
  • Stale-read mechanism and transaction behavior: The discovery reader skips cached connections holding a transaction and prepares a committed snapshot. The write owner instead reuses the admitted connection, and nested transactions use savepoints, allowing the assertion to observe its transaction’s writes. (src/state/openclaw-state-db-readonly.ts:214, 9223ec79e054)
  • Production archival boundary: Retained-source settlement passes its completion assertion into transcript and index archival while publication remains enclosed by withDeferredPluginMigrationsCurrent. Existing maintenance authority, source identity, and import-receipt checks remain in place. (src/commands/doctor-session-sqlite.ts:433, 9223ec79e054)
  • Meaningful regression coverage: The two added cases use real SQLite state to distinguish stale and current generations inside publication. The supplied red/green output records both failing before the repair and all 13 deferred-migration cases passing afterward; this review did not execute tests. (src/infra/deferred-plugin-migrations.test.ts:133, 9223ec79e054)

Likely related people:

  • Peter Steinberger: Raw commit dac3cb6 adds src/infra/deferred-plugin-migrations.ts:167 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: dac3cb6d47c2; files: src/infra/deferred-plugin-migrations.ts)

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-16T10:15:05.035Z sha 243fb59 :: blocked before merge. :: none
  • reviewed 2026-09-16T11:30:22.970Z sha 9223ec7 :: blocked before merge. :: none

@steipete
steipete force-pushed the upd/publication-guard-transaction branch from 243fb59 to 9223ec7 Compare September 16, 2026 11:23
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 16, 2026
@steipete
steipete merged commit 4aef2ed into main Sep 16, 2026
199 checks passed
@steipete
steipete deleted the upd/publication-guard-transaction branch September 16, 2026 15:50
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS 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