🔍 Problem
Adding one Anthropic usage bucket to usage_samples touches 4+ positionally-coupled sites with no parity check:
- 🪦 A hand-written
(pct, resets_at) column pair in pkg/cache/schema.sql:40-79
- 🪦 A hand-written UPDATE line in
normalizeResetsAtSQL (pkg/cache/cache.go:84-95)
- 🪦 A positional
bucketArgs(u.X) append in RecordUsageSample (cache.go:253-297) that must stay in lockstep with the hand-written column order in insertUsageSampleSQL — 19 ? placeholders counted by eye
- 🪦 Optionally an entry in the
utilizationColumns allowlist (cache.go:422-425)
The bucket list is demonstrably still growing (tangelo, iguana_necktie, omelette_promotional are recent additions), and the args↔columns positional coupling is exactly the silent-transposition bug class that derivation eliminates. Nothing at compile time or test time checks that ordering matches.
🛠️ Suggested shape
Declare one ordered descriptor table:
var usageBucketCols = []struct {
name string
get func(anthro.Usage) *anthro.Bucket
}{ ... }
and derive insertUsageSampleSQL, normalizeResetsAtSQL, and the args slice from it at init. schema.sql stays hand-written, but add a parity test asserting the column set matches the descriptor table — that's what keeps the risk down. No schema bump required.
⚠️ Notes
- SQL generated at init needs the parity test against schema.sql to be trustworthy; without it this refactor trades one hazard for another.
🔍 Problem
Adding one Anthropic usage bucket to
usage_samplestouches 4+ positionally-coupled sites with no parity check:(pct, resets_at)column pair inpkg/cache/schema.sql:40-79normalizeResetsAtSQL(pkg/cache/cache.go:84-95)bucketArgs(u.X)append inRecordUsageSample(cache.go:253-297) that must stay in lockstep with the hand-written column order ininsertUsageSampleSQL— 19?placeholders counted by eyeutilizationColumnsallowlist (cache.go:422-425)The bucket list is demonstrably still growing (
tangelo,iguana_necktie,omelette_promotionalare recent additions), and the args↔columns positional coupling is exactly the silent-transposition bug class that derivation eliminates. Nothing at compile time or test time checks that ordering matches.🛠️ Suggested shape
Declare one ordered descriptor table:
and derive
insertUsageSampleSQL,normalizeResetsAtSQL, and the args slice from it at init.schema.sqlstays hand-written, but add a parity test asserting the column set matches the descriptor table — that's what keeps the risk down. No schema bump required.