Skip to content

fix(state): let doctor repair legacy v17 agent databases - #134208

Merged
obviyus merged 4 commits into
openclaw:mainfrom
EthDing:codex/fix-134163-agent-schema-migration
Aug 31, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
EthDing:codex/fix-134163-agent-schema-migration

Conversation

@EthDing

@EthDing EthDing commented Aug 31, 2026 •

Copy link
Copy Markdown

Fixes #134163

What Problem This Solves

openclaw doctor --fix could not migrate a supported agent database from schema v17 when both the additive session route context and the canonical transcript identity index were absent. Doctor validated the additive object before creating it, warned, and left the database at v17.

Root Cause

The v17 canonical-index repair callback ran the strict legacy-schema assertion before ensureSessionAdditiveColumns. The assertion therefore required the route-context trigger that the additive owner had not created yet.

Fix

The existing canonical-index repair savepoint now runs ensureSessionAdditiveColumns before its strict v17 assertion. Additive convergence, index repair, and validation stay atomic. Unrelated schema drift rolls back both repairs.

The takeover keeps validateAfterRepair, does not change the schema version, does not add another migration path, and adds no configuration.

Evidence

I installed CI-built OpenClaw packages for baseline c884d51b870 and contributor head bb70bcb73db2, then ran the distributed binary against byte-identical isolated v17 fixtures.

$ OPENCLAW_STATE_DIR=<isolated> openclaw doctor --fix --non-interactive --yes --no-workspace-suggestions

# baseline
Skipped agent database migration ... missing or drifted trigger session_conversations_route_context_invalidate_after_update
exit 1; user_version 17; additive column absent; canonical index absent

# repaired head, first run
Upgraded agent database schema ... v17 -> v19.
exit 0; user_version 19; schema_meta 19; column, trigger, participant table, and index present
PRAGMA integrity_check = ok; PRAGMA foreign_key_check = empty

# repaired head, second run
Doctor complete.
exit 0; no upgrade message; no skipped-migration message; schema remains clean at v19

The baseline package came from dist-runtime-build run 33408370171. The repaired package came from dist-runtime-build run 33406382600.

Regression Coverage

  • The positive regression fails before the repair with the same missing-trigger warning.
  • The positive regression reaches the current schema and verifies the restored column, trigger, participant table, and canonical index.
  • The negative control removes cache_entries and proves non-additive drift leaves v17 while rolling back both additive and index repair.
  • Focused validation passed 20 tests across the migration owner and sibling session-schema paths.
  • A Doctor CLI process regression runs doctor --fix twice, verifies v17 reaches the current schema, and verifies the second run is clean.

History

entry_valid predates v17. Commit cd8a96491e2 added it while the agent schema was v16. Commit 38fabc4e031 later created v17. Tag v2026.8.1-beta.2 contains v17 and entry_valid, so the savepoint does not expand to that older repair.

@clawsweeper

clawsweeper Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@EthDing
EthDing marked this pull request as ready for review August 31, 2026 15:04
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 31, 2026
@clawsweeper

clawsweeper Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 31, 2026, 12:18 PM ET / 16:18 UTC.

ClawSweeper review

What this changes

The PR repairs legacy v17 agent databases by creating missing additive session objects inside the canonical-index repair savepoint before strict schema validation, with migration and Doctor CLI regression coverage.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

No blocking correctness finding. The owner-level repair is coherent and the supplied packaged Doctor trace clears the prior proof gap; this fresh PR should remain open for exact-head CI and normal maintainer review.

Priority: P1
Reviewed head: b80d94689d66e5be6f710981f51a014632f49b66

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong behavior evidence and focused owner-boundary coverage support a correct, net-neutral repair; exact-head CI remains the appropriate final gate for this persistence-sensitive change.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed production owner is the v17 schema repair callback in src/state/openclaw-agent-db-schema.ts, reached by Doctor’s media-persistence migration. The PR body supplies a real packaged baseline-versus-repaired Doctor invocation against an isolated v17 database, showing v17→v19 recovery, clean integrity checks, and an idempotent second run; the final branch adds matching source-runtime process coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed production owner is the v17 schema repair callback in src/state/openclaw-agent-db-schema.ts, reached by Doctor’s media-persistence migration. The PR body supplies a real packaged baseline-versus-repaired Doctor invocation against an isolated v17 database, showing v17→v19 recovery, clean integrity checks, and an idempotent second run; the final branch adds matching source-runtime process coverage.
Evidence reviewed 8 items Repair owner: The introduced v17 branch runs additive session convergence before the strict legacy-schema assertion, within the canonical-index repair callback and savepoint.
Caller and owner boundary: Doctor's media-persistence migration delegates supported agent schemas to this canonical owner before its own schema validation, avoiding a second migration implementation.
Atomic rollback contract: The index helper executes validation inside a savepoint and rolls back the repair if validation fails; the new callback therefore rolls back additive and index changes together.
Findings None None.
Security None None.

How this fits together

Doctor repairs each persisted per-agent SQLite database before gateway startup uses it. Its migration path must turn a supported legacy schema into the current validated schema or preserve the database unchanged when unrelated drift makes repair unsafe.

flowchart LR
  A[Legacy v17 agent database] --> B[Doctor --fix]
  B --> C[Migration owner]
  C --> D[Index and additive repair savepoint]
  D --> E[Current schema validation]
  E --> F[Gateway startup]
  D --> G[Rollback on unrelated drift]
Loading

Before merge

  • Resolve merge risk (P1) - This changes repair behavior for persisted agent databases. The supplied trace and negative control are strong, but exact-head CI should still validate the final branch before merge.
Agent review details

Security

None.

PR surface

Source 0, Tests +187. Total +187 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 6 0
Tests 2 188 1 +187
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 194 7 +187

Review metrics

Metric Value Why it matters
Production versus test LOC production +6/-6 (net 0); tests +188/-1 (net +187) The repair preserves net-neutral production size while adding migration-owner and real Doctor-process coverage.
New persistent surface 0 DDL additions; 0 config options The PR changes repair ordering for existing schema objects rather than expanding the stored-data or operator configuration contract.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #134163
Summary: This PR explicitly targets the same v17 Doctor migration failure documented in the linked issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Confirm the final migration path (recommended)
    Let exact-head CI validate the final branch’s persisted-schema repair path before merging.
  2. Accept the bounded migration risk
    Merge based on the supplied packaged before/after trace and atomic rollback coverage if maintainers accept the remaining exact-head CI wait.

Technical review

Best possible solution:

Keep one canonical v17 preflight that atomically converges additive session schema and canonical indexes before the normal schema migration, retaining both migration-owner and Doctor-process regressions.

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

Yes. The v17 callback and its Doctor caller establish the path in source, and the PR supplies a packaged before/after Doctor trace using the same missing trigger, column, and canonical index scenario.

Is this the best way to solve the issue?

Yes. This is the best repair shape: it converges the missing additive objects at the canonical validation owner and shares the existing savepoint, rather than adding a Doctor-only workaround or a parallel migration path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9cc05cca83e2.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the v17 schema repair callback in src/state/openclaw-agent-db-schema.ts, reached by Doctor’s media-persistence migration. The PR body supplies a real packaged baseline-versus-repaired Doctor invocation against an isolated v17 database, showing v17→v19 recovery, clean integrity checks, and an idempotent second run; the final branch adds matching source-runtime process coverage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed production owner is the v17 schema repair callback in src/state/openclaw-agent-db-schema.ts, reached by Doctor’s media-persistence migration. The PR body supplies a real packaged baseline-versus-repaired Doctor invocation against an isolated v17 database, showing v17→v19 recovery, clean integrity checks, and an idempotent second run; the final branch adds matching source-runtime process coverage.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: A supported database lineage can prevent Doctor from completing migration and block gateway startup.
  • merge-risk: 🚨 compatibility: The repair changes how existing on-disk agent databases are accepted and upgraded.
  • merge-risk: 🚨 session-state: The affected SQLite schema stores agent session and transcript-routing state.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed production owner is the v17 schema repair callback in src/state/openclaw-agent-db-schema.ts, reached by Doctor’s media-persistence migration. The PR body supplies a real packaged baseline-versus-repaired Doctor invocation against an isolated v17 database, showing v17→v19 recovery, clean integrity checks, and an idempotent second run; the final branch adds matching source-runtime process coverage.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the v17 schema repair callback in src/state/openclaw-agent-db-schema.ts, reached by Doctor’s media-persistence migration. The PR body supplies a real packaged baseline-versus-repaired Doctor invocation against an isolated v17 database, showing v17→v19 recovery, clean integrity checks, and an idempotent second run; the final branch adds matching source-runtime process coverage.

Evidence

What I checked:

Likely related people:

  • Omar Shahine: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Confirm exact-head CI completes before merge.

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 (1 earlier review cycle)
  • reviewed 2026-08-31T15:12:22.254Z sha bb70bcb :: needs real behavior proof before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 31, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 31, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 31, 2026
@obviyus
obviyus merged commit 592253f into openclaw:main Aug 31, 2026
276 of 280 checks passed
@obviyus

obviyus commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Thanks @EthDing!

Proof: The exact-head CI-built package ran openclaw doctor --fix against an isolated v17 agent database. The first run reached v19 with clean integrity checks. The second run completed without another migration.

  • Bug: Doctor validated a missing additive session trigger before creating it, so the database stayed at v17.
  • Fix: The schema owner now performs additive and canonical-index repair in one savepoint before strict validation.
Before After
Doctor exits with a migration warning and leaves schema v17. Doctor reaches schema v19 and a second run is clean.

Source: b80d94689d66e5be6f710981f51a014632f49b66

Landed: 592253ffd1039d877a9ce2cacbde5702176ea297

obviyus added a commit that referenced this pull request Sep 1, 2026
Move the schema-17 additive and canonical-index preflight into the existing migration transaction. A later participant identity rejection now rolls back every prerequisite write while damaged-index recovery still works.

Replace the false-green early-rejection test with red/green owner and `openclaw doctor --fix` process regressions.

Related to #134163 and follows #134208.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 1, 2026
…4208)

Fixes openclaw#134163.

Repair the v17 additive session schema inside the canonical-index savepoint before strict validation. Preserve rollback for unrelated schema drift and cover the distributed Doctor path.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 1, 2026
Move the schema-17 additive and canonical-index preflight into the existing migration transaction. A later participant identity rejection now rolls back every prerequisite write while damaged-index recovery still works.

Replace the false-green early-rejection test with red/green owner and `openclaw doctor --fix` process regressions.

Related to openclaw#134163 and follows openclaw#134208.

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

Labels

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. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

2 participants