Skip to content

refactor: reuse canonical SQL for first-use database setup - #146296

Merged
steipete merged 2 commits into
mainfrom
codex/tenk-ddl
Sep 12, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/tenk-ddl

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #146293

What Problem This Solves

First-use database setup repeats table definitions already maintained in the canonical SQL files, leaving two places that must agree when those tables change. Several feature owners also repeat the same bounded SQL selection logic.

Why This Change Was Made

Use the existing SQLite schema utility to select canonical table regions, and replace six copied DDL bodies with those regions. Feature owners still decide when to install their tables and when an installation can be cached after commit. Index/trigger ranges, transaction boundaries, errors, and first-use scope remain unchanged.

User Impact

No intended user-visible behavior change. Existing databases, lazy feature activation, upgrades, and rollback keep their current schema and lifecycle contracts. This removes 172 net production code lines (173 physical lines), including the shared selector; tests and tooling are unchanged.

Evidence

  • 46 before/after differential cells: identical normalized executed SQL, operation/cache traces, and real SQLite schema results, including repeated calls inside and outside transactions. 34 cells are byte-identical; the six replaced literals differ only in whitespace or statement separators.
  • 197 focused tests passed across 12 files; two existing tests remain skipped. Coverage includes publication/setup, deletion/leases, schemas, Goals, transcript archives, and standing intents.
  • Fresh independent P2 review: no actionable findings.
  • Complete pinned changed-file gate passed, including production/test typechecks, lint, dead-export scans, native schema-version and database/import guards.
  • Initial CI caught four existing raw-SQL justifications displaced by multiline calls. Their comments now precede those same calls; the Kysely guard passes, emitted executable code is identical, and the correction has a fresh clean review. No guard or allowlist changed.
  • An independent QA catalog selector fix from fix(qa): select the renamed diagnostics browser test #146323 was consumed in a patch-identical rebase. All eight changed source files remain byte-identical, all 46 SQL/SQLite comparison cells passed again, and the corrected QA native suite passed 20/20. The latest exact-head CI is green.

@clawsweeper

clawsweeper Bot commented Sep 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 size: M maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete marked this pull request as ready for review September 12, 2026 18:30
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 12, 2026, 4:15 PM ET / 20:15 UTC (Revision 4).

ClawSweeper review

What this changes

The PR replaces duplicated database table definitions and SQL-selection logic with a shared helper that reads the canonical definitions while preserving feature-owned installation timing.

Warning

SQLite table change

This PR modifies persisted SQLite tables in src/infra/sqlite-schema-sql.ts, src/state/openclaw-agent-context-engine-turn-outbox-schema.ts, src/state/openclaw-agent-goal-operations-schema.ts, src/state/openclaw-agent-message-tool-outcome-schema.ts, and 4 more. 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.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains useful, review-clean work. The prior generic migration-proof blocker is resolved: source inspection supports the maintainer’s explanation that no material persistence change is introduced.

Priority: P3
Reviewed head: ace9fdc7a652980b1de871c182e6389280a86d2d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving consolidation with relevant reported validation and no actionable review findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor proof gate does not apply to this maintainer-authored refactor, and no material authority change triggers an exception. The captured body reports production-installer SQL, transaction/cache traces, and real-SQLite equivalence across 46 cells; those results were not independently rerun.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this maintainer-authored refactor, and no material authority change triggers an exception. The captured body reports production-installer SQL, transaction/cache traces, and real-SQLite equivalence across 46 cells; those results were not independently rerun.
Evidence reviewed 9 items Complete introduced change inspected: Inspected the complete merge-base-to-head diff and all eight affected modules. The selector preserves the existing start markers, inclusive or exclusive end boundaries, and supplied diagnostics; feature transaction and cache decisions remain in their existing owners.
Removed literals match canonical definitions: Compared all six removed table definitions with canonical SQL: deletion journal, database leases, setup completions, worker tool authorities, worker tool operations, and GitHub publication requests. Columns, constraints, defaults, foreign keys, and the publication index are preserved.
Storage checkpoint applicability: The storage policy distinguishes material changes to persisted representations or lifecycle semantics from routine maintenance of an approved schema. This patch changes neither the canonical schemas nor their existing installation, repair, transaction, or retention contracts.
Findings None None.
Security None None.

How this fits together

OpenClaw stores shared runtime state and per-agent data in SQLite. Feature-specific installers select the required table definitions and execute them when the owning feature first needs storage.

flowchart TD
  A[Feature first use] --> B[Feature schema installer]
  C[Canonical SQL definitions] --> D[Shared SQL selector]
  B --> D
  D --> E[Existing transaction boundary]
  E --> F[SQLite tables and indexes]
  E --> G[Existing committed-install cache]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source -173. Total -173 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 8 129 302 -173
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 129 302 -173

Review metrics

None.

Stored data model

Persistent data-model change detected: database schema: src/infra/sqlite-schema-sql.ts, database schema: src/state/openclaw-agent-context-engine-turn-outbox-schema.ts, database schema: src/state/openclaw-agent-goal-operations-schema.ts, database schema: src/state/openclaw-agent-message-tool-outcome-schema.ts, database schema: src/state/openclaw-agent-session-participants-schema.ts, database schema: src/state/openclaw-agent-session-transcript-archive-schema.ts, and 4 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #146293
Summary: This PR is the implementation candidate for the explicitly linked consolidation request.

Members:

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

Technical review

Best possible solution:

Keep canonical SQL as the sole definition source while existing feature owners retain installation, transaction, and cache responsibilities.

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

Not applicable: this is a refactor, and current-main source confirms the duplicated definitions and selection logic it addresses.

Is this the best way to solve the issue?

Yes. Reusing the existing SQLite utility removes competing definitions without moving lifecycle decisions or introducing another storage owner.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P3: This is bounded internal cleanup with no intended user-visible behavior or persisted-schema change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this maintainer-authored refactor, and no material authority change triggers an exception. The captured body reports production-installer SQL, transaction/cache traces, and real-SQLite equivalence across 46 cells; those results were not independently rerun.

Evidence

What I checked:

  • Complete introduced change inspected: Inspected the complete merge-base-to-head diff and all eight affected modules. The selector preserves the existing start markers, inclusive or exclusive end boundaries, and supplied diagnostics; feature transaction and cache decisions remain in their existing owners. (src/infra/sqlite-schema-sql.ts:4, ace9fdc7a652)
  • Removed literals match canonical definitions: Compared all six removed table definitions with canonical SQL: deletion journal, database leases, setup completions, worker tool authorities, worker tool operations, and GitHub publication requests. Columns, constraints, defaults, foreign keys, and the publication index are preserved. (src/state/openclaw-state-db-schema-additive.ts:116, ace9fdc7a652)
  • Storage checkpoint applicability: The storage policy distinguishes material changes to persisted representations or lifecycle semantics from routine maintenance of an approved schema. This patch changes neither the canonical schemas nor their existing installation, repair, transaction, or retention contracts. Public docs: docs/reference/database-schemas/storage-changes.md. (docs/reference/database-schemas/storage-changes.md, ace9fdc7a652)
  • Prior blocker addressed in discussion: The captured maintainer response explicitly rejects the generic compatibility checkbox for this behavior-preserving change: refactor: reuse canonical SQL for first-use database setup #146296 (comment). The captured body reports 46 before/after SQL and real-SQLite comparisons, repeated-call and transaction checks, and 197 focused passing tests. These are author-reported results; this review did not rerun them. (ace9fdc7a652)
  • Existing lifecycle coverage: Read the existing Goal, outbox, archive, and runtime-schema tests. They cover absent lazy tables, repeated installation, unchanged version metadata, populated-table reopening, and rejection of schema drift. No test changes are introduced. (src/state/openclaw-agent-goal-operations-schema.test.ts:27, ace9fdc7a652)
  • Still necessary on fetched main: Fetched main still contains the copied deletion-journal, lease, and setup-completion definitions, and its SQLite utility lacks the new selector. The latest supplied release, v2026.9.4, also lacks that selector. No merged replacement for this consolidation is established. (src/state/openclaw-state-db-schema-additive.ts:156, ad08bd71ff1b)

Likely related people:

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

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 (3 earlier review cycles)
  • reviewed 2026-09-12T18:35:47.860Z sha aab69a93741f84c28a2acd8a34ba12b6ffff4d77 :: blocked before merge. :: none
  • reviewed 2026-09-12T18:49:56.455Z sha 145a65307216c47fcb41440dd69e2e1a53ba4e21 :: blocked before merge. :: none
  • reviewed 2026-09-12T19:28:17.916Z sha ace9fdc :: blocked before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer disposition: the generated SQLite compatibility checkbox does not apply to this change. The technical review itself confirms that all six removed DDL literals match the canonical definitions and that there is no material persistence change. Tables, indexes, constraints, first-use installation, transaction boundaries, caches, and repair behavior remain unchanged.

The PR body now records the repeated-call/transaction and real SQLite comparison proof, the 197 focused tests, and the fresh 46-cell replay plus 20 QA tests after a byte-identical rebase. The independent QA selector repair in #146323 receives no credit in this PR. No schema migration, updater change, guard weakening, or compatibility exception is introduced.

@steipete
steipete merged commit 1e103e9 into main Sep 12, 2026
187 checks passed
@steipete
steipete deleted the codex/tenk-ddl branch September 12, 2026 20:18
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 13, 2026
…146296)

* refactor: reuse canonical SQL for first-use database setup

* fix: keep canonical DDL annotations attached to calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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.

Consolidate canonical DDL ownership for first-use database setup

1 participant