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 look at the internal/generator and internal/store directories specifically.
- Assistant
Let me find the store-related files.
- Assistant
Let me explore the internal/generator directory.
- Assistant
Let me look at the templates directory:
- Assistant
I see
store.go.tmpl- that's likely the key file. Let me open it. - Assistant
Let me look at the full file, focusing on the CREATE TABLE logic:
- Assistant
I see that line 279 is the template for creating resource-specific tables. Let me look at the code around there to understand how the column generation works.
- Assistant
Now let me look at how the tables and columns are defined in the generator code:
- Assistant
Let me look at the
hasTypedTablefunction and theTableDefandColumnDeftypes: - Assistant
Let me search for TableDef more broadly:
- Assistant
Let me look at the schema_builder.go file:
- Assistant
Let me see the rest of this function:
- Assistant
Now I understand the issue. The
BuildSchemafunction adds columns for each leaf field without checking if the total column count exceeds SQLite's limit. The fix should be inBuildSchemato check if the column count exceeds 1500 and fall back to the base columns (id, data, synced_at) if it does.Let me look at how
hasTypedTableis used to understand what else might need to change: - Assistant
Let me look at the
hasTypedTablefunction more closely: - Assistant
Now I need to understand how logging works in this codebase:
- Assistant
Let me check how the log/fmt is used elsewhere:
- Assistant
Let me look at the imports in schema_builder.go to see what's available:
- Assistant
Let me check if there are any existing tests for schema_builder.go:
- Assistant
Let me look at the full test file to understand what tests exist:
- Assistant
Let me continue reading the test file:
- Assistant
Let me now understand the full schema_builder.go structure:
- Assistant
Let me read the full schema_builder.go file:
- Assistant
Let me check how the existing tests are structured and what imports they use:
- Assistant
Let me check the test for how it structures the spec and look at the end of the test file:
- Assistant
Let me look at the sync.go.tmpl to understand how the dispatch works for typed tables vs generic tables:
- Assistant
Let me look at the UpsertBatch dispatch in the store template:
- Assistant
Let me look at the UpsertBatch function to see how it dispatches:
- Assistant
Now I understand the issue! Let me look at the full UpsertBatch to understand the dispatch:
- Assistant
Now I have a good understanding. Let me look at how
hasTypedTableis used in the sync template: - Assistant
Now let me look at how
hasTypedTableis used in the UpsertBatch and Upsert functions in store.go.tmpl: - Assistant
Now I have a complete understanding of the architecture. Let me look at how the sync template dispatches:
- Assistant
Let me check how
schemaWithDependentParentsworks: - Assistant
Let me look at the
upsertGenericResourceTxmethod: - Assistant
Now I have a complete understanding of the architecture. Let me summarize:
BuildSchemainschema_builder.gogeneratesTableDefwith columns for each resourcehasTypedTablein the template checkslen(t.Columns) > 3to decide if a table gets typed CREATE TABLE + typed upsert- If
hasTypedTableis false, the table is not created in migrations and data goes only to the genericresourcestable - The issue is that
BuildSchemacan produce tables with 3747+ columns, exceeding SQLite's 2000 column limit
The fix: In
BuildSchema, after building columns, check if count exceeds 1500. If so, truncate to base columns (id, data, synced_at), clear indexes and FTS, and log the fallback. This wayhasTypedTablereturns false naturally, and the data goes to the genericresourcestable.Let me first look at the test infrastructure to understand how to write tests:
- Assistant
Let me look at the findTable function:
- Assistant
Now I have a complete understanding. Let me implement the fix. The approach:
- In
BuildSchemainschema_builder.go, add a constant for the column cap (1500). After adding typed columns, check if the count exceeds this cap. If so, truncate to base columns, clear indexes and FTS, and log the fallback.
Let me implement this:
- In
- Assistant
Now let me implement the fix. First, let me add the constant and imports:
- Assistant
Now let me add the constant and the column count check:
- Assistant
Now I need to add the column count check. Let me look at the area where I need to add it:
- Assistant
Now I'll add the column count check between the gravity block and the FTS5 check:
- Assistant
Good. Now let me verify the file compiles:
- Assistant
Let me check the Go environment:
- Assistant
Let me check the go.mod and set up the environment properly:
- Assistant
Let me try a different approach:
- Assistant
Let me set up the Go environment properly.
- Assistant
Good, it compiles. Now let me add tests. Let me look at the test file structure:
- Assistant
Now let me add the test for the wide column fallback. I'll add it before the
findTablehelper: - Assistant
Now let me add the test for the wide column fallback. I'll add it before the
findTablehelper: - Assistant
I need to add
fmtto the test imports since the new tests usefmt.Sprintf: - Assistant
Now let me add
fmtto the imports: - Assistant
Good. Now let me run the tests to make sure they pass:
- Assistant
All4 new tests pass. Now let me run the full test suite to make sure I didn't break anything:
- Assistant
The only failure is
TestGenerateWithNoAuthwhich fails due to a pre-existing govulncheck issue (GO-2026-5856 - TLS vulnerability in Go standard library). This is unrelated to my changes. Let me verify this was pre-existing: - Assistant
Good - the govulncheck failure is pre-existing (Go 1.26.4 TLS vulnerability). Let me run just the schema_builder tests to confirm:
- Assistant
All tests pass. Let me run the full test suite excluding the govulncheck failure to confirm nothing else is broken:
- Assistant
Let me try a different approach to filter out the test:
- Assistant
Let me now verify that the
hasTypedTablefunction correctly handles the JSON-only fallback by checking the generated code behavior. Let me check the existing tests that test store generation: - Assistant
Let me check if that's the only failure by running a broader set of tests excluding the govulncheck ones:
- Assistant
Hmm, the regex doesn't work well. Let me try a different approach.
- Assistant
Let me verify the full test suite by running tests that exercise the store template generation (these are the ones most likely to be affected by my changes):
- Assistant
All store-related tests pass. Let me also run the full generator test suite to confirm no other failures (excluding the pre-existing govulncheck issue):
- Assistant
The only failure is the pre-existing
TestGenerateWithNoAuthgovulncheck issue. All other tests pass. Let me also run the broader tests: - Assistant
Let me verify the golden tests pass too:
- Assistant
All tests pass. Now let me verify the final state of my changes:
- Assistant
Let me check if there's a proper newline before the
findTablefunction: - Assistant
I notice there's a missing newline between line 739 and line 740. Let me fix that:
- Assistant
Good, the formatting is fixed. Let me run the tests one more time to confirm everything is clean:
- Assistant
Let me run the complete test suite one more time to confirm:
- Assistant
The only failure is the pre-existing
TestGenerateWithNoAuthgovulncheck issue. All other tests pass.Let me do a final review of my changes:
- Assistant
Let me verify the final diff one more time:
- Assistant
The diff looks correct. Let me now run the full test suite one final time to confirm:
- Assistant
Let me try again with proper grep syntax:
- Assistant
No failures other than the pre-existing govulncheck issue. Let me verify the complete summary:
- Assistant
The only failure is the pre-existing govulncheck issue. Let me also run
go vetto make sure the code is clean: - Assistant
Everything looks good. Let me now do a final review of the changes and create my submission:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.