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
I’ll first map the generator/store template code and existing tests, then reproduce the wide-resource behavior through the smallest available generator test path before implementing the threshold fallback.
- Assistant
The store is a single Go template driven by precomputed table metadata. I’ll inspect that metadata construction and every template branch keyed on typed columns, because the fallback must consistently suppress indexes, FTS, and typed upserts—not merely shorten
CREATE TABLE. - Assistant
hasTypedTablealready centrally gates typed DDL/upserts, so reducing a wide table to the three base columns is the cleanest way to reuse the established JSON-only path. I’ll now verify where dependent-parent columns are appended and where generation-time diagnostics are emitted, ensuring the 1500 count is applied only after all such columns exist. - Assistant
A subtle contract point is that fallback tables must still exist, while the current JSON-only tables are intentionally omitted as “dead.” Therefore, simply truncating columns would suppress DDL entirely. I’ll inspect complete migration/upsert sections and render data so I can introduce an explicit fallback marker, preserving the table while excluding all typed behaviors.
- Assistant
The fallback needs its own persistence dispatch: otherwise the required per-resource table would be created but never populated. I’ll locate all single-object and search/table consumers, then add a
JSONOnlytable state with a shared safe helper and generated dispatch cases for both batch and single-object writes, while keeping typed symbols absent. - Assistant
I’ll implement the cap as schema finalization with an explicit
JSONOnlymarker and original count. Wide tables will be reduced to exactly the base three columns, retain DDL, and be populated through the existing generic transaction helper; this naturally covers both batch and singleton sync without generating typed methods, indexes, or FTS. The finalization will run again after dependent-parent augmentation so column 1501 triggers fallback. - Assistant
The metadata layer is now explicit and clears all typed artifacts. Next I’ll wire template DDL and writes:
hasStoreTablewill retain fallback DDL, while generated JSON-only cases inupsertGenericResourceTxwill populate onlyid,data, andsynced_at. - Assistant
Before running the suite, I’ll create a temporary focused test (not committed) that synthesizes 3,001 scalar fields, renders a generated CLI, opens its SQLite store, performs a batch upsert, and inspects both schema and data. This directly reproduces the reported migration failure path and validates persistence plus absence of typed/FTS output.
- Assistant
One edge case surfaced in review: the framework
sync_statehas four columns but is explicitly excluded byhasTypedTable, so it is unaffected. I’ll now run the temporary wide generation/integration test and use SQLitePRAGMA table_infoto enforce the exact three-column contract and batch persistence. - Assistant
The first reproduction attempt was blocked by the shell’s unset Go module environment (
GOPATH/GOMODCACHE), before generation ran. I’ll rerun with explicit cache paths already available in the repository/container, then execute the generated integration test. - Assistant
Generation now reproduces the original 3,004-column candidate and emits the expected fallback diagnostic. I’ll complete the generated-code check by opening the DB and writing a batch item, then inspect generated source for forbidden typed indexes/FTS/upsert methods.
- Assistant
The generated store source is correct (one fallback table/case and no typed control symbols), but its fresh generated module lacks downloaded
go.sumentries. I’ll run the normal generated-projectgo mod tidy, then retry the SQLite integration. - Assistant
The full failure path is fixed: the generated DB opens,
controlhas exactly three columns, and batch sync persists its JSON row. I’ll now run schema and generator tests (including normal narrow typed-table tests) to detect regressions, then inspect the final diff for any accidental files. - Assistant
The generator suite reached broad generation coverage; failures were unrelated environment/toolchain gates (
HOMEunset and a newly reported Go 1.26.4 standard-library vulnerability requiring 1.26.5), not code assertions. I’ll remove cache artifacts, run focused schema/store tests with a validHOME, and verify normal narrow generated code still contains typed columns/upserts. - Assistant
All focused schema, migration, batch dispatch, subresource, FTS, and dead-table tests pass, confirming ordinary typed behavior is unchanged. The test harness created an untracked
.localdirectory; I’ll remove it, run formatting/diff checks andgo veton the affected package, then review the exact final patch. - Assistant
Final verification and checklist:
- Reported error reproduced: yes. A synthetic 3,001-field response produced a 3,004-column candidate, matching the SQLite-cap failure class.
- Fix confirmed: yes. Generated migration opened successfully;
PRAGMA table_info("control")returned exactly 3 columns, andUpsertBatchpersisted JSON into the fallback table. - Edge cases considered: yes. The cap is
>1500, includes base columns and the dependent-parent augmentation pass, clears indexes/FTS/typed upserts, preserves low-gravity dead-table behavior, and safely quotes generated fallback SQL identifiers. - Affected tests run: yes. Focused schema/store generator tests and
go vet ./internal/generatorpass. The broad suite’s only failures were pre-existing environment/toolchain gates: unsetHOMEand GO-2026-5856 in Go 1.26.4 (fixed upstream in 1.26.5). Re-running affected focused tests withHOMEconfigured passed. - Repository cleanliness: only the three intended source/template files are modified; temporary tests and cache artifacts were removed.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.