fix: drop the chats.model_id column default (model provenance, chat#1956)

Merged
SW
4mo ago
+31-0

Closes the database row of recoupable/chat#1956.

What

One migration: alter table public.chats alter column model_id drop default; plus a column comment stating the new semantics โ€” NULL means "not recorded"; a value present is a value some writer chose.

Why

The 'anthropic/claude-haiku-4.5' default fabricated model provenance: any writer omitting model_id produced a row indistinguishable from a deliberate model choice. Reproduced 2026-08-12 with four POST /api/chat/runs calls on four different explicit models โ€” all four chat rows read the default while usage_events billed the real models (evidence table in recoupable/chat#1956).

Merge sequencing โ€” DO NOT merge before recoupable/api#830

Hard dependency: api#830 makes every chats writer (headless + interactive) set model_id explicitly. Dropping the default first would leave interactive chats with NULL while the UI still expects a value. After api#830 is live, this default has zero remaining writers.

No backfill, deliberately

Historical fabricated rows can't be told apart from genuinely-defaulted interactive rows โ€” rewriting in either direction fabricates provenance the other way. Date-fence instead: rows before api#830's deploy are untrustworthy; usage_events remains the record for completed runs.

The read path is already NULL-safe (chat.model_id ?? DEFAULT_MODEL_ID, api/lib/chat/handleChatWorkflowStream.ts:93).

๐Ÿค– Generated with Claude Code


Summary by cubic

Drops the public.chats.model_id column default to stop fabricating model provenance. Previously the column defaulted to 'anthropic/claude-haiku-4.5' when omitted; now it has no default and NULL means "not recorded."

  • Merge only after recoupable/api#830 lands; otherwise interactive chats would write NULL while the UI still expects a value.
  • No backfill; treat rows created before api#830โ€™s deploy as untrustworthy for provenance and rely on usage_events for historical records.
  • No read-path changes required; existing code falls back when model_id is NULL.