Skip to content

fix(sqlite): safely discard retired commitments state - #130629

Merged
vincentkoc merged 2 commits into
mainfrom
fix/sqlite-commitments-retirement
Aug 27, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
fix/sqlite-commitments-retirement

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Fixes #129547

Audit: https://gist.github.com/vincentkoc/10826f918dde7e23020cf2f390af95d3

What Problem This Solves

Fixes an upgrade gap where retired durable commitments state was deleted without
clear operator reporting, while the old commitments/commitments.json store had
no bounded cleanup owner. The schema detector also advertised the schema-7
retirement for versions where its executor would not run.

Why This Change Was Made

This implements the accepted destructive-retirement contract:

  • recognized schema-6 commitment rows, table, and indexes are discarded by the
    existing schema-7 migration;
  • explicit openclaw doctor --fix validates and discards only the exact
    version-1 commitments JSON envelope;
  • no rows are imported, archived, exported, or preserved;
  • malformed, changed, linked, foreign, or dependency-owned state remains
    untouched and fails closed;
  • runtime retirement labels are emitted only after the SQLite transaction
    commits.

There is no schema-version bump, replacement table, query-plan change, or new
index.

User Impact

Operators get an explicit, deterministic retirement outcome. Recovery remains a
verified pre-upgrade backup only; downgrade recreates an empty legacy schema.
Runtime continues to ignore the retired JSON file unless Doctor is explicitly
run.

Evidence

  • Exact v2026.7.1-2 fixture now contains one representative durable commitment
    row and the three shipped indexes before migration.
  • Fixture migration verifies row/table/index deletion, integrity,
    foreign-key checks, reopen, and idempotency.
  • Post-delete receipt recovery regression failed against the pre-fix
    implementation and passes on this head.
  • Rollback logging regression failed when labels were emitted inside the
    transaction and passes when labels are emitted after commit.
  • node scripts/run-vitest.mjs src/infra/state-migrations.commitments.test.ts src/infra/state-migrations.test.ts
    • 108 passed
  • node scripts/run-vitest.mjs src/state/openclaw-state-db.test.ts
    • 161 passed, 2 skipped
  • Core typecheck passed.
  • Database-first legacy-store guard, focused Oxlint, changed-file formatting,
    docs formatting, and git diff --check passed.
  • The broader changed-file gate passed through core and core-test typechecking.
    Its extension typecheck is blocked by missing existing IMAP workspace
    dependencies (imapflow, mailauth, mailparser) in this checkout. The
    dead-export lane is independently blocked because current main omits the
    tracked sparse UI config inputs it requires.
  • Index performance: not applicable. No index DDL or indexed query changed; the
    fixture only proves deletion of the retired shipped indexes.

Review Notes

Root cause: the retirement contract was split across a moving schema detector,
a schema-7 executor, silent runtime result handling, a zero-row release fixture,
and an ownerless legacy JSON source.

Architectural owner: shared-state schema retirement plus Doctor-only legacy
state migration.

Best-fix verdict: this is the canonical owner-boundary fix. Preserving rows,
adding an archive/export path, or adding runtime JSON fallback reads would
contradict the accepted contract and database-first policy.

Production LOC: +356/-17 (net +339). Tests/support: +617/-64 plus the updated
SQLite fixture. Docs: +10/-6. Production growth is the bounded Doctor migration
owner, receipt recovery, and fail-closed source validation; the schema
retirement itself remains small and shared.

Codex contract check: ../codex/codex-rs/state/src/migrations.rs:13-27 and
../codex/codex-rs/state/src/sqlite.rs:254 were inspected. This change does not
touch Codex state or protocol behavior.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: voice-call Channel integration: voice-call size: XL labels Aug 27, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 27, 2026 02:58
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Aug 27, 2026
@vincentkoc vincentkoc self-assigned this Aug 27, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please evaluate the accepted destructive-retirement contract from
#129547 (comment) and
#129547 (comment).

Two independent local reviews found and resolved:

  • recovery when filesystem deletion succeeds but receipt finalization fails;
  • false runtime success logging before the schema transaction commits.

No schema version or index/query-plan changes are included.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member Author

ClawSweeper rank-up moves addressed on exact head c90cc4dc06375d26f2a84bce48619a46d2d493d7:

No index DDL or indexed query plan changes are in this PR; the stable fixture only verifies removal of the retired shipped indexes, so a before/after index performance benchmark is not applicable.

@vincentkoc
vincentkoc merged commit d62cb8a into main Aug 27, 2026
271 checks passed
@vincentkoc
vincentkoc deleted the fix/sqlite-commitments-retirement branch August 27, 2026 03:19
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
* fix(sqlite): finalize commitments retirement

* fix(doctor): discard retired commitments json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: voice-call Channel integration: voice-call docs Improvements or additions to documentation maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQLite migration: decide retention for retired commitments rows

1 participant