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):
codePASS 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:codeError: 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.
Assistant
Good,
osandfmtalready imported. Now let's check tests that verify golden outputs to avoid breaking generation determinism (like tests capturing stdout). Let's check test suite for generate command capturing stdout output that might now include the new log line unexpectedly.Assistant
Good, this is fine — WideFallback tables correctly excluded since hasTypedTable is false for them. Now let's check sync.go.tmpl usage at line 1714.
Assistant
Good, this is also safe since
hasTypedTableis false for WideFallback tables — default falls todb.Upsert(resource, id, data)(generic write). Now let's implement the changes.Assistant
Now let's add the constant and the
applyWideTableFallbackfunction afterbaseTableColumnsdeclaration.Assistant
Now update
schemaWithDependentParentsin generator.go to callapplyWideTableFallbackagain after adding parent_id columns.Assistant
Now let's update the template
store.go.tmplto emit CREATE TABLE for WideFallback tables too.Assistant
Good, balanced. Now let's check the
hasStoreBackfillColumnsandisStoreBackfillColumnfunctions that might reference.Columnsfor wide table's migrate/backfill logic (ensureColumn calls). Let's check.Assistant
Good, that excludes id/data/synced_at, so WideFallback tables produce no backfill entries. Now let's build the project to check for compile errors.
Assistant
Build succeeds. Let's persist these env vars for the rest of the session and run existing tests.
Assistant
Good. Now let's write a reproduction script to verify the fix works with a synthetic wide resource.
Assistant
I need to place this inside the repo module to access internal packages, or write a Go test file temporarily inside the package (and remove before submitting).
Assistant
The fallback logic works correctly. Let's clean up and also test the full generation pipeline end-to-end (actually generating a CLI) to make sure store.go compiles and CREATE TABLE only has 3 columns for the wide resource.
Assistant
Excellent! Exactly as expected — CREATE TABLE with only 3 columns and no typed UpsertControl method. Now let's check the negative case (narrow table below cap keeps typed columns) still works with a broader test, and verify the whole store.go compiles.
Assistant
Both positive and negative cases work. Now let's test full end-to-end: generate a complete CLI project with the wide resource and confirm it builds with
go buildand that async --full --dry-run-style flow (or at least DB migration) succeeds against an empty DB.Assistant
Need
go mod tidyfirst (as the actual pipeline does).Assistant
The migration probe confirms the fix works end-to-end: opening a fresh empty DB succeeds without the "too many columns" error. Now let's confirm this fails without the fix (sanity check) by temporarily reverting and re-running — but that's risky; instead let's just verify the logic once more, then clean up temp test files.
Assistant
We've successfully reproduced the exact error from the issue. Now let's restore the fix.
Assistant
Confirmed both the bug reproduction and the fix. Now let's run the full existing test suite for the generator package (and related packages touching schema/store) to make sure nothing broke.
Assistant
Confirmed: this failure is pre-existing and unrelated to my change (Go toolchain version vulnerability, environment issue). Let's restore the fix.
Assistant
Now let's run the full generator test suite excluding this known-flaky govulncheck-dependent test, to confirm no other regressions.
Assistant
Only the pre-existing, environment-caused
TestGenerateWithNoAuth(govulncheck vs. Go toolchain vulnerability) fails — same as before my changes. All 653 other tests pass. Let's also run the broader test suite (pipeline, store-related packages) to be thorough.Assistant
Pre-existing failure, unrelated to my changes. Let's restore the fix.
Assistant
Both failures are confirmed pre-existing/environmental, unrelated to my changes. Now let's review the final diff for correctness and cleanliness.
Assistant
Good — this gracefully falls back to the generic
resourcestable viajson_extractwhen the field isn't a real column on the resolved table, which is exactly the correct behavior for WideFallback tables (their table now exists but only has id/data/synced_at). No crash risk here. Now let's do a final full build/test pass and review the diff once more.Assistant
Everything builds cleanly with no vet issues, and the working tree contains exactly the three intended file changes. Let's clean up any leftover temp files.
Assistant
No leftover temp/test artifacts. Now let's go through the checklist explicitly.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.