Skip to content

fix(doctor): bound scoped backups to version migrations - #172671

Merged
steipete merged 8 commits into
mainfrom
dbasync/migscope
Oct 15, 2026
Merged

steipete merged 8 commits into
mainfrom
dbasync/migscope

Conversation

@steipete

@steipete steipete commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What problem this solves

A small schema migration currently copies and validates the entire database for rollback. A measured 38 GB deployment snapshot spends about 514 seconds validating the backup and 36 seconds copying it, although agent v27 changes only the outbox and planner statistics.

Doctor now finishes each fully declared version phase before broader maintenance. Eligible agent v26→v27 and shared-state v22→v23 migrations can therefore use a table-scoped rollback archive. Installed updater drivers retain their full-file checkpoint contract, and every selected source still receives integrity admission before its checkpoint.

What changed

The agent version runner separates the declared outbox/statistics migration from later startup-column/index repair, session normalization, orphan recovery, transcript repairs, historical media/directives, ACP accounting, and plugin maintenance. Those later operations retain their existing transactions and preserving repair owners. Retained-content rewrites preserve their original image only when an actual rewrite is needed. Older SQLite versions use bounded ANALYZE for statistics refresh through the existing statistics owner.

The automated-review P2 is fixed: version-phase receipts contain only admitted agent targets. A real preflight regression produces an older database that is both pending and indeterminate; before the fix it throws Missing discovered agent migration target. The fixed path returns no receipt for that excluded database and leaves it at v26.

Main is merged through R9 (#172755, c58d6181af08). Its shared-state v23 declaration remains exactly ["meeting_transcript_sessions"]; the resolver adds schema_meta and config_machine_state. The state version phase runs before agent maintenance leases can open shared state. Unrelated index repair, orphan recovery, quarantine cleanup, and full runtime-shape admission remain with later Doctor maintenance. Scoped restoration preserves current undeclared planner statistics with the archive's existing byte-preserving row codec, including raw text bytes, bigint rowids, and later ANALYZE results. Explicitly declared statistics retain archive-restore semantics. No migration declaration, schema number, retention policy, or public API is changed by this PR.

The declared phase reuses integrity admission under the same offline Doctor custody; it adds no foreign-write polling. Recording backup completion after commit is best effort: failure emits a warning and leaves the original image protected.

Evidence and impact

Measurement Base Candidate
Backup bytes, 1 GiB synthetic retained payload 1,108,066,304 24,576
Backup seconds, median [min–max], three pairs 48.789 [48.295–54.325] 10.036 [7.907–54.086]
Warm all-thread statements/turn, median [min–max] 151.9 [151.6–156.2] 149.1 [147.6–150.9]
Warm requests/turn, median [min–max] 48.4 [48.0–48.9] 47.4 [46.5–47.6]
Turn-caused warm MAIN statements/turn 0 0

Net change against the merged base: production +309 lines, tests +636, docs/tooling +166.

The synthetic archive is 99.9978% smaller. Avoiding the measured deployment snapshot's copy and copied-image validation would remove about 550 seconds of backup work per eligible standalone/startup Doctor migration. Source admission remains. Host load exceeded available cores, so these observed benchmark times are not production latency claims. The touched migration owners contributed zero statements/requests to warmed turns in all six harness runs; the small aggregate decreases are workload noise, not a runtime saving claimed by this PR.

The existing agent fixture verifies undeclared schema and typed contents, retained history, and populated statistics. A deliberate second-database failure plus production restore recovers the first database's version and FIFO outbox while preserving a later unrelated write. Orphan and updater-marker fixtures retain their full-backup contracts. The new state fixture exercises the actual Doctor migration entry point, requires a scoped archive, checks every undeclared table, defers an unrelated missing index, and restores v22 while retaining later unrelated data and statistics.

Validation at the landing head:

  • P2 regression reproduced before the fix. Its focused review is scoped-clean P0/P1.
  • STATE v23 Doctor boundary suite passed 3/3 on the shared-codec implementation. The snapshot suite exposed a Node SQLite write-receipt overflow for rowids above 2^53; enabling bigint receipts fixes it, and all 10 snapshot tests now pass. The changed migration/Doctor, state, and snapshot selection now passes all 103 tests across 12 files, combining the completed unchanged-owner run and targeted rerun after the receipt fix. The final state review is scoped-clean P0/P1.
  • Changed-file format/type-aware lint and the dialect ratchet pass. Final-head CI is fully green, covering production/test types, core/plugin lint, source contracts/export collisions, architecture/Madge, ratchets, and PostgreSQL conformance. The separate Knip export comparison completed at one-minute load 57.71. Production (5), full-tree (2), and scripts (0) findings exactly match scheduled main c58d6181af08. A misplaced SAFETY comment was fixed; scoped assertion-safety and final type-aware core lint pass.
  • The prior published-driver update and forced-failure scoped-restore cell passed, including package integrity and npm 12 installation. The final-head published-driver cell passed in one 499-second attempt, and the whole workflow completed successfully. Its exact-head artifact verifies the unmodified published updater, finished/succeeded update receipt, service PID replacement, readiness HTTP 200, retained durable history, and explicit scoped restore after a forced migration failure. Restore returns the healthy member to v26 while preserving FIFO, both outbox rows, and a later unrelated write. This is explicit restore proof; automatic updater rollback was not exercised. The obsolete P2-head and pre-bigint-fix runs were cancelled and verified terminal.
  • Prior-head CI passed production/test types, core/extensions lint, source contracts/export collisions, Madge, T1/dialect ratchets, PostgreSQL conformance, and changed migration/Doctor tests. The subsequent P2-head run's static jobs also passed, but 123 test jobs failed before checkout because the actions/setup-go archive returned HTTP 404; those jobs provide no behavioral evidence.

Failure classification and proof limits

The historical Telegram join-introduction failure (Automation has no recorded inference account, run 38669500382/job 116209598979) was a base regression fixed upstream by #172775, commit 5f604ddd809518b8d0ce4ad9142584b90ebb12d3. The earlier merge context's main parent 035bf890 treated immediate room-join turns as cron automation. The fix propagates trigger: "event" and restricts the recorded-inference-account requirement to cron turns. It is present in the pinned main baseline, this PR, and current main 91b328ad22271caf6b6fe0ede9ac2597e4d24771.

The exact Telegram test, introduces itself once when Telegram reports joining an allowed supergroup, passes on the final PR head in run 38690495848/job 116275802459, now shard checks-node-changed-23: one file/one test, 64,991 ms, exit 0. No current Telegram failure is being waived. Local main attempts were inconclusive: standalone preparation spent over 72 minutes compiling declarations; CI-style qaRuntime preparation then passed in 33m16s, but the runner's five-minute silence watchdog stopped cold worker compilation before the Telegram case began. Those attempts establish neither a main behavioral pass nor a failure. Current main's later fixture/launcher changes are distinct from the unchanged join-event/auth-guard fix.

The focused runner invocation was:

OPENCLAW_E2E_USE_PREBUILT_DIST=1 node scripts/run-vitest.mjs run \
  --config test/vitest/vitest.e2e.config.ts \
  test/e2e/qa-lab/runtime/telegram-join-intro-gateway.e2e.test.ts \
  --maxWorkers=1

It followed CI's OPENCLAW_BUILD_PRIVATE_QA=1 OPENCLAW_RUN_NODE_SKIP_DTS_BUILD=1 VITEST=1 pnpm build qaRuntime; a task-local filesystem module cache was also configured. Final CI's native shard runner executed the same test against its prepared runtime. The queued local retry was cancelled once that direct final-head proof and the upstream cause/fix were verified.

The migration-runner restart-test failure carried forward from #172390 remains unclassified. No matching baseline failure establishes its cause. The earlier hook-pressure case (20 tool outputs, 19 hook invocations) also remains unclassified despite a later passing replay. Earlier Cron inference-account fixture failures matched scheduled main and passed in the later PR run. The earlier OpenShell retirement path failed on both candidate and baseline with different terminal timing; it is not claimed as an identical-signature failure or a repaired flake.

The former remote proof request reports completion without a GitHub run association; its recovery claim remains preserved, with no duplicate allocation. Ordinary PR CI does not cover Knip. Local export scans used a 30-minute per-scan timeout and began at one-minute load 57.71. The inherited findings are listBundledChannelPluginIds, bindChatPickerOverlay, handleChatComposerDetailsToggle, syncChatPickerOverlay, ChatWorkingIndicatorOptions (production); ClaudeCliSpawnProofKind and syncChatPickerOverlay (full-tree); none (scripts).

Landing head: a71c9506d8ad9b9dadd35adc53c071d830b91382. The last delta enables bigint write receipts and moves an existing SAFETY comment. All required final-head gates are complete; inherited Knip findings and unresolved historical proof limits are identified above.

@clawsweeper

clawsweeper Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper reviews are opt-in for maintainers. If a review is required, finish the work and validation first, then comment @clawsweeper review. Please avoid repeated requests while a review is queued or running; agents should not request reviews automatically.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T06:12:54.932142Z a71c950 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation commands Command implementations size: L labels Oct 15, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 429f22cd74

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts docker Docker and sandbox tooling labels Oct 15, 2026
Exclude pending migrations whose databases were not admitted by preflight. This prevents an older pending-and-indeterminate database from reaching the version runner or later Doctor consumers as a completed migration. Add a production-path regression that reproduced the missing-target error and checks that the excluded database stays at v26.
@steipete
steipete merged commit 3cd9950 into main Oct 15, 2026
280 checks passed
@steipete
steipete deleted the dbasync/migscope branch October 15, 2026 07:51
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
)

Complete declared schema version phases before broader Doctor maintenance so eligible agent v26-to-v27 and shared-state v22-to-v23 migrations can use table-scoped rollback archives. Preserve full-file rollback for installed updater drivers and undeclared scopes, source-integrity admission, and existing repair owners.

Filter version receipts to admitted agent targets, preventing pending-but-indeterminate databases from failing the update path. Run the declared state migration before agent leases can write shared state, retain R9's meeting_transcript_sessions declaration, and preserve live undeclared planner statistics through the existing byte-preserving row codec during scoped restore.

Add Doctor entry-point undeclared-table and forced-restore coverage, the published-driver recovery cell, and bounded statistics refresh for older supported SQLite. The synthetic 1.1 GB backup becomes 24 KB; no warmed-path SQL saving is claimed. No schema-version or retention-policy change.

The migration-runner restart-test failure carried forward from openclaw#172390 remains unclassified; see the PR for validation and inherited CI evidence.
sectrgt pushed a commit to sectrgt/openclaw that referenced this pull request Oct 29, 2026
)

Complete declared schema version phases before broader Doctor maintenance so eligible agent v26-to-v27 migrations can use table-scoped rollback archives.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docker Docker and sandbox tooling docs Improvements or additions to documentation scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant