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.
Assistant
Let me explore the repository structure more carefully.
Assistant
Let me look at the store.go.tmpl to understand the structure of the typed-table-emit path.
Assistant
Let me look at the wider context of the template to understand how tables and columns are defined.
Assistant
Let me find where the template data is prepared (the generator logic).
Assistant
Now let me understand the flow and find where the schema is used and how the
hasTypedTableis defined:Assistant
Now let me look at how the typed-table emit uses the
hasTypedTablegate and theUpsertBatchlogic:Assistant
Now let me look at the UpsertBatch dispatch logic:
Assistant
Now let me look at how the test for
hasTypedTableworks and where store generation is tested:Assistant
Let me look at the entire schema_builder to understand the columns logic:
Assistant
Now let me look at the schema_builder_test.go to understand the testing patterns:
Assistant
Let me understand
domainUpsertMethodNameand look at how the column count check should be implemented:Assistant
Let me check existing tests for the store package to understand test patterns:
Assistant
Let me understand the tests in detail and find what stores test files do (these are test data generated by the generator, not unit tests):
Assistant
Let me check the structure of
Generate()and how schema is used:Assistant
Let me see the Generate function to understand the flow better:
Assistant
Let me also check the test for the dispatch switch:
Assistant
Now I have a complete understanding. Let me also look at how the schema is used elsewhere, particularly
visionRenderData:Assistant
Now let me look at the existing tests to ensure I understand how the current code is tested:
Assistant
Let me look at how
profileis used and the structure of dependent resources:Assistant
Now let me look at the existing structure once more and write my implementation. First, let me check if there's a
Visionlogging mechanism:Assistant
Now let me check the test fixture for
BuildSchemato understand testing patterns better:Assistant
Now I have a comprehensive understanding. Let me implement the fix. The approach is:
- Add a constant
maxTypedTableColumns = 1500 - Add a function
applyWideTableJSONOnlyFallbackthat replaces wide tables with a JSON-only schema - Call it from
schemaWithDependentParents(after parent_id columns are added) - Log the fallback message
The existing
hasTypedTablegate (len(t.Columns) > 3) already excludes 3-column JSON-only tables, so no typed table is created, no typed indexes, no FTS5, no typed upsert, and no dispatch case inUpsertBatch.Let me also look at one more area to understand how
parent_idis added and see if I should add the JSON-only fallback function toschema_builder.goorgenerator.go:- Add a constant
Assistant
Now I have all the context needed. Let me write the implementation. First, let me write a small reproduction script:
Assistant
Now let me implement the fix in
schema_builder.go:Assistant
Let me use sed to modifythe import block.
Assistant
Sed didn't handle multiline properly. Let me use a different approach with python or direct filemanipulation.
Assistant
Now let me add the constant and the fallback function. First, let me add the constant near
baseTableColumns:Assistant
I have an extra newline. Let me fix that.
Assistant
Let me check by viewing the file directly:
Assistant
I see the issue. The string literal is split across two lines, breaking the syntax. Let me fix this:
Assistant
Let me verify the fix:
Assistant
Now let me update
schemaWithDependentParentsin generator.go to call the fallback function:Assistant
Now let me verify the file compiles:
Assistant
The code compiles. Now let me write a temporary test script to verify the fix:
Assistant
All my tests pass. Now let me also test the full pipeline (actual generation):
Assistant
Let me re-read the evaluation contract carefully and check the template logic:
Assistant
I need to refine my implementation. The contract requires the per-resource table to be retained (CREATE TABLE emitted), but the typed upsert code shouldn't be generated. Let me look at all uses of
hasTypedTable:Assistant
Let me check sync.go.tmpl usage:
Assistant
This is interesting. The sync.go.tmpl uses
hasTypedTableto gate the call todb.Upsert<X>(data). For JSON-only fallback, this should be false (no typed upsert function generated). So thedefaultbranch (db.Upsert(resource, id, data)) is used.Let me look at db.Upsert to understand:
Assistant
Now I have a clear plan. Let me implement the changes:
Assistant
Now let me add the
hasPerResourceTablepredicate togenerator.go:Assistant
Now let me update the template to use
hasPerResourceTablefor the CREATE TABLE gate:Assistant
Let me verify the template gate changes:
Assistant
Now let me verify the code compiles:
Assistant
Let me update my test to reflect the new behavior:
Assistant
I need to remove the
newExecCmdsince I haven't defined it. Let me simplify that test:Assistant
The pipeline test fails because of go.sum issues in the generated package, not related to my fix. Let me simplify this test:
Assistant
The python script ran but the previous file content had the broken test. Let me look at the file:
Assistant
Let me delete and rewrite the test file with simpler tests:
Assistant
All tests pass. Now let me also verify the existing tests still pass:
Assistant
The existing test passes. Let me also run all generator tests to make sure I haven't broken anything:
Assistant
The govulncheck failure is unrelated to my changes (it's a vulnerability in Go's standard library). Let me check the other tests:
Assistant
Let me check if this test was already failing before my changes:
Assistant
The git stash didn't remove untracked files. Let me delete my test files and re-run:
Assistant
Good - the govulncheck failure is a pre-existing issue with the Go standard library vulnerability, not caused by my changes. Let me restore my changes:
Assistant
Now let me verify the changes are restored:
Assistant
Let me run all generator tests except the govulncheck-related ones to make sure I haven't broken anything:
Assistant
Let me see which tests pass and which fail:
Assistant
Only
TestGenerateWithNoAuthfails, and that's the govulncheck pre-existing failure (Go stdlib vulnerability), unrelated to my changes. Let me also verify this by running the test with my changes vs without my changes (I already verified this above with git stash).Let me checkthe count of passing tests:
Assistant
Let me re-create my tests temporarily for final verification, then delete them before submitting:
Assistant
Now let me also verify the dependent-parent scenario specifically: a wide table that also has a parent_id column should still hit the fallback:
Assistant
Let me fix the test by adjusting the count:
Assistant
Let me check the test file:
Assistant
I see. The first iteration doesn't start at 0, it starts at... wait, it starts at 0. Let me check:
for i := 0; i < 1497; i++ {This should give 1497 iterations. Plus the 1 parent_id = 1498 total. Hmm.
Wait, let me re-read my test. I removed the
baseColscalculation. Let me look at the actual flow:The schema starts with empty Columns. Then we add 1497 f columns + 1 parent_id = 1498. But we expected 1501. The mismatch is 3, which is the base table columns.
Looking at my test logic - I wanted to start with empty columns and just have 1497 typed + 1 parent_id = 1498. So the cap (1500) would NOT be hit.
Let me make this test correct by adding 1499 f columns + 1 parent_id = 1500. Wait, 1500 is not greater than 1500, so it shouldn't trigger fallback. Let me make it 1500 typed cols + 1 parent_id = 1501, which is > 1500 and would trigger.
Let me think about this more carefully:
- maxTypedTableColumns = 1500
- Trigger: len(Columns) > 1500
- So we need 1501+ columns to trigger
Let me redo the test:
Assistant
All tests pass. Let me also verify the existing store test still passes:
Assistant
Let me also run all the other tests in the repo to make sure nothing else is broken:
Assistant
Let me investigate the failures:
Assistant
This test uses
os.Chmod(blockedDir, 0)which probably fails when running as root. Let me check if this was already failing before my changes:Assistant
Pre-existing failure. Let me check the internal/cli test:
Assistant
The internal/cli tests timed out. Let me try running themwith a faster check:
Assistant
Let me try running just one cli test to see what's happening:
Assistant
Let me verify that my changes don't break the main generator tests:
Assistant
Only TestGenerateWithNoAuth fails (pre-existing govulncheck failure unrelated to my changes). All other tests pass.
Let me now also verify the generated store.go file looks correct by examining the relevant portions:
Assistant
I can't import internal packages from outside. Let me write the script inside the package:
Assistant
The inspection confirms:
-
Control table (wide resource):
- CREATE TABLE emitted with exactly 3 columns: id, data, synced_at
- No
upsertControlTx(no typed upsert code) - No
control_fts(no FTS5)
-
Items table (narrow resource):
- CREATE TABLE emitted with 4 columns: id, data, synced_at, name (typed column preserved!)
upsertItemsTxexists (typed upsert preserved)- No FTS5 (because not enough text fields to qualify)
The fallback log line is emitted:
store-fallback: control (3003 cols) → JSON-only (typed columns would exceed SQLite SQLITE_MAX_COLUMN=2000)This matches the contract exactly. Now let me clean up the temporary test files:
-
Assistant
Now let me verify the final state of changes:
Assistant
The comment I added is now slightly misleading since I changed the CREATE TABLE gate to use
hasPerResourceTable. Let me update it to reflect the actual behavior:Assistant
Let me also verify the template change is correct:
Assistant
Now let me run all the tests again to make sure nothing is broken:
Assistant
Let me also verify the code compiles cleanly:
Assistant
Now let me think about edge cases by re-reading the contract carefully:
Assistant
All edge cases pass. Now let me clean up the test files:
Assistant
Now let me also run the existing store tests one more time to make sure they all pass:
Assistant
Let me also run the schema builder tests:
Assistant
All 9 schema builder tests pass. Let me also test some other potentially relevant tests:
Assistant
Only TestGenerateWithNoAuth fails (pre-existing govulncheck issue, not related to my changes). Let me verify the final state of all my changes:
Assistant
Let me view the complete final diff for one last review:
Assistant
Let me also do a final test to verify the actual generated code is valid Go:
Assistant
Both positive and negative acceptance criteria pass. Let me clean up:
Assistant
Now let me run a final comprehensive test to make sure everything is still in order:
Assistant
Only the pre-existing TestGenerateWithNoAuth (govulncheck) test fails. My changes are clean.
Let me run one last check to verify the diff is clean:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.