Skip to content

build: add shrink-only SQLite dialect ratchet - #168382

Merged
steipete merged 3 commits into
mainfrom
pgprep/dialect-ratchet
Oct 10, 2026
Merged

steipete merged 3 commits into
mainfrom
pgprep/dialect-ratchet

Conversation

@steipete

@steipete steipete commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Keep SQLite-specific SQL debt from growing while preparing OpenClaw for a possible PostgreSQL backend, without treating error messages, HTTP headers, or CLI help as SQL. The corrected executed-SQL census measured approximately 1,008 warmed statements per turn: 59.4% portable, 6.8% mechanical, 7.2% design, and 26.7% engine maintenance, including 221.6 freshness probes per turn.

User Impact

No runtime, schema, configuration, driver, or dependency change. Developers get a shrink-only check that compares each construct group's total with the Git base and reports growth locations. Ordinary prose such as "does not match", "a -> b", "Pragma", "failed to attach", and "use glob patterns" does not count. This is PostgreSQL-readiness preparation only.

Why This Change Was Made

The guard applies identical lexical rules at base and head, scanning only differing production .ts, .mts, and .sql files under src/, extensions/, and packages/, with the database-worker inventory's test and fixture exclusions. Unchanged files cancel out; moves and reductions are allowed. Untracked files are included, --staged reads the index, and --full-tree reports whole-tree totals. The central string-set helpers retain their owner annotation within mechanical debt.

Examined text is restricted to:

  • Whole .sql files minus comments.
  • All static parts of templates whose identifier or property-access tag ends in sql, case-insensitively: for example sql, kyselySql, and db.sql.
  • Strings and untagged templates starting after whitespace and ( with an uppercase keyword from SELECT, INSERT, UPDATE, DELETE, REPLACE, WITH, CREATE, DROP, ALTER, PRAGMA, BEGIN, COMMIT, ROLLBACK, SAVEPOINT, RELEASE, VACUUM, ATTACH, DETACH, ANALYZE, REINDEX, or EXPLAIN; all static template parts are then examined.
  • The five conflict methods (orReplace, orIgnore, orAbort, orFail, orRollback) as code tokens.

Within that text, the existing case-insensitive word-boundary construct regexes are unchanged: SQL double-quoted text never matches, functions require (, and data_version/schema_version/user_version require PRAGMA <name> or pragma_<name>(. Substitutions are never examined. Nonmatching prose, fragments, lowercase untagged statements, and assembled SQL are intentionally ignored or under-counted. A keyword-only SQL classifier token such as "SAVEPOINT" still satisfies this lexical gate. There is no type checking, symbol/import resolution, or SQL token-role analysis.

The implementation is 376 lines across three new production scripts (94 + 192 + 90), with a 174-line test file. The shared TypeScript parser is unchanged. The guard is wired into full/changed checks and CI.

Evidence

  • The new prose/fragment regression failed with the previous scanner and passed after the filter change.
  • pnpm test test/scripts/check-database-dialect-ratchet.test.ts --maxWorkers=1: 2 tests passed, 1.116 s execution, 2.18 s Vitest duration, 7.07 s command wall time. Coverage includes the specified prose exclusions, SQL tags and statement prefixes, static template tails, skipped substitutions, deterministic output, real Git base/head selection, growth/shrinkage, moves, deletion, untracked files, and staged content.
  • pnpm check:database-dialect-ratchet --base 03fab71bbad0: passed in 2.66 s wall time, with zero differing production files. This is above the approximate 2 s target on the loaded local host; user CPU time was 0.57 s.
  • Same command with --full-tree: passed in 53.02 s wall time. Both base and head report 95 mechanical, 366 design, 391 engine-maintenance, with 2 owner occurrences included in mechanical.
  • pnpm check:changed --base 03fab71bbad05c6d73c48c2dff83db07f18263ad: passed on the first Testbox attempt in 468.39 s command wall time, including typechecks, export scans, formatting, and scripts/test lint with zero warnings or errors.
  • Inspected 139 reproducible pseudorandom samples, up to eight unique file:line locations per remaining construct (seed 168382). No English prose appeared in the samples; the retained SQLite SAVEPOINT classifier token is noted above. These are lexical source occurrences, separate from the weighted execution census.
  • One fresh independent Codex autoreview round against the coordinator-owned SQL-looking-text notes: no actionable P0–P2 findings. The notes file was not modified.
  • git diff --check: passed. Hosted PR CI execution time for the test is not yet available; local cost is recorded above.
Per-construct full-tree counts before and after the SQL-looking-text gate
Construct Before After
insert-conflict 26 26
json-string-set 25 25
transaction-mode 34 33
last-insert-rowid 0 0
without-rowid 11 10
randomblob 1 1
fts5 937 8
sqlite-vec 3 2
json-projection 637 223
temp-schema 14 14
rowid 112 70
custom-function 13 5
glob 65 18
indexed-by 8 7
attach 155 2
collate-nocase 3 3
typeof 16 9
printf 5 5
pragma 267 251
data-version 5 3
user-version 23 21
schema-version 10 10
wal-checkpoint 2 2
integrity-check 13 2
vacuum 8 4
sqlite-catalog 109 98

The production source tree is identical for both tallies; the reduction comes from restricting examined text. Total source occurrences: 2,502 → 852.

Landing validation

Rebased after generator PR #168219 onto main 21f5711b9c66, producing 72da62e442daa2c637e99d84395957fa1970a33f. The only conflict was the shared insertion point in storage-changes.md: both paragraphs remain verbatim, generator first and ratchet second. Range-diff reports documentation and adjacent package context shifts; removing the exact original additions from every rebased file yields the new base byte-for-byte. All four new script/test blobs match the reviewed head, so the coordinator's independent Codex review carries over.

git diff --check, the one-file MDX check, and one-file formatting passed. pnpm test test/scripts/check-database-dialect-ratchet.test.ts --maxWorkers=1 passed all 3 tests: 3.551 s test execution / 12.31 s command wall.

PR CI run 38078511415, attempt 1, remains failed on three independently qualified baseline failures:

  • checks-ui (3/3): the sidebar main-chat metadata test cannot find .session-owner-chip; the same case and assertion fail in main run 38076523822.
  • QA Smoke CI (profile 4/4): subagent-completion-direct-fallback fails its private runtime-context/user-turn projection check; the same scenario fails in that main run.
  • checks-node-changed-extensions-bundle-22-1: the unchanged memory-core shard reaches its five-minute no-output limit. Independent main-baseline Testbox proof reproduces repeated hook timeouts in the same provider-none maintenance tests. The lease was stopped after those failures; remaining baseline coverage is unrun. Intervening embedding-cap changes do not execute in the affected provider-none cases.

Runtime, UI, QA and extension inputs are unchanged between the tested main parent and PR merge. These failures are submitted for the native inherited-failure exception; CI is not represented as green. Independent security-fast passed and no jobs were cancelled. No ratchet CI rerun was requested.

@clawsweeper

clawsweeper Bot commented Oct 10, 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 scripts Repository scripts size: L labels Oct 10, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR adds a Git-based check that rejects growth in three groups of SQLite-specific SQL constructs.

Example: A developer adds SELECT value FROM json_each(?) while retaining one INSERT OR IGNORE statement.

  • Before: Repository checks impose no dialect-count limit.
  • After: The mechanical count grows from 1 to 2, and the check rejects the change with source locations.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, focused tooling with supplied CLI evidence, meaningful boundary coverage, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Supplied CLI evidence exercises the actual dialect checker against repository sources in changed-file and full-tree modes; real-Git integration tests separately cover growth rejection and snapshot selection.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Maintenance · Worth it: Yes · Fix scope: Complete
User problem: Developers lack an enforced limit on growing SQLite-specific SQL debt during backend preparation.
Reason: Maintainer-authored direction adds a distinct, bounded guard without changing runtime storage, schemas, or dependencies.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR provides useful portability enforcement absent from current main, with no actionable correctness or security findings.

Priority: P3
Reviewed head: 72da62e442daa2c637e99d84395957fa1970a33f

Before merge

None.

Findings

None.

Agent review details

How this fits together

Local checks and CI supply a Git base; the scanner compares production source snapshots and returns construct counts, growth diagnostics, and an exit status.

flowchart TD
  A[Local checks and CI] --> B[Dialect ratchet]
  B --> C[Git source snapshots]
  C --> D[Shared TypeScript parser]
  D --> E[Lexical construct inventory]
  E --> F[Independent group comparisons]
  F --> G[Diagnostics and exit status]
Loading

Technical review

Best possible solution:

Retain the focused lexical guard, shared snapshot machinery, and documented limits, using the native inherited-failure workflow for landing.

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

This is new developer tooling; supplied CLI results and real-Git integration coverage exercise its intended contract, and no target code was executed during this review.

Is this the best way to solve the issue?

Shared Git-base selection, identical lexical rules at both revisions, and independent group totals provide proportionate enforcement while allowing moves and shrinkage.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Local and CI ratchet integration keeps the original intent (3e0672a: Reject total main-thread SQLite call growth while permitting moves and reductions.)
  • Captured fork-base handling keeps the original intent (23ebaf9: Bind checks to the candidate's captured fork instead of an independently selected moving base.)
  • CI preflight placement keeps the original intent (bc78b4d: Reject ratchet failures before selected Node test fanout.)
  • Database preparation documentation keeps the original intent (4575155: Prepare PostgreSQL schema projections while retaining canonical SQLite ownership and runtime support.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 3e0672a adds scripts/check.mts:14 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3e0672a03521; files: scripts/check.mts)

PR surface

Tests +190, Docs +4, Config +3, Other +396. Total +593 across 9 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 190 0 +190
Docs 1 4 0 +4
Config 2 3 0 +3
Generated 0 0 0 0
Other 5 396 0 +396
Total 9 593 0 +593

Review metrics

Metric Value Why it matters
New CLI mode 1: --full-tree Allows an explicit whole-tree census while ordinary enforcement scans only differing production files.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: Developer tooling and portability preparation introduce no runtime or persisted-state changes.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-10T10:17:44.145Z sha 50e4d12 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T11:00:51.439Z sha c5870e5 :: needs changes before merge. :: none
  • reviewed 2026-10-10T11:43:04.316Z sha b453af2 :: needs changes before merge. :: none
  • reviewed 2026-10-10T19:12:51.087Z sha 72da62e :: needs maintainer review before merge. :: none

Reviewed October 10, 2026, 3:33 PM ET / 19:33 UTC (Revision 5).

@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 10, 2026
@steipete
steipete force-pushed the pgprep/dialect-ratchet branch from b453af2 to 72da62e Compare October 10, 2026 19:04
@steipete
steipete marked this pull request as ready for review October 10, 2026 19:06
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@steipete
steipete merged commit a1c1610 into main Oct 10, 2026
312 of 317 checks passed
@steipete
steipete deleted the pgprep/dialect-ratchet branch October 10, 2026 19:35
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
* build: add shrink-only SQLite dialect ratchet

* fix: restrict dialect ratchet to SQL-looking text

* fix: preserve SQL quote state across template spans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L 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.

1 participant