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
Now let me understand where
Tablesdata comes from — how.Tables,.Columns,hasTypedTable, etc. are populated. Let me find the Go code that drives this template.Assistant
Now I understand the schema building. The key place is
BuildSchema. When gravity >= 2, columns are added. I need to add a threshold check: if the column count exceeds 1500, fall back to JSON-only schema (just baseTableColumns, no indexes, no FTS5).Let me look at how
hasTypedTableworks and what determines the upsert. The issue says: "do not generate typed-column indexes, FTS structures, or typed upsert code for that fallback table."Let me look at the
hasTypedTablefunction and the upsert generation.Assistant
Now let me look at the rest of schema_builder.go to understand sub-resource and dependent-parent column addition.
Assistant
Let me check where dependent-parent columns are added (generator.go ~2453):
Assistant
Now let me check how the generator logs messages (for the generation-time log line).
Assistant
Let me find where
schemaWithDependentParentsis called:Assistant
Assistant
The MCP tools use the schema but probably just for counts/descriptions. The cap should be applied consistently so both paths see the JSON-only fallback. The simplest clean approach: apply the cap inside
schemaWithDependentParents(after parent_id), and only emit the log line once. To avoid double logging, I'll guard with a Generator fieldstoreFallbackLogged. ButschemaWithDependentParentsis a method on*Generator, so it has access to g. Let me check the Generator struct fields.Actually, let me reconsider: is double-logging actually bad? The two calls happen at different generation phases. It's a minor cosmetic issue. But cleaner to log once.
Let me look at the Generator struct to add a field, or better — I'll apply the cap only once. Since
schemaWithDependentParentsis called twice with identical fresh computation, I could memoize the result. But that changes behavior.Simplest robust: apply the cap inside
schemaWithDependentParentsand dedupe the log using amap[string]boolfield on Generator. Let me check the Generator struct.Assistant
Now let me look at the store template's upsert batch dispatch and sync code to understand how resources are routed:
Assistant
Now let me look at the UpsertBatch function to see the dispatch.
Assistant
Assistant
Now I understand the full structure. Let me check whether any golden/test files assert on the "typed-table upsert failed" warning text, before I consider changing it.
Assistant
Let me look at the backfillColumns section and the search.go.tmpl to understand FTS gating and any other places that iterate tables/columns:
Assistant
Let me check the
hasTypedTableusage in sync.go.tmpl and other templates, plus the upsert batch test template:Assistant
The store_upsert_batch_test.go.tmpl uses
hasTypedTableto gate per-resource tests. For JSONOnly tables,hasTypedTableis false, so those tests won't be generated for JSONOnly tables. That's consistent with the contract (no typed upsert code/tests for fallback tables). Good — but should there be a test that JSONOnly tables get populated? The contract acceptance criteria mentions "sync against an empty DB succeeds" — that's runtime, not a generated test. I won't add tests (forbidden).Now, the data_source.go.tmpl calls
UpsertBatchgenerically — that's fine, the dispatch handles JSONOnly.Now let me check sync.go.tmpl to see if it calls typed
Upsert<X>directly anywhere.Assistant
Assistant
OK so single-object responses go through UpsertBatch too (line 263). So the batch dispatch handles JSONOnly. But what about the sync.go.tmpl
upsertSingleObjectfunction (line 1698)? Let me check where that's called in sync.go.tmpl. It callsdb.Upsert<X>for typed, elsedb.Upsert. Let me check where upsertSingleObject is called.Assistant
Assistant
Now I have a clear picture. Let me implement the changes. First, the
TableDef.JSONOnlyfield, the constant, and the cap helper in schema_builder.go:Assistant
Now add the constant and the
applyStoreColumnCaphelper. Let me add it afterbaseTableColumns:Assistant
Now update
schemaWithDependentParentsin generator.go to apply the cap (with caching to avoid duplicate work/logging) and add the cache field to Generator:Assistant
Now update
schemaWithDependentParentsto apply the cap and cache:Assistant
The replace command says "Text not found in displayed lines" — it seems the editor only matches text within the displayed window. Let me navigate to the line and use edit instead.
Assistant
Now update
hasTypedTableto explicitly exclude JSONOnly tables for robustness:Assistant
Now let me update the store.go.tmpl template. First the migrate CREATE TABLE block:
Assistant
I'll add a
{{- else if .JSONOnly}}branch for the JSON-only CREATE TABLE. Let me edit the block:Assistant
Now let me add the JSON-only upsert helpers and update UpsertBatch. Let me view the area around the typed upsert section and UpsertBatch:
Assistant
Let me view the UpsertBatch section now (line ~873+).
Assistant
Now I'll add the JSON-only helper methods. Let me insert them after the typed upsert range:
Assistant
I accidentally removed the first two comment lines of
resourceIDFieldOverrides. Let me fix that:Assistant
I duplicated the comment block. Let me remove the duplicate lines 934-941:
Assistant
Good, the comment block is now correct. Now let me update the UpsertBatch dispatch. First, the
$hasTypedflag computation block:Assistant
Now I need to change the
$hasTypedreferences in the UpsertBatch body to$hasDispatch. Let me update lines 1010-1011:Assistant
Now update the savepoint block gate and the dispatch switch:
Assistant
Now update the trailing warning gate (line 1076) to
$hasDispatch:Assistant
Now let me update the sync.go.tmpl
upsertSingleObjectto add the JSONOnly case:Assistant
Now let me build the generator package to check for compile errors:
Assistant
No GOMODCACHE/GOPATH set. Let me check if there's a vendored module dir or how the repo is set up. Let me check go.mod and whether there's a vendor directory.
Assistant
The generator package builds. Now let me run the existing generator tests to make sure nothing broke (especially schema_builder tests and golden tests):
Assistant
The only failure is
TestGenerateWithNoAuthdue to a govulncheck vulnerability in the Go standard library (crypto/tls@go1.26.4, fixed in go1.26.5) — an environment/toolchain issue unrelated to my change. Let me verify this test fails the same way on the original code (pre-existing) and run the relevant tests:Assistant
Confirmed:
TestGenerateWithNoAuthfails on the original code too (govulncheck stdlib vuln) — pre-existing environment issue, not caused by my changes.Let me run the schema_builder and store-related tests specifically:
Assistant
Let me run a broader set of golden tests to confirm my template changes don't break existing golden generation:
Assistant
Let me find the actual golden test harness. There's
testdata/golden/expected/. Let me search for the test that regenerates and compares against golden.Assistant
Let me look at how the generator tests construct specs to build a reproduction test:
Assistant
I now understand the spec structure. Let me look at an existing generator test that does full generation to model my reproduction:
Assistant
Now let me look at the
Generate()method to understand what it produces:Assistant
Let me check the default VisionSet and profile setup:
Assistant
So
prepareOutputsets up the profile and VisionSet. Let me check whetherStoreis enabled by default in the vision set:Assistant
Store is enabled based on the profiler's plan. For a synthetic spec with a wide resource, the profiler might or might not enable Store. Let me check
constrainVisionTemplates:Assistant
constrainVisionTemplatesonly adjusts Export. So if I set VisionSet.Store=true, it stays. Good.Now let me write a reproduction test. First, let me check the generated store's
Opensignature so I can test migration against an empty DB:Assistant
Good.
store.Open(dbPath)runs migrate. Let me check the generated go.mod to understand the module path and sqlite dependency for my reproduction:Assistant
Let me check the
modulePathtemplate func to know the generated module path:Assistant
naming.CLI(s.Name)is the module path. Now let me write a reproduction test:Assistant
Now let me add the
runMigrateCheckhelper that builds and runs a small program against the generated store:Assistant
I need to add
os/execto the imports:Assistant
Progress! The
store-fallback: control (3003 cols) → JSON-onlylog line is emitted. But the negative test failed: "items" didn't get typed columns. Let me checkdomainUpsertMethodName— "items" may map to UpsertBatch:Assistant
So
domainUpsertMethodName("items")= "UpsertItems" ≠ "UpsertBatch", so hasTypedTable should be true. Let me inspect what actually got generated foritems. Let me checkrenameActiveFrameworkResourceCollisions:Assistant
The columns are emitted as
"title" TEXT(safeName-quoted), so my substringtitle TEXTdoesn't match. Let me fix the assertion:Assistant
The reproduction test passes. Now let me verify I haven't broken existing behavior. Let me run the full generator test suite (excluding the known-failing govulncheck env test) and compare to baseline:
Assistant
There's a FAIL but I need the specific test name. Let me find it:
Assistant
Two failures:
TestGoBuildCacheDirIsSharedandTestGoBuildCacheDirPath. These are about the go build cache dir — unrelated to my changes. Let me verify they fail on baseline too:Assistant
Both failures are pre-existing environment issues (
$HOME is not defined). Let me confirm by setting HOME:Assistant
Confirmed environmental. Let me run the full generator suite with HOME set, skipping only the govulncheck env test:
Assistant
All generator tests pass. Let me check for golden-verification tests that regenerate and compare against
testdata/golden/expected:Assistant
Let me find the golden harness — there's likely a
scripts/golden.sh:Assistant
The golden harness is a shell script that builds the binary and regenerates each golden case, diffing against
testdata/golden/expected. This is the strongest verification that I didn't break normal-spec generation. Let me run it. First build the binary:Assistant
jq isn't available. Let me try to get a static jq binary:
Assistant
Many failures are in files I didn't touch (main.go, types.go, README.md, mcp/tools.go). Let me first check the store.go diff (the file most relevant to my change), then compare against baseline:
Assistant
The store.go diff is purely a normalization artifact (
cli-printing-press→<REPO>substituting inside the URL because the repo dir is namedcli-printing-press). Let me confirm there are no content differences beyond that normalization artifact:Assistant
The ONLY diff in store.go is the normalization artifact. This
<REPO>substitution clobberscli-printing-presseverywhere it appears (URLs, repo name), which is why many unrelated files "fail". Let me confirm every failing diff is only this artifact, by sampling several:Assistant
The grep filtered out
<REPO>/cli-printing-presslines and NO other content lines appeared for any diff — confirming every diff is purely that normalization artifact. Let me double-check the sync.go diffs (files my template touched) in full to be 100% sure:Assistant
Confirmed: every diff is the
<REPO>normalization artifact (the repo dir is namedcli-printing-press, so the sed substitution over-matches the substring in URLs). This is environmental. Let me definitively prove it by running the golden verify on baseline and comparing the failure set:Assistant
Now let me rebuild my binary and run golden verify with my changes, then compare the failure sets:
Assistant
The failure set is IDENTICAL between baseline and my changes — definitively proving my changes produce byte-identical output for all normal golden specs. The "failures" are the environmental
<REPO>artifact present on baseline too.Now let me clean up temp files and verify what will be submitted:
Assistant
The
cli-printing-pressbinary is an untracked build artifact. Let me remove it sincesubmitusesgit diff(tracked changes only), but I'll keep the tree clean:Assistant
Now let me review the full diff to ensure correctness:
Assistant
The diff is clean and complete. Let me verify a couple of edge cases. First, check
GenerateMCPSurfacedoesn't mutate the spec before callingschemaWithDependentParents(which would invalidate the cache):Assistant
GenerateMCPSurfacecallsprepareOutput()(all spec mutations) beforeschemaWithDependentParents(), so caching is safe. Let me check the store test templates don't assume typed columns for all tables:Assistant
Let me look at the schema_version_test template around line 498-560 to check the table iteration gating:
Assistant
This test is gated on
hasBackfillColumnswhich is false for JSONOnly tables (only base columns, no backfill columns). Let me confirm base columns aren't backfill columns:Assistant
isStoreBackfillColumnreturns false for id/data/synced_at, so JSONOnly tables skip the upgrade test. Let me verify the upsert batch test template's table iteration gating once more:Assistant
The per-resource tests are gated on
hasTypedTable, so JSONOnly tables are skipped. Let me check whether any test callsschemaWithDependentParentsdirectly (which could be affected by caching):Assistant
No test calls
schemaWithDependentParentsdirectly. Let me run a final build and the schema_builder tests to confirm everything compiles cleanly after cleanup:Assistant
Everything compiles and tests pass. Let me recreate the reproduction test one final time to confirm the fix works end-to-end on the final state, then remove it:
Assistant
Let me remove the unused import:
Assistant
The reproduction test passes on the final state. Now let me clean up the temp test file and any build artifacts:
Assistant
The working tree is clean — only my 4 intended source files are modified. Let me do a final full diff review to confirm everything is correct:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.