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
Let me analyze the issue:
- The typed-table emit path generates one column per leaf JSON field with no upper bound
- On wide config singletons (like
/Controlwith 3747 columns), this exceeds SQLite's 2000 column limit - The fix should:
- Compute column count before writing CREATE TABLE
- If count > 1500, fall back to JSON-only schema (id, data, synced_at)
- Emit a log line for the fallback
- Preserve typed columns below threshold
Let me start by exploring the repository structure.
Assistant
Let me look at the generator templates for store/CREATE TABLE:
<tool_call> <function=bash_terminal> <parameter=command> find /cli-printing-press -type f -name "*.go" | grep -i template | grep -i store </tool_call>
Assistant
Let me look for the generator templates directory mentioned in the issue.
Assistant
Good, let me look at the templates directory structure.
Assistant
The key file is
/cli-printing-press/internal/generator/templates/store.go.tmpl. Let me look at it.Assistant
Let me see the full template, especially the CREATE TABLE part:
Assistant
The file has 1390 lines. Let me look at the parts around CREATE TABLE statements. I need to find where the CREATE TABLE is generated and where columns are emitted.
Assistant
Let me look at the CREATE TABLE for individual tables around line 279:
Assistant
Let me look at the generator code to understand the data structure:
Assistant
Let me look at the schema_builder.go and generator.go files to understand how tables and columns are structured.
Assistant
Let me look at the helpers template and the generator to understand how template functions are wired up:
Assistant
Now I need to understand how
hasTypedTableis defined and used. Let me look at the generator.go to see how the template functions are registered and how the TableDef data is built.Assistant
Let me look at the generator.go file around line 402 to understand how hasTypedTable is defined:
Assistant
Now let me understand the full flow. Let me look at how Upsert methods relate to tables:
Assistant
Let me look at the domainUpsertMethodName function to understand how typed tables are determined.
Assistant
Now I understand the structure. Let me look at where BuildSchema is called to understand the generation flow:
Assistant
Now I understand the flow. Let me look at the UpsertBatch template to see how the typed table check works:
Assistant
Assistant
The environment seems to have had an issue. Let me try again.
Assistant
Let me continue examining the code.
Assistant
Assistant
I need to invoke a tool call. Let me try the bash command properly.
Assistant
Let me check what Go environment variables are available.
Assistant
The environment seems to have some issues with Go setup. Let me check what environment is available.
Assistant
HOME is not set. Let me set it and try again.
Assistant
Good, all existing tests pass. Now let me understand the full picture and implement the fix. Let me first look at the
TableDefstruct and how it's used in the template:Assistant
Now let me look at the specific places in the template where
.Columnsand.FTS5are used to understand all the gated logic:Assistant
Now I have a clear understanding. Let me implement the fix:
- Add a
JSONOnlyfield toTableDef - In
BuildSchema, check if column count exceeds 1500 and handle wide tables - In the template, emit a minimal CREATE TABLE for JSONOnly tables
- Emit a generation-time log line
Let me start by modifying the schema_builder.go:
- Add a
Assistant
Now I have a clear understanding of the code. Let me implement the fix step by step.
Step 1: Add a
JSONOnlyfield toTableDefin schema_builder.goAssistant
Now let me implement the fix. I'll start by modifying the schema_builder.go to add the JSONOnly field and handle wide tables:
Assistant
Now I have a clear understanding. Let me implement the fix step by step.
Step 1: Add
JSONOnlyfield toTableDefand handle wide tables inschema_builder.go:Assistant
Let me verify the changes and then update the template to handle JSONOnly tables.
Assistant
Let me verify the wide-table guard was added and check the full BuildSchema function:
Assistant
Good, let me verify the rest of the wide-table guard was added.
Assistant
Now I need to update the template to handle JSONOnly tables. The key changes are in the migration SQL section where CREATE TABLE is emitted:
Assistant
Now I need to update the template to handle JSONOnly tables. The current template only emits CREATE TABLE when
hasTypedTableis true, but for JSONOnly tables we need a minimal CREATE TABLE.Assistant
Now I need to update the template to handle JSONOnly tables. Let me replace the migration section to add JSONOnly support:
Assistant
Let me verify the template changes:
Assistant
Let me verify the changes are complete and check all the template sections that reference tables:
Assistant
Good, the template changes look correct. Now let me verify the
hasTypedTablefunction properly handles JSONOnly tables (it checkslen(t.Columns) > 3, which will be false for JSONOnly tables with exactly 3 columns):Assistant
The
hasTypedTablecheckslen(t.Columns) > 3. For JSONOnly tables, we keep only 3 base columns, so this returns false - which is correct. No typed Upsert, indexes, or FTS for these tables.Now let me build and test:
Assistant
Build succeeded. Now let me run the existing tests:
Assistant
There's a template parsing error on line 293. The issue is that Go templates don't support
.Columns[0]syntax directly. I need to use theindexfunction instead.Assistant
I need to fix the template syntax. Go templates don't support
.Columns[0]- I need to use theindexfunction instead. Let me check ifindexis available in the template function map:Assistant
The
indexfunction is a built-in Go template function, so it should be available. Let me fix the template to use proper syntax:Assistant
I made a typo - let me fix that:
Assistant
There's a typo - I created a wrong file. Let me fix this.
Assistant
Let me check the available template functions and fix the template properly:
Assistant
Let me check what functions are available in the template and fix the template properly.
Assistant
I need to understand what template functions are available and how to properly index slices. Let me check the template functions:
Assistant
The
indexfunction is a built-in Go template function, but I need to check if it works with the way the template is structured. Let me look at how the template currently accesses fields from loop variables:Assistant
Good - the
indexfunction is already used in the templates. Let me fix the template properly:Assistant
Let me verify the changes and also fix the Primary Key handling.
Assistant
I see the sed command created double-quoted nested quotes. Let me fix this properly:
Assistant
Let me fix the Python script syntax error with the triple quotes.
Assistant
Let me verify the fix:
Assistant
Now let me run the tests again to verify the fix:
Assistant
Build passes. Now let me run the tests:
Assistant
The error says
safeSQLNameis not defined as a template function. Looking at the generator, the function is registered assafeName(line 389 in generator.go). Let me fix the template to usesafeNameinstead:Assistant
Good, I replaced
safeSQLNamewithsafeNamein the template. Let me verify the fix and run the tests:Assistant
Wait, there's a problem. The
safeNamefunction in the template map takes a single argument, but I'm using a pipe (index .Columns 0 | safeName). Let me check if this works. In Go templates, the pipe passes the output of the left side as the last argument to the right side. So{{index .Columns 0 | safeName}}should work - it takesindex .Columns 0(which returns a ColumnDef struct) and passes it tosafeName.But wait,
safeNameissafeSQLName, which takes a string. Let me check whatsafeSQLNamedoes:gofunc safeSQLName(name string) string { return `"` + strings.ReplaceAll(name, `"`, `""`) + `"` }It takes a string name and returns it quoted. But I'm passing a ColumnDef struct to it. That won't work.
Let me look at how other templates handle this. Looking at the original CREATE TABLE code:
Assistant
Let me fix the template to use the correct syntax.
Assistant
Let me verify the fix and run the tests:
Assistant
Let me verify the fix and run the tests:
Assistant
Now let me run the tests again:
Assistant
The test failure is about a Go standard library vulnerability (GO-2026-5856), not related to my changes. All the relevant generator tests pass. Let me run the schema builder tests specifically:
Assistant
All schema builder tests pass. Now let me add a test to verify the wide-table fallback behavior works correctly. Let me look at existing tests for reference:
Assistant
Now I need to create a test for the wide-table fallback. Let me look at how findTable works and then add a test.
Assistant
Let me add a test for the wide-table fallback:
Assistant
Now let me run the new tests to verify the fix works:
Assistant
I need to add the
fmtimport to the test file.Assistant
I need to add the
fmtimport to the test file.Assistant
Let me run the new tests to verify the fix works.
<tool_call> <function=bash_terminal> <parameter=command> export HOME=/root && export GOPATH=/root/go && export GOMODCACHE=/root/go/pkg/mod && export GOCACHE=/root/.cache/go-build && cd /cli-printing-press && go test ./internal/generator/ -run "TestBuildSchema_WideTableJSONOnlyFallback|TestBuildSchema_NormalTableUnchanged" -v 2>&1 </tool_call>
Assistant
Let me run the new tests to verify the fix works.
Assistant
Both new tests pass. Let me run all the schema builder tests to make sure nothing is broken:
Assistant
All schema tests pass. Let me verify the build works and run a broader set of tests:
Assistant
Good. Let me run the store-related tests to make sure everything works:
Assistant
All tests pass. Now let me also add the generation-time log line as required by the issue. Let me find where
BuildSchemais called:Assistant
Now I need to add a log line when a wide table is detected. Let me look at the code around line 2442.
Assistant
Let me add a generation-time log line when a wide table is detected. I'll add it right after
BuildSchemais called:Assistant
Let me add a generation-time log line when a wide table is detected. I'll add it right after
BuildSchemais called:Assistant
Let me verify the changes and run the build:
Assistant
The string literal got split across lines incorrectly. Let me fix it:
Assistant
The string literal got broken across lines. Let me fix it:
Assistant
Let me verify the changes and run the build:
Assistant
Let me run the build:
Assistant
Build succeeded. Let me run the tests:
Assistant
All tests pass. Let me now verify the complete fix by reviewing all the changes made:
Assistant
Let me review all the changes:
Assistant
The fix looks correct. Let me run all the generator tests one more time to make sure everything passes:
Assistant
All generator tests pass except
TestGenerateWithNoAuthwhich fails due to a Go standard library vulnerability (GO-2026-5856) - completely unrelated to my changes. Let me verify by running only the tests directly affected by my changes:Assistant
All tests pass. Let me also run
go vetto ensure code quality:Assistant
The fix is complete. Let me summarize what was implemented:
Summary of Changes
1.
internal/generator/schema_builder.go- Added
MaxTableColumns = 1500constant as the safety cap (1500 leaves headroom under SQLite's default 2000 column limit) - Added
JSONOnly boolfield toTableDefstruct to flag wide tables - Added wide-table guard in
BuildSchema(): when column count exceedsMaxTableColumns, strips all typed columns and keeps only the 3 base columns (id, data, synced_at), resets indexes/FTS5/FTS5Triggers, and setsJSONOnly = true
2.
- Added
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.