Skip to content

build: generate Kysely declarations at build time - #162288

Merged
steipete merged 3 commits into
mainfrom
deslop/l251-gen-kysely-build
Oct 1, 2026
Merged

steipete merged 3 commits into
mainfrom
deslop/l251-gen-kysely-build

Conversation

@steipete

@steipete steipete commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Maintainer-requested build cleanup removes 2,563 lines of committed Kysely declarations that duplicate the maintained SQLite schemas.

User Impact

Net removal: 2,504 production/tooling lines, excluding docs and tests. No runtime, SQL schema, stored data, Doctor, or protocol change. Normal installation, builds, typechecks, and tests prepare the declarations automatically; no additional developer command is required. Source-less npm installs and Docker dependency stages retain their existing behavior.

Why This Change Was Made

The existing generator now writes byte-identical, type-only .ts files to ignored .artifacts/kysely/. Unbundled SDK compilation emits their declarations alongside its other outputs, while bundled SDK output inlines them. Two one-line, hand-written type exports preserve existing consumers and normal TypeScript/declaration-bundler resolution. A content fingerprint covers the generator, both schemas, and emitted bytes; unchanged preparation skips SQLite and all writes. Missing or corrupt outputs regenerate; each changed file is replaced atomically.

Install preparation also supports source archives without Git metadata. Build, compiler, test, and SDK-declaration entrypoints prepare artifacts even after --ignore-scripts; SDK generation occurs before compiler input snapshots. The schema check retains regeneration from authoritative SQL, plus an independent SQL fixture covering type mapping, nullability, defaults, composite primary keys, hidden columns, deterministic ordering, and cache invalidation.

This is generated-source relocation, not runtime simplification. Native apps do not consume these TypeScript declarations.

Evidence

Initial measurement and design were completed before removing the committed files. Timings below include the integrated implementation, measured on macOS with Node 26.10.0 under concurrent host load:

Measurement Wall time
Original standalone generator, cold 1.64 s
Original standalone generator, repeated 1.30–1.65 s
Final standalone process, cold 1.09 s
Final standalone process, warm 0.49–0.60 s
Final generator in existing Node process, cold 143.70 ms
Final generator in existing Node process, warm 3.00–7.35 ms

The in-process measurements isolate the added work in existing build/check/test entrypoints. Standalone timings include Node startup and loaded-host scheduling. Final generated outputs exactly match all 65,141 bytes of the previous committed declarations (1,927 + 636 lines). Git confirms both output paths are ignored.

Independent Codex review: no actionable P0–P2 findings, including the final type-only source layout and the test-root correction. The first complete focused run passed 275 tests across 14 files (7 platform skips) in 76.64 s wall. Both cycle checks reported 0 (22.41 s Madge, 9.19 s runtime graph).

The unbundled SDK consumer negative control failed for the intended reason with declaration-only inputs: a SQL text value silently became any, and the compiler accepted a number assignment. The corrected type-only source layout passes that regression. The next changed-file run identified two obsolete explicit test-root paths; this PR updates them to the source entry points without changing shard selection.

Blacksmith Testbox proof on Node 24.19.0:

  • node scripts/check-changed.mjs: passed all selected typechecks, lint, and guards (2,069.86 s).
  • Fresh worktree with no generated files: pnpm install --frozen-lockfile passed (1.79 s) and created both projections automatically; pnpm build passed (300.31 s); pnpm tsgo passed (37.35 s); focused generator tests passed (1.73 s). Bundled declarations had no from imports back into .artifacts/kysely/.
  • New/changed test cost with --maxWorkers=1: generator file 1.78 s wall / 9 ms test execution; existing unbundled declaration suite 23.24 s wall / 21.67 s tests, including the new consumer regression at 875 ms. Real native compiler emission and an isolated consumer are required to catch the lost-declaration/any failure.
  • Final delta: pnpm db:kysely:check passed (1.51 s wall), targeted generator/test lint passed, and both cycle checks again reported 0. The final tested tree matches the committed tree; this delta only makes the rendering helper private and exercises the same generation contract through its production preparation entrypoint.

The successful full build also printed largest JS gzip: 217.2 KiB exceeds 215.0 KiB from the UI reporter. This change does not touch UI source or its budget. Prior-head hosted CI run 36808415247 failed only checks-windows-node-test-3: src/infra/package-update-swap.windows.test.ts:72, “preserves the package after persistent EPERM on linux (retries=false)”. It received packageRollbackVerified: false and helper-unavailable / “native retained-directory staging is unavailable”, instead of verified rollback and EPERM.

The same test and error independently fail on main run 36807764485, Windows shard 3, at 96f6d042f0de19cc17a28784076d3978eb1b90ee. The failing test, fixture, and package-swap owner are outside this diff; their native staging path does not consume the generated Kysely types. This qualified the previous head for the maintainer-authorized pre-existing-failure exception. The final corrected head completed CI successfully, so no inherited-failure exception is needed. Main CI repair remains with its coordinator.

On that earlier head, build artifacts, TypeScript contracts, security-fast, security-sensitive review, and dependency review passed. Fail-fast cancelled remaining matrix jobs; those earlier jobs remain unrun, not passing. The Windows shard itself recorded 654 passing tests, one failing test, and 81 skips.

Final head 9e82f326f6da9e1f1edd67da630885404dadef19: the enforced openclaw/ci-gate is successful, with no unfinished or failed checks; final CI run 36815023102. Build artifacts, TypeScript contracts, security-fast, and all Security High checks passed.

Late review found that the trusted PR-tooling archive omitted the generator newly imported by test preparation. Added scripts/generate-kysely-types.mts to the existing archive inventory. On Blacksmith Testbox tbx_01m3tt5gzajefeegg2mb0nne6h, removing this entry made both existing inventory/isolated-dependency tests fail with the missing generator; restoring it passed all 16 archive-closure tests and 3 generator tests (18.27 s wall). Both cycle checks again reported 0. Independent Codex review of this correction found no actionable P0–P2 findings. The lease was stopped after proof.

Conflict resolution preserves main's added cron_run_receipts.delivery_attempt_state SQL column and schema version 20. The rebased projections match all 65,141 bytes of main's declarations, including that new field. Generation contracts, the unbundled SDK consumer, and both zero-cycle checks passed again on the rebased head.

The automated data-model compatibility flag is triggered by deleting a generated TypeScript declaration. Both authoritative SQL schemas and the schema version are unchanged relative to the PR base; there is no stored-data or migration change in this PR. Existing build/typecheck evidence is retained for the unchanged implementation, with the affected schema projection and SDK consumer revalidated after integration.

Generation-lane coverage
Baseline lines Production projection Coverage
1,927 src/state/openclaw-state-db.generated.d.ts READ entirely; no handwritten augmentations. SQL-derived projection moved to ignored preparation output.
636 src/state/openclaw-agent-db.generated.d.ts READ entirely; includes SQLite FTS shadow-table types. SQL-derived projection moved to ignored preparation output.

The 135-line baseline generator remains the owner. Both SQL schema sources are unchanged. Integration edits are limited to existing lifecycle, compiler, test, declaration, API-diff, and package-boundary entrypoints; the shared test-shard configuration changes only the two obsolete explicit file paths. No shard selection or CI planner/workflow changes. The only PR-tooling change is one required archive inventory entry; wrapper behavior is unchanged.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: XL labels Oct 1, 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: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 1, 2026, 12:31 AM ET / 04:31 UTC (Revision 5).

ClawSweeper review

What this changes

Generate SQLite-derived TypeScript types automatically during installation and development workflows instead of committing large declaration files, while preserving existing imports and SDK consumers.

Merge readiness

⛔ Blocked before merge - 1 item remains

The prior archive-inventory blocker is resolved, and no new actionable defect was found. Current main still commits the declarations, so this cleanup remains useful.

Priority: P3
Reviewed head: 9e82f326f6da9e1f1edd67da630885404dadef19

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused source relocation, meaningful consumer coverage, detailed production build evidence, and resolution of the prior finding support strong review confidence.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied Node 24.19.0 Testbox observations exercise the changed preparation owner through fresh installation, full build, and typecheck, showing generated projections and self-contained bundled declarations. Native consumer and archive negative controls supplement that proof. SQL schemas and stored-data contracts are unchanged.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The supplied Node 24.19.0 Testbox observations exercise the changed preparation owner through fresh installation, full build, and typecheck, showing generated projections and self-contained bundled declarations. Native consumer and archive negative controls supplement that proof. SQL schemas and stored-data contracts are unchanged.
Evidence reviewed 8 items Pinned introduced change: Reviewed the merge-base-to-head delta rather than endpoint drift. The change relocates generated types and integrates preparation into existing tooling; neither authoritative SQL schema changes.
Prior finding resolved: The only change since the previously reviewed head adds the generator to the trusted wrapper inventory. Its direct-run dependency is already listed. The captured PR body reports that removing the entry fails the existing closure checks and restoring it passes all 16 archive-closure tests plus three generator tests.
Compiler preparation and consumer contract: Declaration preparation precedes compiler input snapshots. The added isolated SDK consumer uses real native declaration emission and requires a string-to-number assignment to fail, protecting against generated types becoming any.
Findings None None.
Security None None.

How this fits together

OpenClaw’s SQL schemas feed a generator that supplies database types to its TypeScript code and plugin SDK builds. Installation, build, compiler, and test preparation now refresh those types before consumers load them.

flowchart TD
  A[SQL schemas] --> B[Type preparation]
  C[Install build and test entrypoints] --> B
  B --> D{Inputs and outputs unchanged?}
  D -->|Yes| E[Reuse generated types]
  D -->|No| F[Regenerate type files]
  E --> G[TypeScript and SDK compilation]
  F --> G
Loading

Before merge

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

Security

None.

PR surface

Tests +152, Docs +6, Config 0, Generated -2561, Other +57. Total -2346 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 6 155 3 +152
Docs 1 6 0 +6
Config 1 2 2 0
Generated 4 2 2563 -2561
Other 9 87 30 +57
Total 21 252 2598 -2346

Review metrics

None.

Stored data model

Persistent data-model change detected: database schema: src/state/openclaw-state-db.generated.d.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep SQL as the authoritative schema source and refresh its type projections through the existing preparation owner before compilation.

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

Not applicable: this is generated-source cleanup rather than a reported runtime bug; the supplied evidence exercises installation, builds, and declaration consumers.

Is this the best way to solve the issue?

Yes: extending the existing generator and preparation entrypoints preserves one schema owner and existing imports without introducing another runtime implementation.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is internal build cleanup with preserved runtime behavior, SQL schemas, and consumer type contracts.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The supplied Node 24.19.0 Testbox observations exercise the changed preparation owner through fresh installation, full build, and typecheck, showing generated projections and self-contained bundled declarations. Native consumer and archive negative controls supplement that proof. SQL schemas and stored-data contracts are unchanged.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Node 24.19.0 Testbox observations exercise the changed preparation owner through fresh installation, full build, and typecheck, showing generated projections and self-contained bundled declarations. Native consumer and archive negative controls supplement that proof. SQL schemas and stored-data contracts are unchanged.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head delta rather than endpoint drift. The change relocates generated types and integrates preparation into existing tooling; neither authoritative SQL schema changes. (scripts/generate-kysely-types.mts:115, 9e82f326f6da)
  • Prior finding resolved: The only change since the previously reviewed head adds the generator to the trusted wrapper inventory. Its direct-run dependency is already listed. The captured PR body reports that removing the entry fails the existing closure checks and restoring it passes all 16 archive-closure tests plus three generator tests. (scripts/pr-lib/wrapper-components.txt:124, 9e82f326f6da)
  • Compiler preparation and consumer contract: Declaration preparation precedes compiler input snapshots. The added isolated SDK consumer uses real native declaration emission and requires a string-to-number assignment to fail, protecting against generated types becoming any. (test/scripts/prepare-extension-package-boundary-artifacts.native.test.ts:122, 9e82f326f6da)
  • After-change production build evidence: The complete captured body, sourceRevision 5d3c662c16f2490dfe231be3da16b46be409b70db0ab7bdd88935320637ee5b2, records Node 24.19.0 Testbox proof: fresh installation creates both projections, the full build and typecheck pass, and bundled declarations contain no imports back into the artifact directory. It also records byte equality with previous declarations and revalidation after integration. These supplied observations were assessed without executing target code. (9e82f326f6da)
  • Still necessary on main and latest release: The fetched main generator still writes committed generated declaration files. The latest release tree also contains both declarations; the requested relocation is not already implemented there. (scripts/generate-kysely-types.mts:13, 410c54ee128e)
  • Release tree check: Both generated .d.ts files remain tracked in the supplied v2026.9.7 release commit. (src/state/openclaw-state-db.generated.d.ts:1, c074824a27c9)

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 (4 earlier review cycles)
  • reviewed 2026-10-01T02:16:20.738Z sha c4a536618c5be995859c509ffe826155b7696367 :: blocked before merge. :: none
  • reviewed 2026-10-01T02:46:00.018Z sha c4a536618c5be995859c509ffe826155b7696367 :: blocked before merge. :: none
  • reviewed 2026-10-01T03:11:08.638Z sha ed5e775 :: blocked before merge. :: [P2] Include the generator in the trusted wrapper inventory
  • reviewed 2026-10-01T03:57:14.272Z sha ed5e775 :: blocked before merge. :: [P2] Include the generator in the trusted wrapper inventory

Prepare ignored type-only schema projections through existing install, build, compiler, test, SDK API, and package-boundary entrypoints. Preserve existing import paths and generated bytes, cache unchanged inputs, and cover unbundled SDK declaration consumers. No SQL, data, or runtime migration.
Point explicit test roots at the type entrypoints and exercise generation through its production preparation owner without a test-only export.
@openclaw-barnacle openclaw-barnacle Bot closed this Oct 1, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Oct 1, 2026
@steipete
steipete force-pushed the deslop/l251-gen-kysely-build branch from c4a5366 to ed5e775 Compare October 1, 2026 02:59
@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. 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. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 1, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor 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. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 1, 2026
@steipete
steipete merged commit 6337d15 into main Oct 1, 2026
244 checks passed
@steipete
steipete deleted the deslop/l251-gen-kysely-build branch October 1, 2026 05:10
@steipete

steipete commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Oct 1, 2026
#162288 added a guarded generator import to the packaged prepare hook but
omitted it from package.json files. The docker-seed-e2e package integrity
check therefore rejected the tarball before any image build. Include the
generator and its sole relative dependency, lib/direct-run.mjs, and guard
the packaged script inventory with the existing runtime closure checker.
Source-less Docker dependency stages already skip generation and need no
copy-list changes.

The exact CI package command fails before with the missing-generator error
and passes after. The functional Linux Docker image builds and runs the
packaged prepare hook and CLI. All 17 import-closure tests, both restricted
Docker lifecycle tests, scoped changed checks and independent review pass.
The new closure assertion costs 144ms; existing wrapper/bootstrap tests
dominate the full file's runtime.

Test cost: node scripts/run-vitest.mjs test/scripts/eager-import-closure.test.ts --maxWorkers=1: 90.56s wall.
steipete added a commit that referenced this pull request Oct 1, 2026
Keep the packed prepare hook independent of the unshipped source generator:
invoke its CLI only when source schemas exist and preserve failure exits.
Prepare declarations through their existing owner before direct tsgo profiling.
This completes the source preparation gaps from 6337d15 (#162288).

Update behavior: published npm installs have no source schemas and skip
source preparation. No database, rollback, or runtime update behavior changes.
No published version contains the regressing commit; 2026.9.7 predates it.

Validation: real pnpm-pack tarball fails the missing-import guard before and
passes after; cold profiler fails before and passes after. Focused owner and
package tests, changed checks, boundary lint, architecture, and P2 review pass.
Patrick-Erichsen pushed a commit that referenced this pull request Oct 1, 2026
Keep the packed prepare hook independent of the unshipped source generator:
invoke its CLI only when source schemas exist and preserve failure exits.
Prepare declarations through their existing owner before direct tsgo profiling.
This completes the source preparation gaps from 6337d15 (#162288).

Update behavior: published npm installs have no source schemas and skip
source preparation. No database, rollback, or runtime update behavior changes.
No published version contains the regressing commit; 2026.9.7 predates it.

Validation: real pnpm-pack tarball fails the missing-import guard before and
passes after; cold profiler fails before and passes after. Focused owner and
package tests, changed checks, boundary lint, architecture, and P2 review pass.

(cherry picked from commit 83e4755)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
* build: generate Kysely declarations at build time

Prepare ignored type-only schema projections through existing install, build, compiler, test, SDK API, and package-boundary entrypoints. Preserve existing import paths and generated bytes, cache unchanged inputs, and cover unbundled SDK declaration consumers. No SQL, data, or runtime migration.

* build: finish Kysely preparation contract integration

Point explicit test roots at the type entrypoints and exercise generation through its production preparation owner without a test-only export.

* build: include Kysely generator in trusted tooling archive
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
openclaw#162288 added a guarded generator import to the packaged prepare hook but
omitted it from package.json files. The docker-seed-e2e package integrity
check therefore rejected the tarball before any image build. Include the
generator and its sole relative dependency, lib/direct-run.mjs, and guard
the packaged script inventory with the existing runtime closure checker.
Source-less Docker dependency stages already skip generation and need no
copy-list changes.

The exact CI package command fails before with the missing-generator error
and passes after. The functional Linux Docker image builds and runs the
packaged prepare hook and CLI. All 17 import-closure tests, both restricted
Docker lifecycle tests, scoped changed checks and independent review pass.
The new closure assertion costs 144ms; existing wrapper/bootstrap tests
dominate the full file's runtime.

Test cost: node scripts/run-vitest.mjs test/scripts/eager-import-closure.test.ts --maxWorkers=1: 90.56s wall.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
Keep the packed prepare hook independent of the unshipped source generator:
invoke its CLI only when source schemas exist and preserve failure exits.
Prepare declarations through their existing owner before direct tsgo profiling.
This completes the source preparation gaps from d8075c5 (openclaw#162288).

Update behavior: published npm installs have no source schemas and skip
source preparation. No database, rollback, or runtime update behavior changes.
No published version contains the regressing commit; 2026.9.7 predates it.

Validation: real pnpm-pack tarball fails the missing-import guard before and
passes after; cold profiler fails before and passes after. Focused owner and
package tests, changed checks, boundary lint, architecture, and P2 review pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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