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 identify the relevant files for fixing this issue.
- Assistant
Let me look at the directory structure more specifically for the generator and store templates.
- Assistant
Let me look at the internal directory structure to find the generator and store templates.
- Assistant
Let me explore the generator directory and find the store templates.
- Assistant
Let me examine the store template and related files.
- Assistant
Let me continue reading the store template to understand the table creation logic.
- Assistant
Let me search for CREATE TABLE and migration-related code in the store template.
- Assistant
Let me examine the area around the CREATE TABLE generation for typed resources.
- Assistant
Let me now look at the generator's main file to understand the data structures used in templates.
- Assistant
Let me search for table structure definitions and the hasTypedTable function.
- Assistant
Let me look at the TableDef type and hasTypedTable function.
- Assistant
Let me search for the TableDef type definition.
- Assistant
Let me search for TableDef in the codebase.
- Assistant
Let me examine the schema_builder.go file.
- Assistant
Let me look at the schema_builder test to understand how tests are structured.
- Assistant
Now let me look at how the UpsertBatch dispatch works in the store template.
- Assistant
Let me look at the UpsertBatch function template.
- Assistant
Let me search for the upsert method pattern in the store template.
- Assistant
Let me examine the typed upsert function template.
- Assistant
Now let me check how the generator processes schema to understand where logging should happen.
- Assistant
Let me look at how BuildSchema is called and what logging is available.
- Assistant
Let me see the full schemaWithDependentParents function.
- Assistant
Let me now check the existing tests for the schema builder.
- Assistant
Let me check the Go environment.
- Assistant
Let me set up the Go environment properly.
- Assistant
Let me set up the environment properly for Go.
- Assistant
Now I understand the issue. Let me create a plan:
-
Issue: When a resource's response schema has many leaf fields (e.g., 3747), the generated
CREATE TABLEhas too many columns, exceeding SQLite's SQLITE_MAX_COLUMN=2000 limit. -
Solution: Add a column count check in
BuildSchemathat falls back to JSON-only schema when the column count exceeds a threshold (1500). -
Implementation:
- Add a constant
maxTypedColumns = 1500in schema_builder.go - After building columns for a resource, check if column count exceeds the threshold
- If it does, fall back to JSON-only schema (just id, data, synced_at)
- Log a warning message to stderr
- Add a constant
Let me implement this fix:
-
- Assistant
Let me continue reading the BuildSchema function to see the full column building logic.
- Assistant
Now I understand where to add the fix. Let me implement it. I'll add the column count check after the typed columns are built but before the FTS5 check. Here's my implementation plan:
- Add a constant
maxTypedColumns = 1500at the top of the file - Add an import for
fmtandosto support logging - After building typed columns (line 118), check if column count exceeds the threshold
- If it does, reset the table to JSON-only schema and log a warning
- Add a constant
- Assistant
Now let me add the constant for maxTypedColumns.
- Assistant
Let me see the area around lines 121-140 where FTS5 is set.
- Assistant
Now let me add the column count check between the column building and FTS5 logic.
- Assistant
Let me check if there's an indentation issue with line 121.
- Assistant
Let me look at the original indentation structure around this area more carefully.
- Assistant
Let me check the original file from git to understand the correct indentation.
- Assistant
I see the issue - I accidentally removed the closing brace for the
for _, temporalloop. Let me fix the indentation. - Assistant
Let me verify the changes compile properly.
- Assistant
Let me run the existing tests to make sure nothing is broken.
- Assistant
Now let me check the
schemaWithDependentParentsfunction to understand how it adds columns. - Assistant
Let me examine the schemaWithDependentParents function more closely.
- Assistant
Now I need to add a test to verify the fix. Let me create a test that validates the column count check.
- Assistant
Let me look at the end of the test file to see where to add the new test.
- Assistant
Now let me add a test for the column count check.
- Assistant
Let me check the current state of the file and fix the issues.
- Assistant
Let me run the new tests to see if they pass.
- Assistant
Let me check the file around line 537-545 to see the issue.
- Assistant
I see the issue - the new tests were inserted in the middle of a function. Let me fix this.
- Assistant
Let me look at the full TestBuildSchema_ColumnCapFallback function to see what's missing.
- Assistant
Let me fix the incomplete test function.
- Assistant
Let me run the tests now.
- Assistant
I need to add the
fmtimport to the test file. - Assistant
Let me run the tests again.
- Assistant
Let me run all BuildSchema tests to make sure nothing is broken.
- Assistant
Excellent! All BuildSchema tests pass. Now let me run the full test suite for the generator package.
- Assistant
The only failure is unrelated to my changes - it's a govulncheck issue with crypto/tls. All other tests pass. Let me verify my changes are correct by reviewing them.
- Assistant
Let me review the full diff of my changes.
- Assistant
Let me run the generator tests excluding the govulncheck test to confirm all other tests pass.
- Assistant
Let me also run a broader set of tests to ensure nothing is broken.
- Assistant
Let me run a final comprehensive test to ensure my changes are solid.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.