Skip to content

refactor(state): inline canonical database schemas at build - #117433

Merged
steipete merged 1 commit into
mainfrom
codex/state-schema-inline
Aug 1, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/state-schema-inline

Conversation

@steipete

@steipete steipete commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The committed runtime schema modules duplicate 2,835 lines from the canonical SQLite .sql files. That creates a large generated diff surface and a second representation that must stay byte-aligned with the actual schema owner.

Why This Change Was Made

Keep the committed .sql files as the sole canonical schema source. Direct source runs read those files through Node's native builtin handle, so unrelated filesystem mocks cannot replace the input. The production tsdown graph replaces the two tiny loader modules with byte-exact inlined constants. Packaged runtime behavior remains asset-free and performs no schema-file reads. The build cache now tracks .sql inputs, and Kysely generation remains responsible only for generated database types.

No SQLite schema, schema version, migration, config, protocol, or public API changes.

User Impact

No user-visible behavior changes. Maintainers remove 2,744 net lines and one entire class of committed generated duplication while preserving source, packaged, recovery, and install behavior.

Evidence

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts commands Command implementations size: XL maintainer Maintainer-authored PR labels Aug 1, 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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 11:30 AM ET / 15:30 UTC.

ClawSweeper review

What this changes

The PR removes committed generated SQLite schema-string modules, makes source runs read the canonical SQL files, and inlines those same bytes into the unified packaged runtime build.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

This refactor appears technically sound: it replaces duplicated generated schema strings with canonical SQL loaders for source runs and build-time inlining for packaged runtime. It should remain open for explicit maintainer review because the protected maintainer label applies and packaged database bootstrap now depends on every released schema consumer remaining inside the unified tsdown build graph.

Priority: P3
Reviewed head: b2ec661afe4e1809e4f2e8de3d82f8dcd4baa52c
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong artifact and runtime proof supports a focused cleanup with no discrete correctness finding; the remaining decision is the durable ownership of the unified packaging invariant.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The PR body provides exact-head CI, built-artifact, Node 22/24, npm-install, Docker, and SQLite integrity evidence for the after-fix source and packaged paths; no chat-surface proof is relevant.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The PR body provides exact-head CI, built-artifact, Node 22/24, npm-install, Docker, and SQLite integrity evidence for the after-fix source and packaged paths; no chat-surface proof is relevant.
Evidence reviewed 8 items Current main behavior: Current main imports generated runtime schema strings into the shared state database lifecycle, so the requested cleanup is not already implemented on current main.
Canonical source-run loader: The PR loader reads the adjacent canonical SQL through Node’s native builtin filesystem module, while the package build replaces this module before runtime.
Packaged-runtime boundary: The tsdown plugin matches only the two schema-loader modules, watches their canonical SQL inputs, and emits JSON-escaped schema constants; it is installed only on the unified runtime graph.
Findings None None.
Security None None.

How this fits together

OpenClaw’s state layer initializes shared and per-agent SQLite databases from schema SQL. The change moves the source of truth to the canonical .sql files while tsdown injects their contents into distributed runtime bundles so packaged installs do not require schema assets.

flowchart LR
  A[Canonical SQLite schema files] --> B[Source schema loaders]
  B --> C[Shared and agent database setup]
  A --> D[Unified build-time inlining]
  D --> E[Packaged runtime bundle]
  C --> F[SQLite databases]
  E --> F
Loading

Decision needed

Question Recommendation
Should the maintainer accept the invariant that every packaged database consumer of these schema loaders remains inside the unified tsdown graph? Confirm the unified-graph invariant: Accept the current architecture and merge with the expectation that any future packaged database entrypoint receives the same inlining treatment.

Why: The patch and tests establish the invariant for today’s runtime graph, but only an owner can decide whether that packaging boundary is the durable contract for future database entrypoints.

Before merge

  • Resolve merge risk (P1) - Packaged database bootstrap will no longer have SQL assets to fall back to; a future released database entrypoint outside the unified tsdown graph must receive equivalent schema inlining before it can safely import these loaders.
  • Complete next step (P2) - The protected maintainer label and the intentional package-graph availability invariant require owner confirmation; there is no narrow mechanical defect for an automated repair lane.
Agent review details

Security

None.

PR surface

Source +14, Tests +62, Docs 0, Generated -2835, Other +15. Total -2744 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 12 24 10 +14
Tests 8 72 10 +62
Docs 1 6 6 0
Config 0 0 0 0
Generated 2 0 2835 -2835
Other 3 39 24 +15
Total 26 141 2885 -2744

Review metrics

None.

Stored data model

Persistent data-model change detected: database schema: docs/refactor/database-first.md, database schema: src/state/openclaw-agent-schema.generated.ts, database schema: src/state/openclaw-state-schema.generated.ts, migration/backfill/repair: src/commands/doctor-session-sqlite-recover-report.ts, migration/backfill/repair: src/commands/doctor-state-sqlite-compact.test.ts, persistent cache schema: test/scripts/build-all.test.ts, and 19 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Confirm package graph ownership before merge (recommended)
    Merge after the state/build owner confirms that released database entrypoints remain in the unified graph or will add equivalent inlining when introduced.
  2. Pause for a broader packaging contract
    Hold the refactor if maintainers want out-of-graph database entrypoints to be supported without an explicit inline-schema integration.

Technical review

Best possible solution:

Keep the canonical SQL files as the sole schema representation, retain the unified-build inlining and cache coverage, and make any future packaged database entrypoint join that graph or explicitly receive the same schema-inlining treatment.

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

Not applicable: this PR refactors build and state-schema representation rather than repairing a reported user-facing defect; its relevant behavior is covered by source/build and packaged-artifact proof.

Is this the best way to solve the issue?

Yes, with maintainer confirmation of the package-graph invariant: replacing duplicated generated runtime strings with canonical SQL plus build-time inlining is the narrower maintainable solution and preserves asset-free packaged startup.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7bcbe743bd42.

Labels

Label justifications:

  • P3: This is an internal duplication-removal refactor with no claimed user-visible behavior or schema change.
  • merge-risk: 🚨 availability: A packaged database entrypoint that bypasses the unified build graph could lack an inlined schema and fail during database bootstrap.
  • 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 (logs): The PR body provides exact-head CI, built-artifact, Node 22/24, npm-install, Docker, and SQLite integrity evidence for the after-fix source and packaged paths; no chat-surface proof is relevant.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides exact-head CI, built-artifact, Node 22/24, npm-install, Docker, and SQLite integrity evidence for the after-fix source and packaged paths; no chat-surface proof is relevant.

Evidence

What I checked:

  • Current main behavior: Current main imports generated runtime schema strings into the shared state database lifecycle, so the requested cleanup is not already implemented on current main. (src/state/openclaw-state-db.ts:77, 7bcbe743bd42)
  • Canonical source-run loader: The PR loader reads the adjacent canonical SQL through Node’s native builtin filesystem module, while the package build replaces this module before runtime. (src/state/openclaw-state-schema.ts:5, b2ec661afe4e)
  • Packaged-runtime boundary: The tsdown plugin matches only the two schema-loader modules, watches their canonical SQL inputs, and emits JSON-escaped schema constants; it is installed only on the unified runtime graph. (tsdown.config.ts:65, b2ec661afe4e)
  • Focused regression coverage: The new config tests compare emitted literals with the canonical SQL, verify watch registration, and assert that exactly one inline plugin is attached to the unified graph. (src/infra/tsdown-config.test.ts:96, b2ec661afe4e)
  • Build-cache coverage: The unified build cache begins tracking .sql source inputs, avoiding a stale bundle when a canonical schema changes. (scripts/build-all.mjs:26, b2ec661afe4e)
  • Dependency contract: The available Node 24 runtime exposes process.getBuiltinModule and returns a filesystem builtin with readFileSync; installed Node type declarations define the same API. (src/state/openclaw-state-schema.ts:6, b2ec661afe4e)

Likely related people:

  • steipete: Current-main blame attributes the schema import being replaced to Peter Steinberger, and the same person authored the focused refactor. (role: recent state-area contributor; confidence: high; commits: d585c0c1ec49, b2ec661afe4e; files: src/state/openclaw-state-db.ts, src/state/openclaw-state-schema.ts, src/infra/tsdown-config.test.ts)

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 (5 earlier review cycles)
  • reviewed 2026-08-01T14:01:55.092Z sha 28d7b30ea4659550c75415698bed94271a3a5d65 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T14:22:35.715Z sha 73f4151 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T14:35:02.033Z sha 73f4151 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T15:10:13.369Z sha b2ec661 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T15:20:06.552Z sha b2ec661 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/state-schema-inline branch from 28d7b30 to 73f4151 Compare August 1, 2026 14:16
@steipete
steipete marked this pull request as ready for review August 1, 2026 14:29
@steipete
steipete force-pushed the codex/state-schema-inline branch from 73f4151 to b2ec661 Compare August 1, 2026 15:02
@steipete
steipete merged commit e7950d9 into main Aug 1, 2026
138 checks passed
@steipete
steipete deleted the codex/state-schema-inline branch August 1, 2026 15:39
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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: XL 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