Skip to content

fix(state): make schema-17 session repair atomic - #134272

Merged
obviyus merged 4 commits into
openclaw:mainfrom
RileyJJY:sunlit/fix/issue-134163
Sep 1, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
RileyJJY:sunlit/fix/issue-134163

Conversation

@RileyJJY

@RileyJJY RileyJJY commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Schema-17 repair was not atomic after #134208. Doctor repaired missing additive session objects and a canonical index before the main schema migration transaction began. If the later participant identity migration rejected an unknown dependency, the database stayed at version 17 but retained those prerequisite writes.

Related to #134163 and follows #134208.

Why This Change Was Made

The schema owner now performs the v17 additive and canonical-index preflight inside the existing immediate migration transaction. A later migration rejection rolls back the whole attempt, while the preflight can still recover a damaged canonical index before strict integrity admission.

The regression uses a valid legacy participant table with an unknown non-unique dependency. Current main accepts and commits the prerequisite repair, then rejects the participant migration. The repaired head rejects the same database without leaving the route column, trigger, or repaired index behind.

The final diff also removes the one-use exported helper and the call-order lease test. Production is net-negative and the test now fails on pre-fix code for the intended reason.

User Impact

openclaw doctor --fix still upgrades repairable schema-17 databases to schema 19. If later validation rejects a database, Doctor now leaves its schema unchanged instead of committing a partial repair.

Evidence

  • Current-main red at c50533f9d944e7cced59c650b426d3ea18dfc7d0: the focused regression failed because route_context_json remained present after the participant migration rejection.
  • Exact-head green at 7e8b26722634ae730b1a1c62ef09f5882a7f00a3: sanitized clean Linux proof passed the v17 migration, participant recovery, retired-lease, and full Doctor process suites — 34 tests.
  • Doctor boundary: both the repairable-v17 and rejected-v17 openclaw doctor --fix process paths passed.
  • Production-entrypoint anti-cheat probe: migrateLegacyMediaPersistence produced the same atomic rollback for main and a varied secondary agent id.
  • Static proof: Oxfmt, Oxlint, and git diff --check passed. Production +15/-16 (net -1); tests and test support +193/-26 (net +167).

AI-assisted: built with Codex

@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.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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, 8:46 PM ET / September 1, 2026, 00:46 UTC.

ClawSweeper review

What this changes

This PR moves schema-17 session-schema convergence and canonical-index validation into the migration transaction, renews the maintenance lease before that preflight, and adds rollback and ordering coverage.

Warning

SQLite table change

This PR modifies persisted SQLite tables in src/state/openclaw-agent-db-schema-helpers.ts. Prefer a design that avoids changing persisted SQLite tables. If the change is necessary, verify migration and upgrade compatibility against an existing database before merge.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. The earlier repair was merged in #134208, but this PR still contributes the distinct atomic transaction boundary; no blocking introduced defect was found, and the previous lease-renewal finding is addressed.

Priority: P1
Reviewed head: be71261816beff7edd323508b81c79f67cb2edae

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, owner-boundary repair with credible production-path proof and regression coverage; only normal exact-head validation remains.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The supplied exact-head terminal trace invokes the production migrateLegacyMediaPersistence entrypoint against the v17 database shape and observes schema-19 convergence plus integrity success; focused real-SQLite regressions cover the added rollback and lease-ordering behaviors.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The supplied exact-head terminal trace invokes the production migrateLegacyMediaPersistence entrypoint against the v17 database shape and observes schema-19 convergence plus integrity success; focused real-SQLite regressions cover the added rollback and lease-ordering behaviors.
Evidence reviewed 6 items Introduced atomic migration boundary: The PR performs v17 additive convergence and canonical validation inside the immediate transaction, replacing the former out-of-transaction preflight.
Production entrypoint and owner: Doctor’s media-persistence migration delegates v17-and-later database admission to the canonical schema owner while holding the maintenance lease.
Rollback coverage: The focused regression forces canonical validation failure and verifies that the version plus each added v17 projection object remain absent after rollback.
Findings None None.
Security None None.

How this fits together

OpenClaw Doctor upgrades per-agent SQLite databases before the gateway can operate normally. This change controls the schema-17 path from Doctor’s migration entrypoint through schema validation and final database readiness.

flowchart LR
  A[Doctor repair] --> B[Agent SQLite database]
  B --> C[Migration transaction]
  C --> D[Session schema convergence]
  D --> E[Canonical index validation]
  E --> F[Schema 19 database]
  E --> G[Rollback and warning]
Loading

Before merge

  • Resolve merge risk (P1) - This stored-data migration can still block gateway readiness if it regresses on existing schema-17 databases; the focused proof is strong, but the review snapshot still has incomplete exact-head checks.
  • Resolve merge risk (P1) - Production code grows by a net 19 lines; the added helper is justified by keeping the legacy v17 convergence and validation boundary in one transaction.
  • Complete next step (P2) - No repair job is needed: this contributor PR already implements the direct migration-boundary fix, and the remaining action is normal exact-head validation.
Agent review details

Security

None.

PR surface

Source +19, Tests +188. Total +207 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 37 18 +19
Tests 1 189 1 +188
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 226 19 +207

Review metrics

Metric Value Why it matters
Production versus test LOC production +37/-18 (net +19); tests +189/-1 (net +188) The production growth creates one transaction-bound migration helper; the larger test delta covers ordering and rollback behavior.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/state/openclaw-agent-db-schema-helpers.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: partial_overlap
Canonical: #134163
Summary: The PR refines the same schema-17 Doctor repair, while adding an atomicity guarantee not present in the earlier merged fix.

Members:

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

Merge-risk options

Maintainer options:

  1. Land after exact-head validation (recommended)
    Retain the atomic v17 preflight and proceed once the PR’s required migration checks complete on its exact head.

Technical review

Best possible solution:

Retain the dedicated transaction-bound v17 preflight and merge after exact-head migration validation completes, preserving rollback for every preflight failure.

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

Yes, source-reproducible with high confidence: the deterministic Doctor migration entrypoint reaches the v17 schema owner, and the supplied exact-head trace exercises that production path against the affected database shape. This read-only review did not execute the contributor command.

Is this the best way to solve the issue?

Yes. Moving all v17 additive convergence and validation under the existing immediate transaction is the clean owner-boundary repair; leaving validation outside it would permit partial schema writes on rejection.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 04d73ea52d82.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 supplied exact-head terminal trace invokes the production migrateLegacyMediaPersistence entrypoint against the v17 database shape and observes schema-19 convergence plus integrity success; focused real-SQLite regressions cover the added rollback and lease-ordering behaviors.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: This repair covers an upgrade path that can otherwise leave agent databases below the schema needed for gateway readiness.
  • merge-risk: 🚨 availability: A failure in this migration path can keep an affected gateway unavailable until Doctor completes successfully.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 supplied exact-head terminal trace invokes the production migrateLegacyMediaPersistence entrypoint against the v17 database shape and observes schema-19 convergence plus integrity success; focused real-SQLite regressions cover the added rollback and lease-ordering behaviors.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied exact-head terminal trace invokes the production migrateLegacyMediaPersistence entrypoint against the v17 database shape and observes schema-19 convergence plus integrity success; focused real-SQLite regressions cover the added rollback and lease-ordering behaviors.

Evidence

What I checked:

Likely related people:

  • EthDing: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Omar: 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.

  • Let the exact-head required migration checks complete 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-31T16:34:27.073Z sha 3bebe3a9a2b1d0d809dc80afffd76542396b88b2 :: needs changes before merge. :: [P1] Renew the maintenance lease before the v17 preflight

@RileyJJY
RileyJJY force-pushed the sunlit/fix/issue-134163 branch from 3bebe3a to be71261 Compare September 1, 2026 00:38
@clawsweeper clawsweeper Bot added 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 1, 2026
@obviyus obviyus self-assigned this Sep 1, 2026
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: M and removed size: S labels Sep 1, 2026
@obviyus

obviyus commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus merged commit c893a1f into openclaw:main Sep 1, 2026
295 checks passed
@obviyus

obviyus commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Thanks @RileyJJY!

Proof: Current-main red proof showed a rejected schema-17 migration leaving route and index repairs behind. Exact-head sanitized Linux proof passed 34 owner, sibling, and Doctor process tests, and required CI completed green.

  • Bug: A later participant identity rejection left the earlier schema-17 prerequisite repair committed.
  • Fix: The schema owner now performs additive and canonical-index repair inside the same migration transaction.
Before After
Doctor warned and stayed at schema 17, but retained partial route and index writes. Doctor warns and stays at schema 17 with every prerequisite write rolled back.

Source: 7e8b26722634ae730b1a1c62ef09f5882a7f00a3

Landed: c893a1f8453191951bce75a8769fc5db8e775d68

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

commands Command implementations merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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: M 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.

2 participants