Task 13 — Version-write logic
Depends on: 12
Unblocks: 14
Goal
Glue task 12's parsed output into the database with the version-timeline
semantics. This is the only task that writes to model_pricing and
model_pricing_versions.
Scope
In src/lib/pricing-sync.ts:
export async function runPricingSync(opts: {
syncModel?: string,
}): Promise<{ status: SyncStatus; updated: number; rejected: number }>
Body:
req = await buildSyncRequest().
parsed = await callSyncLlm(req, pickSyncModel(...)).
- Per-row sanity gate — if any row fails sanity, set
status = 'rejected' and skip writes.
- In one transaction:
- Insert
pricing_sync_log row with status = 'pending' (or write at end
with the final status — implementer's call).
- For each accepted row:
- Look up current
model_pricing_versions.* WHERE effective_to IS NULL.
- If
priceChanged() is false: skip (no version row).
- Else:
UPDATE versions SET effective_to = ?detectedAt WHERE id = old.id,
INSERT versions (effective_from = ?detectedAt, effective_to = NULL, sync_log_id = ?logId, ...).
UPSERT model_pricing with the new row.
- Update
meta.last_pricing_sync_ts.
- Finalize
pricing_sync_log row.
Status values:
'ok': at least one update, zero rejections, no sanity failures
'partial': some rejections OR partial coverage of knownModels
'rejected': sanity gate triggered, no DB writes
'failed': fetch / LLM / validator error
Definition of Done
Task 13 — Version-write logic
Depends on: 12
Unblocks: 14
Goal
Glue task 12's parsed output into the database with the version-timeline
semantics. This is the only task that writes to
model_pricingandmodel_pricing_versions.Scope
In
src/lib/pricing-sync.ts:Body:
req = await buildSyncRequest().parsed = await callSyncLlm(req, pickSyncModel(...)).status = 'rejected'and skip writes.pricing_sync_logrow withstatus = 'pending'(or write at endwith the final status — implementer's call).
model_pricing_versions.* WHERE effective_to IS NULL.priceChanged()is false: skip (no version row).UPDATE versions SET effective_to = ?detectedAt WHERE id = old.id,INSERT versions (effective_from = ?detectedAt, effective_to = NULL, sync_log_id = ?logId, ...).UPSERT model_pricingwith the new row.meta.last_pricing_sync_ts.pricing_sync_logrow.Status values:
'ok': at least one update, zero rejections, no sanity failures'partial': some rejections OR partial coverage ofknownModels'rejected': sanity gate triggered, no DB writes'failed': fetch / LLM / validator errorDefinition of Done
effective_toand inserts one new version.
'rejected'and zero DB mutations.no-op.
docs/tasks/13-version-write-logic.mddocs/design/