ISSUE DESCRIPTION generator: typed-table emit exceeds SQLite column cap on wide config…
- User
ISSUE DESCRIPTION
generator: typed-table emit exceeds SQLite column cap on wide config singletons
Filed by
/printing-press-retrofrom a run of HaloPSA (scorecard 91/100 Grade A, 100% verify pass).Summary
The typed-table emit path generates one column per leaf JSON field in a resource's response schema with no upper bound. On HaloPSA's tenant-global
/Controlconfig singleton, this produced a 3,747-columnCREATE TABLEthat exceeded SQLite's defaultSQLITE_MAX_COLUMN=2000. Generation passed every quality gate;sync --full --dry-rundied cold withSQL logic error: too many columns on control (1). The failure mode is silent until first sync.Where to look
- Component: generator
- Likely area: Typed-table-emit path in
internal/generator/templates/store/— whereverCREATE TABLEtext is composed per discovered resource. - Triggered when: A spec resource's response schema flattens to >~1500 leaf fields. Enterprise config singletons are the obvious class.
What we observed
Run-1 output (post-generate):
PASS go mod tidy / govulncheck / go vet / go build PASS halopsa-pp-cli --help / version / doctor Generated halopsa at .../working/halopsa-pp-cliFirst
sync --full --dry-run:Error: opening local database: running migrations: migration failed: SQL logic error: too many columns on control (1)Per-table column counts (top 5 widest, recorded by Python introspection of
internal/store/store.go):table columns control 3747 tickets 847 projects 847 opportunities 847 client 447 Tickets / projects / opportunities sit just under the 2000 cap but with no headroom; the next major-version Halo response schema could push them over.
Workaround applied this run: hand-stripped
/Control*paths from the spec (5 paths) and added a stubControlschema so residual$reftargets resolved. Regenerated successfully.Suspected root cause
Assistant
Let me explore the repository structure to understand the codebase.
Assistant
Let me look at the generator's store template path.
Assistant
Let me look at the store.go template and the store generation logic.
Assistant
This is a large template. Let me see the rest of it, particularly the CREATE TABLE part and the migrate part.
Assistant
Let me see the key regions of the template: the CREATE TABLE gate, the per-table templates (around 270-340), the typed upsert (790-870), the Search (1027), and the UpsertBatch dispatch (938-1020).
Assistant
Now let me look at the typed upsert region, the Search, and the UpsertBatch dispatch.
Assistant
Now let me find where
hasTypedTableis defined and where the Tables are constructed.Assistant
Let me find the TableDef definition and where tables/columns are built.
Assistant
Let me look at
schemaWithDependentParentsand how the schema is passed to render.Assistant
Let me look at the store test templates and how the schema is used in the mcp/vision render data.
Assistant
Let me see the Search function and what comes after the typed upsert block.
Assistant
Now I have a good understanding. Let me plan the implementation:
- Add a
JSONOnly boolfield toTableDefin schema_builder.go. - Add a constant for the safety cap (1500 columns).
- Apply the cap. The question is where. The cap must include dependent-parent columns per the evaluation contract ("including dependent-parent columns"). So the cap check must be applied AFTER
schemaWithDependentParentsadds parent_id. ButschemaWithDependentParentsis called inrenderStoreFiles? Let me check where schemaWithDependentParents is called.
Let me search.
- Add a
Assistant
Let me check how the generator logs/prints during generation.
Assistant
Let me look at the existing warning style around line 1755 and 1851.
Assistant
Let me check when renderMCPEntrypoint and the two schemaWithDependentParents calls happen during Generate.
Assistant
Let me look at the Generator struct definition.
Assistant
Let me look at the start of the Generator struct to find where to add a field.
Assistant
Let me check the store_schema_version_test.go.tmpl.
Assistant
Now I understand the full picture. Let me implement. First, modify
schema_builder.goto add theJSONOnlyfield, the cap constant, and theapplyTypedColumnCapfunction.Assistant
Now let me add the
JSONOnlyfield toTableDef:Assistant
Now let me add the cap constant and
applyTypedColumnCapfunction afterbaseTableColumns:Assistant
The heredoc had a trailing blank line issue. Let me retry:
Assistant
Now I'll insert the cap function after the
baseTableColumnsvar (line 54 is blank). Let me replace line 54:Assistant
I need a blank line between line 111 and 112. Let me fix:
Assistant
Let me add the missing blank line by replacing lines 111-112:
Assistant
The comment got duplicated. Let me fix lines 113-117:
Assistant
Now let me add the
storeFallbackLoggedfield to the Generator struct and updateschemaWithDependentParents:Assistant
Now let me update
schemaWithDependentParentsto apply the cap and log fallbacks:Assistant
The function's closing brace got lost. Let me fix lines 2495-2497:
Assistant
Now let me modify the store.go.tmpl CREATE TABLE gate. Let me view the exact lines:
Assistant
I'll restructure the CREATE TABLE gate to include JSONOnly tables, while keeping Indexes/FTS5 gated to typed tables only. Let me replace lines 274-323:
Assistant
Now let me build the generator package to check compilation:
Assistant
There are env vars already set: GOMODCACHE=/go/pkg/mod, GOCACHE=/.cache/go-build, GOPATH=/go, HOME=/root. The earlier issue was HOME not set. Let me just run go build with these env vars.
Assistant
The generator package builds. Now let me write a reproduction test to confirm the fix works. Let me first look at existing generator tests to understand the test harness and how to build a synthetic spec.
Assistant
Let me look at the migration test around line 3113 to model my reproduction test:
Assistant
Let me look at
minimalSpecandcollectResponseFieldsto understand how to construct a spec with many fields:Assistant
Let me check the spec types:
spec.TypeField,ResponseDef,Types:Assistant
Let me check how
TestGenerateProjectsCompilecompiles generated CLIs:Assistant
Let me check the
runGoCommandhelper:Assistant
Now let me write a temporary reproduction test to validate the fix:
Assistant
The cap fired (log emitted). My regex didn't match the CREATE TABLE. Let me inspect the actual generated content:
Assistant
Let me modify the repro test to dump the store.go to a temp file for inspection:
Assistant
The table name is quoted (
"control"). Let me view the control CREATE TABLE body:Assistant
The control table has exactly 3 columns — the fix works. Let me fix the test regex to account for the quoted table name:
Assistant
Let me check the actual regex in the test file:
Assistant
The Python replace didn't apply (the regex still lacks the quotes). Let me fix the regexes directly to allow optional quotes:
Assistant
Let me check the colCount logic:
Assistant
The newline count gives 4 (not 3). Let me use a column-declaration regex instead. Let me fix both colCount computations:
Assistant
Now let me run the test:
Assistant
The
\(is an invalid Go escape in a double-quoted string. Let me fix the regexes to use raw strings:Assistant
Let me simplify the regexes to not match the backtick delimiters:
Assistant
The build step needs the full vision set. Let me check the default
VisionTemplateSetand howTestGenerateProjectsCompilebuilds without setting it:Assistant
So when VisionSet.IsZero(), Generate() calls SelectVisionTemplates(plan). If plan is nil (no visionary plan), it returns empty set. For the build to succeed, I need the full set. The simplest: don't set VisionSet manually, but provide a VisionaryPlan? That's complex.
Alternatively, I can construct the full VisionTemplateSet manually: Store, Search, Sync, MCP, Export, Import, Analytics, Tail all true. But the build might require other things. Let me check what TestGenerateProjectsCompile does — it just calls gen.Generate() with no VisionSet, and the spec (stytch.yaml etc.) presumably has a visionary plan embedded? Actually those specs likely include a
visionsection that produces a plan.Simpler approach for my repro: instead of building the full CLI, just verify the store package compiles and its tests pass. But
go test ./internal/store/...requires the store package's dependencies, which need go.mod to be complete. The store package imports modernc.org/sqlite which is in go.mod. Butgo test ./internal/store/...with -mod=mod needs the go.mod to have all store deps. The store package only needs modernc.org/sqlite. But go test also compiles the test files which import the same. Should be fine if go.mod has modernc.org/sqlite.Assistant
Let me change the repro test to use the full VisionTemplateSet and build only the store package (not
./...):Assistant
The test passes. The store package compiles and its tests pass (which Open a fresh DB and run all migrations, including the control CREATE TABLE — confirming sync against empty DB succeeds). Let me verify that before the fix, the generated store test would have failed. Let me temporarily disable the cap and re-run to confirm the bug reproduces:
Assistant
This confirms the exact error from the issue:
migration failed: SQL logic error: too many columns on control (1). Now restore the cap:Assistant
Now let me run the existing generator tests that touch the store generation to make sure I haven't broken anything. Let me run the store-related tests:
Assistant
All pass. Now let me check the golden test fixtures. There may be golden tests that compare generated output byte-for-byte. Let me search for golden tests involving the store:
Assistant
Let me find the golden test runner (likely a script):
Assistant
The golden tests require building the binary. Let me check whether the golden suite is run as part of
go test. Let me check if there's a Go test that runs golden cases:Assistant
Let me build the entire repository to ensure everything compiles:
Assistant
Let me run
go veton the generator package and the schema_builder to be safe:Assistant
Now let me run the golden suite to confirm generated output is unchanged for existing cases. Let me build the binary and run verify:
Assistant
jqis required. Let me install jq.Assistant
Some golden failures appear unrelated (README.md, client.go, stdout.txt). Let me check whether these are pre-existing by examining the store.go diff specifically and comparing against a clean checkout:
Assistant
The store.go diff is just a
<REPO>normalization artifact (the golden harness's sed mangles the URL), not related to my change. Let me confirm the store.go diff is only that line:Assistant
The only store.go diff is the pre-existing
<REPO>normalization mangling. These golden failures look environmental. Let me confirm by stashing my source changes and re-running golden to get the baseline failure set:Assistant
Baseline also has 16 cases changed. Let me restore my changes and re-run golden, then compare failure sets:
Assistant
The golden failure set is identical with and without my changes — meaning my change introduces zero golden regressions (the failures are pre-existing environmental normalization artifacts).
Now let me clean up: remove the temporary reproduction test file and the build artifacts:
Assistant
Now let me run a broader slice of the generator test suite to make sure nothing broke. Let me run the fast (non-short-skip) tests in the generator package:
Assistant
The
TestGenerateWithNoAuthfailure is fromgovulncheckreporting a Go stdlib TLS vulnerability — environmental and unrelated to my change. Let me confirm it's pre-existing by stashing and running just that test:Assistant
Confirmed pre-existing (fails on baseline too due to
govulncheckstdlib vuln).Now let me run the store/schema-specific generator tests (excluding the govulncheck one) to confirm they pass with my change:
Assistant
All pass. Let me do a final review of the complete diff:
Assistant
The diff is clean and complete. Let me run one final build to be sure everything compiles after cleanup:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.