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 and find the relevant files.
Assistant
Let me explore the generator templates store area.
Assistant
Let me open the store.go.tmpl file to see the full content.
Assistant
Let me see the key sections: the migrate section (around lines 256-322), and the upsert section (around 783-830+). Let me look at those.
Assistant
Now I understand the migrate section. Let me find the Go code that builds the
.Tablesdata model and the template helper functions.Assistant
Now I understand the structure. Let me look at the
hasTypedTablefunction and the generator template dispatch code more closely. Let me look at generator.go around lines 380-410.Assistant
Let me look at the UpsertBatch dispatch switch in the template (around line 783+) and the upsertTx functions.
Assistant
Let me look at how the generator emits log lines and check the rest of the template (FTS/populated tests).
Assistant
Let me find where BuildSchema is called and look at the rest of the template (populated tests, FTS).
Assistant
Let me find where
schemaWithDependentParentsis called.Assistant
Let me look at the populated-table tests template and the store_upsert_batch_test template.
Assistant
Let me check
domainUpsertMethodNameto understand which tables get typed upserts.Assistant
Now let me look at
columnNames,columnPlaceholders,updateSethelpers.Assistant
Let me find all uses of
hasTypedTablein templates and the populated-test logic, and check the FTS/search template usage.Assistant
Let me look at the sync.go.tmpl usage at line 1714.
Assistant
Let me look at the store.go.tmpl lines 980-1010 (the dispatch section) and line 936.
Assistant
Let me check vision/analytics templates that might reference typed columns or FTS, to ensure JSONOnly tables don't break them.
Assistant
The search.go.tmpl uses
.FTS5per-table (gated on.FTS5). Since JSONOnly tables have FTS5=false, they're skipped. Good. The sync.go.tmpl dispatch at 1714 useshasTypedTable— I'll change toisDomainTableso JSONOnly tables dispatch toUpsert<Pascal>.Let me check the search.go.tmpl more carefully - it iterates .Tables and checks
.FTS5. Let me verify it doesn't use hasTypedTable for anything that would break. Let me look at search.go.tmpl around 175-210.Assistant
Let me find all templates that iterate
.Tablesto make sure none reference typed columns unguarded.Assistant
Let me check store_schema_version_test.go.tmpl around 493.
Assistant
Now I have a complete understanding. Let me implement. First, let me modify
schema_builder.goto add theJSONOnlyfields, the cap constant, and the fallback helper.Assistant
Now let me add the
StoreColumnCapconstant andapplyJSONOnlyFallbackhelper at the end of schema_builder.go.Assistant
Now let me update
schemaWithDependentParentsin generator.go to apply the fallback after dependent-parent columns are added, and add theisDomainTabletemplate func + updatehasTypedTable.Assistant
Now add the log line in renderStoreFiles at the start of the
if g.VisionSet.Storeblock.Assistant
Now update the
hasTypedTabletemplate func to exclude JSONOnly, and add theisDomainTablefunc.Assistant
The indentation is slightly off; I'll run gofmt later. Now let me update the templates. First, the CREATE TABLE gate in store.go.tmpl (line 278).
Assistant
Now the upsertTx + Upsert generation block. Let me find its current line.
Assistant
Let me update the upsert generation gate (line 794) to
isDomainTable.Assistant
Now update the UpsertBatch dispatch section. Let me find the current line numbers.
Assistant
Let me view lines 1000-1025 to see the remaining
$hasTypedusage and the warning text.Assistant
Now let me apply the renames in store.go.tmpl:
$hasTyped→$hasDomain, and the two remaininghasTypedTablein the dispatch (lines 941, 987) →isDomainTable.Assistant
Now update sync.go.tmpl dispatch (line 1714) from
hasTypedTabletoisDomainTable.Assistant
Now let me run gofmt on generator.go and build the generator package.
Assistant
Build succeeds. Now let me write a reproduction script to confirm the fix. First, let me examine an existing generator test to understand the test harness.
Assistant
Let me look at how a typed-table test builds a spec with response types, to model my reproduction. Let me look at TestGenerateStoreUpsertBatchDispatchesToTypedTable.
Assistant
Now let me create a temporary reproduction test in the generator package to verify the fix (positive + negative).
Assistant
Let me set up persistent env and run the test (build first).
Assistant
go vetpasses. Now let me run my reproduction tests.Assistant
The fix works (store-fallback log emitted, narrow test passes). My test assertions about counting are off. Let me inspect the actual generated control block.
Assistant
Let me adjust the repro test to log the relevant blocks so I can inspect the actual format.
Assistant
Let me open the repro test and add a log line for the block.
Assistant
The control table has exactly 3 columns as intended. My assertions were just wrong. Let me view and fix them.
Assistant
Now re-run the wide test.
Assistant
Both pass, including the migrate (
go test ./internal/store) step. Now let me run the existing store/typed-table generator tests to ensure no regressions. Let me list relevant test names first.Assistant
All pass. Now let me find and run a golden test to ensure narrow-spec output is byte-identical.
Assistant
Important: I changed the
upsert<X>Txdoc comment, which would alter generated output for ALL typed resources and break golden tests. Let me restore the original comment verbatim and add the JSON-only note only conditionally.Assistant
Now let me re-run the repro tests to confirm they still pass after restoring the comment.
Assistant
Now let me build the CLI binary and run the golden verification suite to confirm byte-identical narrow-spec output.
Assistant
Let me run the full golden verification suite.
Assistant
Many golden failures across unrelated files (main.go, types.go, README.md, stdout.txt) — these may be pre-existing environment diffs. Let me check the one store.go diff (sync-walker) which is most likely affected by my change.
Assistant
The diff is only the
<REPO>path-normalization artifact (repo dir namecli-printing-presscollides with the URL suffix), not my change. Let me confirm the full store.go diff has no other hunks, and verify these failures are pre-existing by stashing my changes.Assistant
Let me confirm these failures are pre-existing (environmental) by stashing my changes, rebuilding, and re-running golden verify.
Assistant
Confirmed: the 16 golden failures are pre-existing environmental failures (the
<REPO>path-normalization artifact), present both with and without my changes. Let me restore my changes.Assistant
Both runs show 16 pre-existing environmental failures. Let me verify the sync.go golden diffs (my other template change) are only the
<REPO>artifact, not my dispatch change.Assistant
Let me capture the failing case set from the baseline run (current
.gotmp), then re-run with my changes and compare to confirm no new failures.Assistant
Let me re-run golden verify with my changes and capture the failing cases for comparison.
Assistant
Now let me run the baseline (stashed) failing cases and diff against my-changes set.
Assistant
Identical failing sets — my changes introduce zero new golden failures. Let me restore my changes.
Assistant
My changes are restored. Let me run the generator package tests in short mode first (fast lane).
Assistant
The failure is a pre-existing
govulncheckgate (Go 1.26.4 stdlib crypto/tls vuln) unrelated to my change. Let me re-run short mode skipping that env-dependent test.Assistant
Let me see the actual failing test (filter out warnings).
Assistant
Two failures in
validate_test.goabout go build cache dir — let me check whether these are pre-existing/environmental.Assistant
These
goBuildCacheDirfailures look environment-related (HOME not concretely set). Let me check HOME and re-run those two tests with a concrete HOME.Assistant
HOME is empty — that's the cause. Let me set a concrete HOME and re-run those two env-sensitive tests.
Assistant
Those were env-related (HOME empty). Now let me re-run the full generator short suite with proper HOME, skipping the env-dependent govulncheck gate.
Assistant
All short tests pass. Now let me run a focused set of the heavy compile/run store+sync tests (non-short) to be thorough.
Assistant
All pass. Let me add a mixed-spec sanity check (narrow typed + wide resource coexisting) to my repro to confirm both paths coexist and compile.
Assistant
Let me fix a nonsensical assertion line I added.
Assistant
The whitespace in my hardcoded assertion is wrong. Let me simplify the mixed-test assertions to robust substrings.
Assistant
The mixed-spec test passes. Let me run all three repro tests together to confirm.
Assistant
All repro tests pass. Now let me remove the temporary repro test and clean up build artifacts before submitting.
Assistant
Let me do a final review of the complete diff.
Assistant
The diff is clean. Let me do a final gofmt + build + vet check.
Assistant
Let me confirm no vision/MCP templates iterate
.Tablesin a column-sensitive way.Assistant
Let me check how
share.go.tmplbuildsmanifest.Tablesentries (line 236 area).Assistant
share.go.tmpluses a runtime manifest (manifest.Tablesfrom live DB columns), not the generator schema — safe. All checks pass. Let me do a final git status confirmation.Assistant
Let me do a rigorous pre-fix reproduction to confirm the original "too many columns" failure, then verify the fix resolves it. I'll recreate a minimal repro test, run it against stashed (pre-fix) code, then against my fix.
Assistant
Confirmed the pre-fix failure:
migration failed: SQL logic error: too many columns on control (1)— exactly the issue's reported error. Now let me restore my fix and re-run to confirm resolution.Assistant
Post-fix passes. Let me capture the post-fix log line and store size for confirmation.
Assistant
Pre-fix (560KB store.go,
too many columnsmigration failure) vs post-fix (45KB store.go, 3-col JSON-only table, migrate succeeds,store-fallback: control (3003 cols) → JSON-onlylog) — fully confirmed. Let me clean up the temp test and do a final status check.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.