Repository navigation
build: generate Kysely declarations at build time - #162288
Conversation
|
Codex review: blocked before merge. Reviewed October 1, 2026, 12:31 AM ET / 04:31 UTC (Revision 5). ClawSweeper reviewWhat this changesGenerate 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 Review scores
Verification
How this fits togetherOpenClaw’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
Before merge
Agent review detailsSecurityNone. PR surfaceTests +152, Docs +6, Config 0, Generated -2561, Other +57. Total -2346 across 21 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Technical reviewBest 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. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
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.
c4a5366 to
ed5e775
Compare
|
Merged via squash.
|
#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.
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.
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)
* 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
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.
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.
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
.tsfiles 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:
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).pnpm install --frozen-lockfilepassed (1.79 s) and created both projections automatically;pnpm buildpassed (300.31 s);pnpm tsgopassed (37.35 s); focused generator tests passed (1.73 s). Bundled declarations had nofromimports back into.artifacts/kysely/.--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/anyfailure.pnpm db:kysely:checkpassed (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 KiBfrom the UI reporter. This change does not touch UI source or its budget. Prior-head hosted CI run 36808415247 failed onlychecks-windows-node-test-3:src/infra/package-update-swap.windows.test.ts:72, “preserves the package after persistent EPERM on linux (retries=false)”. It receivedpackageRollbackVerified: falseandhelper-unavailable/ “native retained-directory staging is unavailable”, instead of verified rollback andEPERM.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 enforcedopenclaw/ci-gateis 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.mtsto the existing archive inventory. On Blacksmith Testboxtbx_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_stateSQL 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
src/state/openclaw-state-db.generated.d.tssrc/state/openclaw-agent-db.generated.d.tsThe 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.