Skip to content

fix(update): let native Doctor own managed schema crossings - #169752

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-schema-crossing-generic-update-20260919
Oct 12, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-schema-crossing-generic-update-20260919

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Managed release activation rejects supported schema crossings such as agent 25 → 26 because the controller recognizes only previously qualified edges.

User Impact

Managed updates delegate forward migration and recovery to the candidate OpenClaw release. Operators no longer need a controller update for each schema edge. Unknown future schemas and downgrades remain refused. This PR changes no database schema/version or user configuration option, and does not deploy or restart Team.

Migration measurement: 4m03.74s for 3.865 GiB; about 38.9 minutes at 37 GiB by linear extrapolation, excluding backup, drain, and restart. The shared Linux rig was contended and used synthetic data, so this is a scenario estimate, not a production downtime promise. Short outages at that scale need a separate OpenClaw-owned resumable derived-column backfill.

A native restore interrupted while publishing database files can require explicit recovery. It retains backups and displaced files and keeps the Gateway stopped; it never starts an older reader against mixed generations. Automatic per-file database restoration is deliberately outside this change. Existing edge-specific transactions must settle with their original installed controller before adopting this closure.

Why This Change Was Made

The controller keeps build, drain, service lifecycle, release pointers, and acceptance. The candidate's internal update migrate, update restore, and update finish commands reuse OpenClaw's WAL-safe backup, Doctor maintenance, and restoration owners. Durable receipts retain database/config preimages and canonical include bindings. Unchanged config includes are left untouched; restoring a symlinked include preserves its alias and restores the canonical target.

Delete the controller's schema-edge tables, copied rehearsals, qualification/preservation machinery, and obsolete tests. Keep its startup fence closed through migration and restoration. Acceptance checks readyz, real sessions.list, and the original session witness before retiring recovery artifacts. Host handoff retains pre-Doctor copy verification and post-Doctor logical continuity checks. Give migration/restoration at least two hours, preserving larger existing build-budget overrides. Update the operator skill and controller README.

Production delta, excluding tests, fixtures, support, and Markdown: +890 / -4,527 = -3,637 lines.

Evidence

  • Before: controller admission for 25 → 26 exits 2 with unsupported shared or agent schema crossing. After: admission returns native-update.
  • Native recovery regression: future-schema refusal, failure rollback, successful cleanup, interrupted config retry/newer-content refusal, absent primary config, canonical backup path, unchanged include, and symlink include. 8/8 pass with node scripts/run-vitest.mjs src/cli/update-cli/update-command-migrate.test.ts --maxWorkers=1 (544.28s wall, 316.73s test time on the contended Mac; 19.44s summed case time on CI/Bun). Both new include regressions were first observed failing for the intended reasons.
  • Actual Doctor assembly, without mocking Doctor: synthetic 25 → 26 → 25 passes with original config and canonical session data restored.
  • Linux synthetic controller flow: 3/3 accepted flows (25 → 26, wider shared/agent crossing, same-schema repair) and 3/3 negative flows (migration failure, startup failure, failed restoration stays stopped). Across focused runs, 68 controller contract cases passed. Initial fixture failures were repaired and the affected cases replayed; this is not a full systemd/live-service proof.
  • JSON command-classification guard: 4/4 pass; the native callback/catch type contracts and always-JSON classification were corrected after initial CI findings.
  • Independent complete-diff review: no actionable P0–P2 findings. Focused lint, Bash/Node syntax, and git diff --check pass.
  • Export collision, eager-import closure, PR-wrapper closure, and CI Node test-plan guards pass. Full repository gates use PR CI; no additional leases were started after the local-light validation rule.

Synthetic migration measurement

The real candidate schema owner ran under its maintenance lease on Linux, using the full v25 schema: 500,000 transcript rows, 25,000 sessions/windows, and 12,500 outbox rows with mixed raw/compressed payloads. Command: nice -n 10 ionice -c3 /usr/bin/time -v node --import ./scripts/tsx.mjs .local/lane809/benchmark.ts migrate, with disk-backed task-local TMPDIR. Exit 0; both version markers became 26; canonical sample bytes and row counts were preserved.

Peak RSS: 630.6 MiB. Peak source/WAL/temp footprint: 11.557 GiB (~3× input); a retained backup adds another input-sized copy. A 7.73 GiB process-kill trial preserved schema 25, counts, and canonical samples after reopen. Its later completion attempt hit the rig's disk safety floor and was stopped. No production database was copied.

Validation environment

Earlier remote native proof passed 61 tests in five files on Hetzner lease cbx_02ad7c96ce0a. Queued Testbox attempts did not run tests; the small AWS fallback failed during compilation with exit 137. Those runs preceded the current validation policy, and all leases were released. Current final proof uses the focused local native file and PR CI.

@clawsweeper

clawsweeper Bot commented Oct 12, 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 cli CLI command changes commands Command implementations size: XL labels Oct 12, 2026
@steipete
steipete marked this pull request as ready for review October 12, 2026 08:16
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR delegates managed schema migration and restoration to native OpenClaw owners and removes the controller’s edge-specific migration machinery.

Example: A managed update advances an agent database from schema 25 to 26.

  • Before: The controller rejects the crossing as unsupported.
  • After: The controller invokes the candidate’s native migration command and verifies activation or restores the predecessor.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The owner consolidation has clear value, but a supported config remains blocked and unchecked rollback can discard accepted writes.
Proof confidence 🦐 gold shrimp (3/6) Ordinary contributor proof gating is exempt for this maintainer-authored PR; reported synthetic native Doctor and controller flows support the owning boundaries, but do not establish latest-stable installed-driver compatibility for the new recovery path.
Patch quality 🧂 unranked krab (1/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Managed updates reject supported schema crossings until the deployment controller learns each new edge.
Reason: The maintainer-authored direction completes the interim controller’s intended native handoff and removes substantial duplicate migration policy.

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep this PR open: the native-owner cutover is useful, but Doctor-repairable config remains blocked and rollback can discard writes accepted by the candidate; the earlier JSON-classification finding is fixed.

Priority: P2
Reviewed head: de960fd14e5df518d289316329e3146cbed66862

Before merge

  • Admit Doctor-repairable config before invoking migration (P1) - For agents.entries={ops:{},research:{default:true}}, the config reader returns valid=false because the shipped default marker requires Doctor. This call supplies neither a legacy plan nor candidate validation, so captureTargetDatabaseSchemaContext throws before backup capture and runDoctorHealthFlow. Managed schema crossings and explicit offline Doctor repair therefore cannot repair this supported input. Use the existing non-mutating legacy/candidate admission path, retain the authored preimage, and cover this input through the native migration owner.
  • Preserve candidate-accepted writes before restoring snapshots (P1) - The controller starts the candidate before acceptance completes, and a fresh Gateway admits ordinary work. If a user message commits during that window and a later channel or model-marker check fails, rollback stops the candidate and reaches this call. Omitting expectedGenerations bypasses the existing native later-write refusal and replaces active databases with pre-update snapshots, removing that accepted session/transcript work; retaining displaced files only permits manual recovery. Reuse native write-generation safeguards and preserve current state when restoration would discard later writes. This is a late discovery: the unsafe restore call and controller path were equally visible at the earlier reviewed head 14b0272 and remain unchanged.
  • 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.
  • Explain or restore the original intent of Native restoration eligibility - d780fdc: Restoration preserved unaccounted writes by checking recorded generations and excluding candidates that had begun activation.

Findings

  • [P1] Admit Doctor-repairable config before invoking migration — src/cli/update-cli/update-command-migrate.ts:137
  • [P1] Preserve candidate-accepted writes before restoring snapshots — src/cli/update-cli/update-command-migrate.ts:282-287

Provenance

  • Native restoration eligibility changes intended behavior without addressing why it exists (d780fdc: Restoration preserved unaccounted writes by checking recorded generations and excluding candidates that had begun activation.)

Tests

  • Missing end-to-end proof: Show the v2026.10.2 installed-driver-to-candidate upgrade and recovery flow with existing settings, include bindings, agent ownership, and session data intact.
Agent review details

How this fits together

The deployment controller owns service lifecycle, release pointers, and acceptance; native update commands receive stopped state and a backup root and use the existing backup, Doctor, and restoration owners.

flowchart TD
  A[Managed controller] --> B[Drain and stop Gateway]
  B --> C[Native migration command]
  C --> D[Backup and Doctor owners]
  D --> E[Candidate start and acceptance]
  E --> F[Retire backup]
  E --> G[Native restoration command]
  G --> H[Predecessor recovery]
Loading

Technical review

Best possible solution:

Keep the native-owner cutover, admit repairable config without changing its preimage, and preserve writes accepted by the candidate during recovery.

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

Source establishes main’s unsupported crossing, the head’s legacy-config refusal, and the unchecked restoration path after candidate startup; no target code was executed.

Is this the best way to solve the issue?

Delegating to existing native owners is the right approach, provided the adapter preserves their repairable-config admission and later-write recovery safeguards.

Full review comments:

  • [P1] Admit Doctor-repairable config before invoking migration — src/cli/update-cli/update-command-migrate.ts:137
    For agents.entries={ops:{},research:{default:true}}, the config reader returns valid=false because the shipped default marker requires Doctor. This call supplies neither a legacy plan nor candidate validation, so captureTargetDatabaseSchemaContext throws before backup capture and runDoctorHealthFlow. Managed schema crossings and explicit offline Doctor repair therefore cannot repair this supported input. Use the existing non-mutating legacy/candidate admission path, retain the authored preimage, and cover this input through the native migration owner.
    Confidence: 0.99
  • [P1] Preserve candidate-accepted writes before restoring snapshots — src/cli/update-cli/update-command-migrate.ts:282-287
    The controller starts the candidate before acceptance completes, and a fresh Gateway admits ordinary work. If a user message commits during that window and a later channel or model-marker check fails, rollback stops the candidate and reaches this call. Omitting expectedGenerations bypasses the existing native later-write refusal and replaces active databases with pre-update snapshots, removing that accepted session/transcript work; retaining displaced files only permits manual recovery. Reuse native write-generation safeguards and preserve current state when restoration would discard later writes. This is a late discovery: the unsafe restore call and controller path were equally visible at the earlier reviewed head 14b0272 and remain unchanged.
    Confidence: 0.96
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Controller migration admission and recovery changes intended behavior with a stated reason (072215c: The controller was imported as an interim deployment closure pending proven native migration and recovery support.)
  • Host-handoff preservation verification changes intended behavior with a stated reason (072215c: Imported copies were verified against original backups; this PR retains exact pre-Doctor verification and documents logical continuity afterward.)
  • Doctor verified snapshot reuse keeps the original intent (2a1402c: Doctor reused verified recovery coverage before migration; the new handoff supplies that coverage from the updater’s native capture.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/cli/update-cli/update-command-migrate.test.ts --maxWorkers=1
  • pnpm test src/infra/update-database-restore.test.ts --maxWorkers=1
  • pnpm test src/config/legacy.roster.test.ts --maxWorkers=1
  • pnpm test src/cli/program/root-command-descriptions.test.ts --maxWorkers=1
  • node --import ./.agents/skills/update-team-server/controller/test-environment.mjs --test ./.agents/skills/update-team-server/controller/frozen-continuation.test.mjs ./.agents/skills/update-team-server/controller/migration-admission.test.mjs

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit d780fdc adds src/infra/update-database-restore.ts:94 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d780fdc672d3; files: src/infra/update-database-restore.ts)
  • Jason (Json): Raw commit b66471a adds src/infra/update-database-restore.ts:257 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b66471a26d9a; files: src/infra/update-database-restore.ts)

PR surface

Source +444, Tests -3542, Docs 0, Other -4098. Total -7196 across 30 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 7 447 3 +444
Tests 18 700 4242 -3542
Docs 2 87 87 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 443 4541 -4098
Total 30 1677 8873 -7196

Review metrics

Metric Value Why it matters
Production versus tests Production +890/-4,527; tests +697/-4,031 The reduction removes competing migration and rehearsal policy; fixtures, test support, and Markdown are excluded.
Internal command interface Three hidden commands, each requiring --backup-root These supervisor interfaces add a CLI argument without adding a user configuration key, database schema version, or default.

Labels

Label changes:

  • add merge-risk: 🚨 session-state: Snapshot rollback after candidate startup can remove subsequently accepted session and transcript writes from active state.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦐 gold shrimp and patch quality is 🧂 unranked krab.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.

Label justifications:

  • P2: This repairs supported schema crossings on a limited managed-operator update surface.
  • merge-risk: 🚨 compatibility: A shipped legacy default-agent marker is rejected before its supported Doctor repair can run.
  • merge-risk: 🚨 session-state: Snapshot rollback after candidate startup can remove subsequently accepted session and transcript writes from active state.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦐 gold shrimp and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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-10-12T08:27:08.120Z sha 14b0272 :: blocked before merge. :: [P1] Admit Doctor-repairable config before invoking migration | [P2] Classify the new always-JSON update commands

Reviewed October 12, 2026, 4:37 AM ET / 08:37 UTC (Revision 2).

@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 12, 2026
@steipete
steipete merged commit aee12b6 into main Oct 12, 2026
136 of 137 checks passed
@steipete
steipete deleted the steipete/perf-micro-schema-crossing-generic-update-20260919 branch October 12, 2026 08:48
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…#169752)

* fix(update): delegate managed schema crossings to Doctor

* fix(update): complete JSON and type contracts for migration commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XL 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