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 trace the generator’s store templates and tests first, identify where resource column metadata drives migrations/upserts/indexes/FTS, then reproduce the wide-resource behavior with the existing test infrastructure before implementing a single dispatch decision at the 1500-column cap.
- Assistant
The store template already gates all typed artifacts on the same
.HasUpsertresource flag, which is promising: if wide resources are transformed to a JSON-only table model with no typed upsert/FTS metadata, batch dispatch should naturally omit them. I’ll inspect the table model construction and exact template guards to ensure the fallback still emits its own three-column table rather than disappearing entirely. - Assistant
hasTypedTableis currently inferred fromlen(Columns)>3; therefore a fallback represented by exactly the base columns automatically suppresses typed upserts and batch dispatch. However, table creation itself is also currently guarded byhasTypedTable, so simply truncating metadata would remove the per-resource table and violate the contract. I’ll separate “emit resource table” from “emit typed machinery,” add an explicit fallback marker for clarity/logging, and determine where generation-time diagnostics are conventionally written. - Assistant
The cap must apply to the final generated column count—not raw leaves—because duplicate/non-scalar fields do not become SQLite columns, and subresources add a dependent-parent foreign-key column. I’ll inspect subresource assembly and generation data flow, then implement the check after each table’s full column set is assembled. The threshold semantics will preserve exactly 1500 columns and fallback only when the final count exceeds 1500.
- Assistant
A key edge case is now clear: capping only in
BuildSchemais insufficient when a 1500-column table later receivesparent_id, and capping before parent injection could accidentally re-addparent_idto an already-fallback table. I’ll add explicitJSONOnly/pre-fallback count metadata, enforce once during base schema construction and again after dependent augmentation, skip augmentation for prior fallbacks, log exactly once from the generation path, and change only DDL emission to include marked JSON-only tables. All typed/index/FTS/upsert guards remain unchanged. - Assistant
The other template loops are already driven by FTS, backfill columns, or
hasTypedTable, so cleared fallback metadata suppresses them. I’m applying the focused source/template changes now, then I’ll use a temporary synthetic Go test (removed afterward) to generate 3000 fields and exercise the generated store’s SQLite migration, since repository tests must not be added or modified. - Assistant
Reviewing the acceptance wording reveals one more requirement beyond migration success: batch generation must “dispatch wide resources to the JSON-only path.” The current generic
resourcesinsert alone would leave the retained per-resource fallback table empty. I’ll add a non-typed JSON-only upsert helper and include fallback cases in batch dispatch/savepoint handling, while still generating no resource-specific typed helper, typed columns, indexes, or FTS. - Assistant
Singleton sync uses a separate single-object dispatch, so I’ll cover both routes with one generic
UpsertJSONOnlyAPI plus an internal transaction helper. Table names are generator-produced but will still be validated against the existing identifier regex before interpolation. Resource-specific typed function names remain absent, allowing hidden checks to distinguish this from typed emission. - Assistant
The focused tests could not start because the environment has both
GOMODCACHEandGOPATHunset, not because of a code failure. I’ll rerun with a temporary GOPATH/module cache, then create an ephemeral in-package test to access the unexported generation helpers and verify exact cap boundaries, generated source suppression/dispatch, and an actual SQLiteOpenon the generated 3000-field CLI. - Assistant
A second environment variable is also absent (
GOCACHE, with noHOMEfallback). I’ll provide both temporary cache locations and continue; these do not alter repository files. - Assistant
Focused existing tests pass. For the required reproduction, I’ll model the wide response with 3000 scalar fields, run the normal generator against it, assert the emitted DDL has only
id/data/synced_at, no wide typed helper/index/FTS, and both batch/singleton JSON dispatches, then compile and run a tiny generated-store program that opens an empty SQLite database and confirms the fallback table has three columns. The temporary test file will be deleted immediately afterward. - Assistant
The repository provides
minimalSpecand generated-module command helpers, so the ephemeral test can stay concise and exercise the real path. I’ll inspect that fixture’s resource setup to modify it correctly rather than constructing unrelated required metadata by hand. - Assistant
I’ll now run the ephemeral reproduction. It will also verify the negative boundary directly in memory: 1497 unique response fields plus the three base columns remains a typed 1500-column table, while one additional field triggers fallback.
- Assistant
The reproduction reached generation and emitted the expected fallback log, but my temporary fixture enabled only the Store vision, so
sync.gowas correctly not generated and the singleton assertion could not run. This is a fixture setup issue, not a product failure. I’ll rerun with Sync enabled; the temporary file was already removed cleanly. - Assistant
The real reproduction now passes: the generated migration opens an empty SQLite DB, creates exactly three fallback columns, and batch sync inserts into the fallback table; the 1500-column boundary remains typed. To preserve ordinary generated output as closely as possible, I’ll conditionally emit the generic JSON-only helper only when at least one fallback exists, rather than adding dead helper code to every normal CLI. Then I’ll run the full generator package and repository test suites.
- Assistant
The full generator suite ran broadly but failed in an unrelated validation test because the installed Go 1.26.4 standard library is flagged by
govulncheck(GO-2026-5856, fixed in Go 1.26.5). Tests before that point—including many generated-project builds—ran, and there is no indication of a template regression. I’ll rerun the focused store/schema tests after the conditional change, run all non-generator repository packages, and inspect the final diff/status for accidental files. - Assistant
The focused generator tests pass. The non-generator command’s package-list substitution ran before the temporary environment assignment, so
go listitself lacked GOPATH and produced an invalid empty package list. I’ll rerun it inside a child shell with the cache variables exported for both listing and testing. - Assistant
The non-generator suite passed except one unrelated filesystem/error-injection pipeline test (
TestLiveCheck_BinaryRefreshReasonIncludesSourceWalkError); all other listed packages passed. Before final verification, I noticed the fallback helper’s identifier validation would reject a legitimate generated resource beginning with a digit, even though the DDL safely quotes such names. I’ll replace rejection with proper double-quote escaping, preserving support for every resource name the existing SQL-name helper supports, then rerun the wide generated-store reproduction and final checks. - Assistant
The final wide reproduction passes after identifier escaping: generation logs the 3003-column fallback, generated store compilation succeeds, empty-DB migration creates three columns, and batch insertion populates the per-resource table. I’ll now run formatting/static checks and inspect the complete patch for scope, temporary artifacts, and test-file modifications before submission.
- Assistant
The final patch is clean, limited to four generator/template files, and no tests or temporary files remain. One internal comment still claimed
hasTypedTablecontrolled table creation, which is no longer true for explicit JSON-only fallbacks; I’ll correct that documentation, then submit. Checklist assessment:- Reproduced: yes, with a synthetic 3000-field resource representing a 3003-column projection.
- Fix confirmed: yes, generated empty-DB migration succeeded with three columns, and batch storage populated the fallback table.
- Edge cases: exact 1500 boundary remains typed; dependent-parent columns are counted; prior fallbacks cannot regain parent columns; generated SQL identifiers are safely escaped.
- Tests: focused generator tests and
go vetpass; broad suites were run, with only unrelated environment/baseline failures (Go stdlib vulnerability and one pipeline filesystem test).
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.