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 start by exploring the repository structure to understand the codebase and then locate the relevant files mentioned in the issue.
- Assistant
Let me explore more of the repository structure, particularly the internal/generator directory mentioned in the issue.
- Assistant
Let me explore the internal/generator directory and specifically look for the templates/store path mentioned in the issue.
- Assistant
The issue mentions
internal/generator/templates/store/as the likely area. Let me look at the templates directory. - Assistant
Let me look at the store template file first:
- Assistant
Let me see the full store.go.tmpl file, particularly the CREATE TABLE section:
- Assistant
Now let me look at the section around line 279 where the typed table CREATE TABLE is generated:
- Assistant
Now let me look at the generator.go file to see how the Tables and Columns are populated:
- Assistant
Let me search for where Tables are defined in the template data structures:
- Assistant
Let me find the TableDef struct definition and where Tables are populated:
- Assistant
Let me search in other files as well.
- Assistant
Let me look at the schema_builder.go file:
- Assistant
Now I understand the structure. Let me look at how Upsert is generated and where FTS5 triggers are handled:
- Assistant
Let me look at the full store.go.tmpl to see how the migration works:
- Assistant
Now let me understand the UpsertBatch logic:
- Assistant
Now let me look at the UpsertBatch function to understand how it dispatches:
- Assistant
Now let me look at the upsert functions for typed tables:
- Assistant
Let me look at the upsert{{pascal .Name}}Tx template function to see how it's generated:
- Assistant
Now let me look at the hasTypedTable function in generator.go:
- Assistant
Now let me look at the existing tests to understand what's expected:
- Assistant
Let me also look for any logging mechanism in the generator:
- Assistant
Now I have a good understanding of the codebase. Let me create a reproduction script first to confirm the issue:
- Assistant
Let me look at the spec package to understand the types:
- Assistant
Let me check the spec.go file to understand the types:
- Assistant
Let me look at the TypeField struct:
- Assistant
Let me run the existing tests to see the current state:
- Assistant
Now I have a good understanding of the codebase. Let me implement the fix. The key is:
- In
BuildSchemainschema_builder.go, check column count and fall back to base-only schema when >1500 - In the template, the table needs to be created (CREATE TABLE) for wide fallback tables but without FTS5/typed upsert
- Add a new template predicate for wide fallback tables
Let me start with the schema_builder.go change:
- In
- Assistant
Let me look at BuildSchema more carefully:
- Assistant
Let me also check the
isBackfillColumnand related functions: - Assistant
Let me look at those functions:
- Assistant
Now let me understand the full template function map in generator.go:
- Assistant
Now I have a complete understanding. Let me implement the fix. I need to:
- Add a
WideFallbackfield toTableDefinschema_builder.go - In
BuildSchema, check column count and strip to base columns if >1500 - Add a
hasStoreTabletemplate function ingenerator.go - Update
store.go.tmplto usehasStoreTablefor CREATE TABLE emission
Let me start:
- Add a
- Assistant
Let me look at the full TableDef struct and the area around BuildSchema where I need to add the check:
- Assistant
Now let me add the WideFallback field to TableDef:
- Assistant
Let me use the edit command instead:
- Assistant
Now let me add the WideFallback field to TableDef:
- Assistant
Good. Now let me add the column count threshold constant and the fallback logic. Let me look at the area after the column building loop:
- Assistant
Now I need to add the column count threshold and the fallback logic. Let me add the constant first:
- Assistant
Now let me add the column count check. I need to add it after the FTS5 section and before
tables = append(tables, table): - Assistant
Now let me add the column count check between the FTS5 section and
tables = append(tables, table): - Assistant
I see there are some issues. Let me fix the duplicates:
- Assistant
I see there are still issues. Let me fix the extra closing brace and the duplicate append:
- Assistant
Let me fix the remaining duplicates:
- Assistant
Now let me fix the duplicate
tables = append(tables, table): - Assistant
Let me fix the remaining duplicate comment:
- Assistant
Good. Now I need to add the
fmtandosimports since I'm usingfmt.Fprintf(os.Stderr, ...): - Assistant
Let me add the required imports:
- Assistant
I see there's a duplicate closing parenthesis on line 11. Let me fix that:
- Assistant
I had a typo - I used
EOFinstead ofEOFat the end of the heredoc. Let me fix the duplicate closing paren. - Assistant
There's a duplicate import line on line 10. Let me fix that:
- Assistant
Good, now the file looks correct. Let me verify it compiles:
- Assistant
Great, it compiles. Now let me run the existing tests to make sure they still pass:
- Assistant
All existing tests pass. Now let me update the generator.go to add the
hasStoreTabletemplate function. Let me look at where it should be added: - Assistant
Now let me add the
hasStoreTablefunction afterhasTypedTable: - Assistant
I see there are duplicate lines. Let me fix them:
- Assistant
There's still a duplicate
pathContainsParamon lines 420-421. Let me fix that: - Assistant
Good, the file looks correct now. Let me verify it compiles:
- Assistant
Now let me update the store.go.tmpl to use
hasStoreTablefor the CREATE TABLE section: - Assistant
Now let me update the template to use
hasStoreTablefor the CREATE TABLE section: - Assistant
Good. Now let me verify the generator builds correctly:
- Assistant
Let me wait for the build to complete:
- Assistant
Let me run the build again to see if it completes:
- Assistant
Good, the build succeeds. Now let me run the existing tests to make sure they still pass:
- Assistant
Good. Now let me run the broader generator tests to make sure nothing is broken:
- Assistant
The test failure is due to a vulnerability in the Go standard library (GO-2026-5856), not related to my changes. This is a pre-existing issue in the test environment. Let me check if there are any tests that specifically test the store generation or the hasTypedTable predicate:
- Assistant
Let me look at the TestGenerateStoreUpsertBatchDispatchesToTypedTable test to see if it needs to be updated:
- Assistant
Let me look at the TestGenerateStoreUpsertBatchDispatchesToTypedTable test:
- Assistant
Good, the existing tests should still pass because my changes only affect tables with >1500 columns. Now let me create a temporary test to verify my fix works:
- Assistant
Let me check what the Response type looks like in the spec:
- Assistant
Let me check the ResponseDef struct:
- Assistant
Good, the ResponseDef has
Itemfield. Let me fix my test to useResponseDefinstead ofResponseType: - Assistant
Now let me run my test to verify the fix works:
- Assistant
My tests pass. Now let me remove the temporary test file since the issue says I shouldn't add new tests to the repository:
- Assistant
Now let me check if the hasTypedTable function is used in other places:
- Assistant
Let me check what sync.go.tmpl does at line 1714:
- Assistant
Good, the sync dispatch already correctly uses
hasTypedTablewhich returns false for fallback tables. Let me also check the store_upsert_batch_test.go.tmpl: - Assistant
Good, the test template also correctly uses
hasTypedTable. Now let me run the existing tests to make sure everything still passes: - Assistant
Good, all existing tests pass. Let me also run some specific tests that test the store generation:
- Assistant
Let me also run the store-related tests:
- Assistant
Good, the store-related tests pass. Now let me also check if there are any tests that test the actual sync with the store:
- Assistant
All the store-related tests pass. Now let me also verify the full end-to-end scenario by creating a temporary test that generates a CLI with a wide resource and verifies the generated store.go:
- Assistant
Let me run this test:
- Assistant
Let me find the naming package:
- Assistant
Let me find the naming package properly:
- Assistant
Let me find the naming import:
- Assistant
Let me look at the imports:
- Assistant
I see, the naming package is at
github.com/mvanhorn/cli-printing-press/v4/internal/naming. Let me fix my test file: - Assistant
Let me run this test:
- Assistant
The end-to-end test passes. Now let me clean up the temporary test file:
- Assistant
Now let me run the broader set of existing tests to make sure nothing is broken:
- Assistant
All the store-related tests pass. Now let me also run the schema_builder tests:
- Assistant
All tests pass. Let me also verify the final state of my changes by looking at the git diff:
- Assistant
Let me also check if the baseTableColumns comment got accidentally trimmed:
- Assistant
I see the baseTableColumns comment got accidentally trimmed. Let me fix it:
- Assistant
I see there's a duplicate line. Let me fix that:
- Assistant
Good, now the file looks correct. Let me verify it compiles:
- Assistant
Let me run the final verification tests:
- Assistant
All tests pass. Now let me also look at the
TestStoreSkipsDeadTablesForResourcesWithoutTypedUpserttest to make sure my changes don't affect it: - Assistant
Let me look at this test to understand what it does:
- Assistant
This test is critical! It checks that dead tables are not created. My change with
hasStoreTableshould still work correctly because:demo_authhas only 3 columns andWideFallback=false->hasStoreTablereturns falseitemshas >3 columns andWideFallback=false->hasStoreTablereturns true
Let me verify by running the test:
- Assistant
The test passes. Now let me also run a broader set of tests to make sure nothing is broken. Let me also check if there are any tests that specifically test the store generation:
- Assistant
The only failure is the pre-existing govulncheck issue (GO-2026-5856) which is a Go standard library vulnerability, not related to my changes. All the store-related tests pass.
Let me verify the final state of my changes:
- Assistant
The diff looks clean and correct. Let me also run a broader set of tests to make sure nothing is broken. Let me run the full test suite for the generator package:
- Assistant
Let me verify by checking how many tests passed:
- Assistant
Let me also count the PASS tests:
- Assistant
Let me try again with a more verbose output:
- Assistant
Let me try with -count=1 to force re-running tests:
- Assistant
All tests pass except for the pre-existing govulncheck issue (GO-2026-5856) which is a Go standard library vulnerability. This is not related to my changes.
Let me verify the final state of the changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.