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 explore the repository structure to understand the codebase.
Assistant
I need to make sure I only send a single tool call. Let me combine my commands.
Assistant
Now let me find where the store.go is generated and how TableDef is consumed.
Assistant
Let me look at the store.go.tmpl template and how hasTypedTable works, plus the upsert batch dispatch. Let me find the templates directory.
Assistant
Let me look at the
hasTypedTablefunction and the upsert batch dispatch closely.Assistant
So
hasTypedTablereturns true whenlen(t.Columns) > 3. A JSON-only fallback table has exactly 3 columns (id, data, synced_at), sohasTypedTablewould return false. That's perfect - the existing template already gates onhasTypedTable, so if I make the fallback table have only 3 columns, the CREATE TABLE typed section, the typed Upsert, the FTS5, and the indexes would all be skipped.But wait - let me re-read the template. The CREATE TABLE section at line 274-278 gates on
hasTypedTable .. So if hasTypedTable is false (only 3 columns), the CREATE TABLE for that table would NOT be emitted at all! That means the table wouldn't exist in the DB. But the issue says "Resources exceeding the cap must retain their per-resource table but fall back to a JSON-only schema". So we need the table to still be created with id/data/synced_at.Let me look more carefully at the template to understand the gating. The issue: when hasTypedTable is false, no CREATE TABLE is emitted. But we want a CREATE TABLE with just id/data/synced_at for the wide resource.
Let me look at the full store.go.tmpl around the CREATE TABLE section and the UpsertBatch dispatch.
Assistant
Now let me look at the UpsertBatch dispatch section and the typed upsert section in the template.
Assistant
Let me look at the test files to understand the testing patterns.
Assistant
Now I understand the codebase. Let me look at the
schemaWithDependentParentsand how the store template dispatches. The key insight: thehasTypedTablefunction gates onlen(t.Columns) > 3. If a resource exceeds 1500 columns, I want it to fall back to JSON-only (just id/data/synced_at = 3 columns), which would naturally make return false, skipping typed CREATE TABLE, typed upsert, FTS, indexes.Assistant
Now I understand the full picture. Let me design the change:
- Add
JSONOnly boolfield toTableDef. - Add a constant
maxTypedColumns = 1500. - In
BuildSchema, after computing columns (and before adding FTS), check if the column count exceeds 1500. If so, reset the table to only base columns, clear indexes, setJSONOnly = true, and log.
But the column count includes dependent-parent columns added later in
schemaWithDependentParents. The evaluation contract says "including dependent-parent columns". So the check needs to happen AFTER dependent parents are added. ButBuildSchemais called byschemaWithDependentParentswhich then adds parent_id. Let me reconsider.The acceptance criteria mention "including dependent-parent columns". So I need to account for the parent_id column too. The cleanest place: do the check in
schemaWithDependentParents(which is what's passed torenderStoreFiles), OR do the check inBuildSchemaaccounting for a possible +1 parent_id column.Actually, let me check where
schemaWithDependentParentsis called and whetherrenderStoreFilesuses it.- Add
Assistant
Now let me understand the
hasTypedTablepredicate. The cleanest approach: apply the JSON-only fallback insideschemaWithDependentParentsafter dependent parents are added, so the column count includes the parent_id. Let me look at wherehasTypedTableis defined and consider addingJSONOnlyto the predicate.Let me check the spec package for
TypeField,Resource,Endpointsstructure to build a test.Assistant
Now I have enough understanding. Let me write a reproduction test first. Let me create a synthetic spec with a wide resource.
Assistant
Good, the build compiles except for the missing field. Now let me implement the fix. First, add the
JSONOnlyfield toTableDefand the threshold constant inschema_builder.go.Assistant
Now let me make the edits. First, add the
JSONOnlyfield and a threshold constant.Assistant
Now let me add the fallback logic in
BuildSchema. After computing columns and before FTS, check the column count. Let me view the relevant section now.Assistant
Now, the dependent-parent columns (parent_id) are added later in
schemaWithDependentParents. The evaluation contract says "including dependent-parent columns". So the check must happen after those columns are added.But
BuildSchemais the natural place for the column extraction. The dependent parent adds at most 1 column (parent_id) + 1 index. To keep things clean and account for the +1, I'll do the threshold check inschemaWithDependentParentsafter adding the parent_id, since that's where the final column count is known. ButBuildSchemais also called directly elsewhere (e.g.renderMCPToolFilesviaschemaWithDependentParents).Actually wait - let me check: is
BuildSchemacalled directly anywhere besidesschemaWithDependentParents?Assistant
BuildSchemais only called fromschemaWithDependentParents. So I have two options:Option A: Do the JSON-only check inside
BuildSchemaafter column extraction, but it won't know about the dependent-parent +1. To handle the "including dependent-parent columns" requirement, I could checklen(table.Columns) + 1 >= maxTypedColumnsfor dependent resources, but that's awkward.Option B: Do the JSON-only fallback in
schemaWithDependentParentsafter the parent_id is added, since that's where the final column count lives. This cleanly accounts for dependent-parent columns.Actually, the cleanest approach that respects the contract: Apply the fallback in
schemaWithDependentParentsafter the dependent-parent columns are added, iterating over all tables and applying the threshold to the final column count. This single pass handles both wide top-level resources and wide dependent resources.But
BuildSchemais what sets up FTS, indexes etc. The fallback inschemaWithDependentParentswould strip those. Let me apply the fallback there. Let me viewschemaWithDependentParents.Assistant
Now I'll think about the best design. The issue mentions the fallback should emit a generation-time log line. Let me check whether the generator has a logging mechanism.
Assistant
The generator uses
fmt.Fprintf(os.Stderr, ...)for warnings. I'll use that pattern. The schema_builder.go doesn't importfmtoros. Let me put the fallback + log inschemaWithDependentParents(which has access tofmt/osvia generator.go imports). Let me check generator.go imports.Assistant
Good,
fmtandosare imported in generator.go. Now I'll implement the fallback inschemaWithDependentParents. After the dependent-parent loop, I'll iterate over all tables and apply the threshold to the final column count, stripping typed columns/indexes/FTS and settingJSONOnly.Let me write the edit for
schemaWithDependentParents.Assistant
Wait, I used
\u2192(→) literal which won't render correctly in a Python f-string with the escaping. Let me check what got written.Assistant
The
\u2192is a Go string literal for the → character, which is fine — Go interprets\u2192as the Unicode arrow. But the issue example uses a literal →. That's fine functionally. However, let me reconsider — the issue says "store-fallback: control (3747 cols) → JSON-only". The\u2192escape works in Go. Let me verify it compiles. Now let me run the repro test.Assistant
The fallback is only applied in
schemaWithDependentParents, but my test callsBuildSchemadirectly. The test needs to be set and a generator instance.Assistant
schemaWithDependentParentsis a method on*Generator, so my test can't call it directly (it's lowercaseg.profilebut the method is exported... no,schemaWithDependentParentsis unexported). It's in the same packagegeneratorso the test CAN call it. Let me update the test to construct aGeneratorwith justSpecset (profile nil). The fallback loop runs regardless of profile.Let me update the repro test.
Assistant
The fallback fires and the arrow renders correctly. Now the negative test:
Assistant
Now I need to update the
hasTypedTablepredicate in generator.go to also exclude JSON-only tables, and update the store.go.tmpl to emit the CREATE TABLE for JSON-only tables (just 3 base columns, no indexes/FTS), while NOT emitting typed upsert methods or dispatch.Let me first update
hasTypedTableto exclude JSON-only.Assistant
The currently open file is schema_builder.go, but I need to edit generator.go. Let me use the --file option.
Assistant
The replace tool needs the file open. Let me open generator.go and navigate to line 408.
Assistant
Now I need to update the store.go.tmpl to emit the CREATE TABLE for JSON-only tables. Let me look at the CREATE TABLE block in the template and add a JSON-only branch.
Assistant
Now I'll add a JSON-only CREATE TABLE branch. After the typed table block (line 322
{{- end}}closeshasTypedTable), I'll add an{{- else if hasJSONOnlyTable .}}branch that emits the bare 3-column CREATE TABLE.Let me restructure the gating. Currently:
{{- range .Tables}} {{- if hasTypedTable .}} ... typed CREATE TABLE + indexes + FTS ... {{- end}} {{- end}}I'll change
{{- if hasTypedTable .}}...{{- end}}to include an{{- else if hasJSONOnlyTable .}}branch.Assistant
Now I need to check the
backfillColumnssection — it iterates over all table columns and emits backfill entries forisBackfillColumncolumns. For JSON-only tables (only 3 base columns),isBackfillColumnshould return false for the base columns. Let me checkisStoreBackfillColumn.Assistant
Good —
isBackfillColumnreturns false for id/data/synced_at, so JSON-only tables won't emit any backfill entries. That's fine.Now let me check the other templates that use
.Tablesto make sure JSON-only tables don't cause issues elsewhere. Let me check the store_schema_version_test.go.tmpl and store_upsert_batch_test.go.tmpl, plus the FTS search section and the upsert batch dispatch test.Assistant
Both test templates gate on
hasTypedTable, so JSON-only tables are excluded. Let me check the store_schema_version_test template section around 493 to understand what it does with columns.Assistant
This section gates on
hasBackfillColumns, which is false for JSON-only tables (no backfill columns). So no issue.Now let me check the store_upsert_batch_test.go.tmpl around lines 262-290.
Assistant
All gated on
hasTypedTable, so JSON-only tables are excluded from the typed upsert tests.Now let me check the FTS search section in store.go.tmpl (line ~1024 now shifted). It's gated on
.FTS5which is false for JSON-only. And the upsert method section (line ~790) is gated onhasTypedTable. Good.Now let me verify the whole thing compiles and run the existing schema_builder tests.
Assistant
Now let me run the full generator test suite to check nothing is broken.
Assistant
The failure is due to a
govulncheckgate detecting a Go stdlib vulnerability (crypto/tls in go1.26.4) — this is unrelated to my change (it's about the Go toolchain version). Let me confirm this is a pre-existing environmental issue by checking if this test also fails on the unmodified repo. Let me stash my changes and run just that test... actually, the govulncheck failure is clearly environmental (Go toolchain vuln, not my code). Let me verify by running a more targeted subset of generator tests that don't run govulncheck.Assistant
This is clearly an environmental issue — the Go toolchain (go1.26.4) has a known vuln that govulncheck flags, fixed in go1.26.5. This is unrelated to my change. Let me confirm by checking git stash to verify the same test fails without my changes.
Assistant
The build failed without my changes because the untracked
repro_wide_test.goreferencesJSONOnlywhich doesn't exist on the stashed version. Let me move that test out of the way temporarily to confirm the govulncheck failure is pre-existing.Assistant
Confirmed — the
govulncheckfailure is pre-existing and environmental (Go toolchain vuln), not caused by my change. The same test fails on the unmodified repo.Now let me run a broader set of generator tests that don't invoke govulncheck. Let me run all tests except the generate-quality-gate ones that run govulncheck. Let me run the schema_builder tests and a few store-related ones.
Assistant
All store-related tests pass. Now let me write a comprehensive end-to-end test that generates an actual store.go from a synthetic spec with a wide resource and verifies it has only 3 columns and that the generated store compiles and migrates. Let me look at an existing store generation test to understand the pattern.
Assistant
I understand the test pattern. Let me write a comprehensive end-to-end test that generates store.go with a wide resource and verifies the CREATE TABLE has only 3 columns, no typed upsert, and the store compiles. Let me add this to my repro test file.
Assistant
Let me look at how a test that compiles the generated CLI works (e.g. TestGenerateReservedWordResourceTableNamesCompileAndMigrate).
Assistant
Now let me write a full end-to-end test that generates a CLI with a wide resource, verifies the store.go has a 3-column CREATE TABLE for the wide resource, no typed upsert, and the generated store compiles and migrates. Let me find
runGoCommand.Assistant
Note:
runGoCommandskips build/test in-shortmode, andrunGoCommandRequiredskipsgo mod tidy. Let me write the e2e test. I'll model it on the reserved-word test. I need the wide resource to have enough fields to exceed 1500 but also have gravity >= 2 (so it would normally be typed). The 3000 scalar fields will produce gravity >= 2 (lots of fields, but text fields? need textFieldKeywords). Let me ensure gravity >= 2: with 3000 fields and 4+ endpoints... Actually gravity from epCount: only 1 endpoint (list) = +1. fields >= 10 → +2. textFields: need fields named title/name/etc. Let me include a "title" field so textFields >= 1 → +1. temporal: include created_at/updated_at → +2. fk: include a foo_id → +1. Total = 1+2+1+2+1 = 7 >= 2. Good, typed path engaged.Let me write the test.
Assistant
The second import block won't work — Go requires a single import block. Let me fix the test file to have all imports at top.
Assistant
Let me rewrite the entire test file cleanly with a single import block.
Assistant
go vetpasses. Now let me run the e2e test. It runsgo buildandgo test ./internal/storeon the generated CLI, which may take a while. Let me run it.Assistant
The build fails because of module resolution (
go build ./...can't find modules). This is becauserunGoCommandRequiredskipsgo mod tidy, so the generated module's go.mod isn't tidied. The reserved-word test uses the samerunGoCommandcalls and works in CI, but in this environmentgo mod tidyis skipped. The issue iscmd/widecfg-pp-mcp/main.goreferencingwidecfg-pp-cli/internal/mcp— the MCP module needs tidy.The MCP entrypoint is generated. The
go build ./...includes the MCP cmd which needsgo mod tidyto set up its own go.mod (the generated project has multiple modules). SincerunGoCommandRequiredskipsgo mod tidy, the build can't resolve modules in this sandboxed env.Let me check how the reserved-word test handles this — it passes in CI presumably because CI runs the full lane with network/module cache available. In this environment the module cache is restricted.
The key part of my acceptance test is the store.go content assertions. The build/migrate step is a bonus that may not work in this sandbox. Let me check: does the generated CLI have separate go.mod files for cli and mcp?
Assistant
Let me check whether the reserved-word build test actually passes in this environment — that tells me if the build step is feasible here at all.
Assistant
The reserved-word test passes, including
go build ./...andgo test ./internal/store. So the build step IS feasible in this environment. The difference: that test doesn't generate an MCP entrypoint (thedocstorespec has no MCP). Mywidecfgspec generates an MCP cmd (cmd/widecfg-pp-mcp) which is a separate module that needsgo mod tidy.Wait — the reserved-word test's
apiSpecdoesn't set MCP. Let me check what triggers MCP generation. TherunGoCommandRequiredskipsgo mod tidy. So the generated project must already have a valid go.mod that doesn't need tidy. But the MCP cmd needs its own go.mod withmcp-godependency.Let me check: does the reserved-word spec generate an MCP? Probably not. The issue is my spec generates MCP. Let me check what controls MCP generation —
VisionSet.MCPor similar.Assistant
MCP is always generated (
if g.VisionSet.MCP || true). So the reserved-word test ALSO generates an MCP cmd. Yet it passesgo build ./.... That means the generated project has separate go.mod files for the cli and mcp, andgo build ./...is run from the cli dir. Let me check the generated go.mod structure. Actually the error for my test wascmd/widecfg-pp-mcp/main.go:13:2: package widecfg-pp-cli/internal/mcp is not in std— this meansgo build ./...from outputDir includes the MCP cmd which is in a different module. But the reserved-word test passed...The difference might be: the reserved-word spec's MCP build worked because
go build ./...resolves relative to the main module's go.mod which includesinternal/mcp. Let me check the generated project's go.mod and whether MCP cmd has its own go.mod.Assistant
Can't use internal package from outside. Let me instead just inspect the generated output directly from a test by generating to a temp dir and inspecting the store.go. Actually, my e2e test already generates and asserts on store.go content — those assertions passed (the test got past the assertions to the
runGoCommandbuild step). The build step failed on module resolution for the MCP cmd.The reserved-word test passes
go build ./.... Let me check why. The difference must be thatgo build ./...is run fromoutputDirand the MCP cmd is atcmd/widecfg-pp-mcpwhich IS under outputDir, so./...includes it. For the reserved-word test it works. The errorpackage widecfg-pp-cli/internal/mcp is not in stdsuggests the MCP main.go's import pathwidecfg-pp-cli/internal/mcpisn't resolvable because the module path in go.mod doesn't match, OR the MCP cmd has its OWN go.mod making./...from the cli dir not cover it.Let me check: does the generated project have the MCP cmd under the SAME module or a separate go.mod?
Assistant
There's only ONE go.mod at the root. So
cmd/widecfg-pp-mcpis in the same module. The MCP main.go importswidecfg-pp-cli/internal/mcp. The module path must bewidecfg-pp-cli. Let me check the module path and the MCP main.go import.Assistant
The go.mod doesn't include
github.com/mark3labs/mcp-goin require (it's missing!). That's whygo build ./...fails on the MCP cmd — it needsmcp-gowhich isn't in go.mod, andrunGoCommandRequiredskipsgo mod tidy.But the reserved-word test (
docstore) passedgo build ./.... The difference: maybe the reserved-word test's go.mod DOES include mcp-go? Or maybe the docstore spec doesn't generate an MCP main that imports mcp-go?Actually wait — the reserved-word test passed. Let me check: does the docstore go.mod include mcp-go? The difference might be that the generation adds mcp-go to go.mod only when there are actual MCP tools. Let me check — the widecfg go.mod is missing mcp-go. This suggests the go.mod generation for widecfg didn't add mcp-go dependency, but docstore did.
Assistant
The mcp-go require is gated on
.VisionSet.MCP. My test setgen.VisionSet = VisionTemplateSet{Store: true}but did NOT setMCP: true. Yet MCP is always generated (if g.VisionSet.MCP || true). So the MCP cmd is generated but mcp-go isn't added to go.mod. That's the bug in my TEST setup, not the generator.The reserved-word test (
docstore) doesn't setVisionSetat all (usesNew+Generatewith default VisionSet). Let me check the default VisionSet — doesNeworGenerateset MCP? Let me check what the reserved-word test does: it just callsNew(apiSpec, outputDir)thengen.Generate(). So the default VisionSet must have MCP=true. My test overrode VisionSet with onlyStore: true, losing MCP.Let me fix my test to set
MCP: truetoo (or not override VisionSet and just set Store). Let me check the default VisionSet.Assistant
Generate()setsg.VisionSet = SelectVisionTemplates(plan). So the default VisionSet is computed. My test overrode it with{Store: true}losing MCP. The reserved-word test doesn't set VisionSet, so it gets the default (which includes MCP).The fix for my test: don't override VisionSet, OR set both Store and MCP. The simplest: set
gen.VisionSet = VisionTemplateSet{Store: true, MCP: true}. Let me check what fields VisionTemplateSet has.Assistant
Let me update my test to set
MCP: trueas well. Let me edit the test file.Assistant
The full e2e test passes — the generated store compiles and migrates against an empty DB. The
store-fallback: control (3007 cols) → JSON-onlylog line is emitted.Now let me run the full store-related test suite again to make sure nothing broke, plus the schema_builder tests.
Assistant
Now let me check the edge case mentioned in the contract: "Batch store generation must dispatch wide resources to the JSON-only path while preserving the existing typed behavior for ordinary narrow resources." The UpsertBatch dispatch switch (lines 981-984 area) gates on
hasTypedTable, so JSON-only tables won't be in the dispatch switch — items go to the genericresourcestable. That's correct.Let me also verify the dependent-parent edge case: a wide dependent resource that gets a parent_id column added, then exceeds the cap and falls back. The fallback loop runs after the parent_id is added, so it'll catch it. Let me also make sure the
sync_statetable isn't affected (it has 4 columns, way under cap). Good — excluded explicitly.Let me also double check: the threshold is
> maxTypedColumns(1500). A resource with exactly 1500 typed columns + 3 base = 1503 columns would NOT fall back (>1500 is false at 1500... wait 1500 is the column count, the check is i.e. >1500). So a table with 1501 columns falls back; 1500 stays typed. The contract says "Use 1500 columns as the safety cap" — meaning ≤1500 is safe, >1500 falls back. That matches .Assistant
All passing. Now let me remove my repro test file before submitting, since the instructions say not to add new tests to the repository.
Assistant
Now let me review the final diff of my source changes.
Assistant
The diff looks clean. Let me reconsider one edge case: the
\u2192escape in the Go string. In Go, within a double-quoted string literal,\u2192is a valid Unicode escape that produces the → character. The grep earlier showed it renders as→in stderr output (store-fallback: control (3007 cols) → JSON-only). Good.Now let me double-check that there are no other templates that iterate over
.Tablesand might break on JSON-only tables (e.g. vision templates, mcp tools). Let me search broadly.Assistant
search.go.tmpl: gates on.FTS5— JSON-only tables have FTS5=false, so excluded. Good.sync.go.tmpl: gates onhasTypedTable— JSON-only excluded. Good.share.go.tmpl: theColumnsreferences are onrows/entry(runtime), not.Tables. Good.
Let me verify the
search.go.tmplandsync.go.tmpldon't reference columns of JSON-only tables in a way that breaks. Let me look at the sync dispatch.Assistant
The sync dispatch gates on
hasTypedTable— JSON-only tables fall to thedefaultcase which callsdb.Upsert(resource, id, data)(the generic resources insert). Correct behavior.Now let me run the search/sync-related generated tests to confirm no breakage.
Assistant
Let me also run the broader
go vetandgo buildacross the project to make sure the source changes compile cleanly.Assistant
Everything compiles and vets cleanly. Let me also run the
go testfor the schema_builder package tests one more time to confirm the existing tests still pass (the ones that callBuildSchemadirectly and check typed columns for normal resources).Assistant
All tests pass. Let me do a final review of the complete changes once more and confirm the git status is clean of test files.
Assistant
Only the three source files are modified, no test files added. Let me do a final sanity build of the whole project once more.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.