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
I’ll first map the generator/store templates and existing tests, then trace how flattened columns, migrations, indexes/FTS, and upserts are emitted so the fallback is applied consistently rather than only changing
CREATE TABLE. - Assistant
The schema builder is the right choke point because the template already gates every typed artifact on table metadata. I’ll inspect that builder, generator orchestration/logging, and all template loops to determine whether a fallback table should remain in
Schema.Tableswith a flag, or use a separate collection. - Assistant
A simple “three columns means untyped” gate would wrongly omit the required per-resource fallback table, since current dead-table suppression uses that same condition. I’ll locate template helper definitions and sub-resource parent-column construction, then introduce explicit JSON-only metadata and enforce the 1500 cap after dependent-parent columns are included.
- Assistant
The fallback must not just migrate successfully; “dispatch … to JSON-only path” means sync must populate its retained table. I’ll inspect single-object dispatch and template function registration/log facilities. Then I’ll implement a non-typed JSON-only transaction helper selected by table name/resource, while ensuring no per-resource typed methods, indexes, or FTS are emitted.
- Assistant
schemaWithDependentParentscan be called more than once during generation, so logging there could duplicate warnings. I’ll inspect render call flow and generated store test assumptions before editing. The implementation will centralize cap application in a pure helper, with logging only at a generation boundary if practical. - Assistant
I’ll now implement the metadata and cap in the schema layer, including a second enforcement pass after profile-derived parent columns. I’ll also add a one-time-per-generator stderr diagnostic (
store-fallback: …) and template predicates separating “create this store table” from “generate typed projection code.” - Assistant
Next I’ll wire cap enforcement after dependent-parent augmentation, avoid adding parent columns to an already-fallback table, and add template support for retained JSON-only tables. The diagnostic will report the pre-fallback projected count once per generator instance.
- Assistant
I’ll update the store and sync templates now. The JSON-only writer will use compile-time switch cases and quoted literal table names, preserving SQL safety. It writes both the generic
resourcesrow and the retained per-resource table, but generates noUpsert<Resource>typed method, typed index, or FTS structure. - Assistant
The core wiring is in place. I’ll run focused generator tests first; template parse/render tests should catch scope or syntax errors, while schema tests verify ordinary resources remain byte-compatible. Then I’ll create a temporary 3000-field reproduction outside tracked tests and generate/build/open its SQLite store.
- Assistant
The test environment has neither
GOPATHnorGOMODCACHE; this is infrastructure configuration, not a code failure. I’ll pointGOPATHat a temporary cache and rerun the focused suite. - Assistant
Go also requires a build cache because
HOMEis unset. I’ll configure temporaryHOME/GOCACHEand rerun. - Assistant
Focused tests pass. For the requested reproduction, I’ll use a temporary root-level Go program (removed afterward, not a test) to synthesize the API model. First I’ll inspect the exact spec structs and minimal generation setup so the reproduction exercises full generation rather than only the cap helper.
- Assistant
I can construct the wide resource directly from the public spec model. I’ll make a temporary executable that (1) confirms
BuildSchemacollapses 3004 projected columns to three, (2) generates a Store+Sync CLI while capturing the fallback diagnostic, and then inspect/build/run the generated store. - Assistant
I’ll execute the temporary reproduction now. It will fail loudly if the schema isn’t exactly three columns or if generation fails; afterward I’ll verify emitted SQL/method absence and run the generated store package’s own migration tests against empty databases.
- Assistant
The reproduction confirms exactly three columns, emits the diagnostic, and contains neither typed
UpsertControl, index, nor FTS code. The generated package test was blocked only because fresh generated projects intentionally requirego mod tidyto populatego.sum; I’ll run tidy as the normal post-generation gate, then rerun migrations and inspect that batch writes populate the fallback table. - Assistant
The generated empty-DB migration suite now passes. I’ll additionally execute a temporary generated-project program that calls
UpsertBatchand queries thecontroltable, proving the dispatch writes the JSON-only table rather than merely creating it. Then I’ll run the repository’s complete generator suite. - Assistant
The runtime fallback write succeeds. The complete generator suite reached an unrelated pre-existing quality-gate failure: the environment’s Go 1.26.4 standard library is flagged by
govulncheck(fixed in Go 1.26.5); focused affected tests passed.I’ll do a final audit of every
.Tablesconsumer, generated schema-version tests, formatting, and diff to ensure JSON-only metadata cannot accidentally trigger typed SQL elsewhere. - Assistant
The audit shows all other table consumers are either FTS-gated or backfill-gated, both cleared by fallback. I’ll make a small documentation correction (typed predicate is no longer responsible for fallback table creation), then run
go teston all non-generator packages plus focused generator tests,go vet, and inspect final status.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.