fix(warp): bump the parse version so cached databases take the share rule

An unchanged Warp database kept serving calls split by the old re-spread,
because nothing invalidated its cache entry. exchange-share-v1 re-parses it
once; the version is pinned in a test. Also pins that a conversation whose
exchanges are no longer finished clears its cached calls: keepCachedWarpShares
returns the empty set before reading any call, since every cached key is then
missing from the current set.
This commit is contained in:
Resham Joshi 2026-11-06 06:28:25 -08:00
parent 32f0eee2a2
commit 5714aa3d22
2 changed files with 25 additions and 1 deletions

View file

@ -642,7 +642,10 @@ export const PROVIDER_PARSE_VERSIONS: Record<string, string> = {
// to land.
// billed-cost-v1: total_billed_cost_in_cents prices conversations that carry
// no provider cost or charged usage.
warp: 'worktree-project-grouping-v1-est-cost-billing-cost-v1-billed-cost-v1',
// exchange-share-v1: cached exchanges keep their share of a conversation's
// cost and only new spend goes to new exchanges (parser.ts
// keepCachedWarpShares); unchanged databases re-parse once onto that rule.
warp: 'worktree-project-grouping-v1-est-cost-billing-cost-v1-billed-cost-v1-exchange-share-v1',
// cache-read-v1-est-cost: gen_metadata and RPC usage now carry cache-read
// tokens, fields 9/10 read as thinking/response (they were swapped), and
// placeholder-only models are priced and flagged costIsEstimated.

View file

@ -288,3 +288,24 @@ itUnlessNoSqlite('allocates two conversations in one database independently', as
expect(costs.get('warp:B:B1')).toBeCloseTo(7.5, 10)
expect(costs.get('warp:B:B2')).toBeCloseTo(0, 10)
})
it('bumps the warp parse version for the per-exchange share rule', async () => {
const { PROVIDER_PARSE_VERSIONS } = await import('../src/session-cache.js')
expect(PROVIDER_PARSE_VERSIONS['warp']).toContain('exchange-share-v1')
})
itUnlessNoSqlite('clears a conversation whose exchanges are no longer finished', async () => {
writeWarpDb('2026-08-16 10:00:00.000000')
const { clearSessionCache, parseAllSessions } = await import('../src/parser.js')
const calls = async () => {
clearSessionCache()
return (await parseAllSessions(undefined, 'warp')).reduce((sum, p) => sum + p.totalApiCalls, 0)
}
expect(await calls()).toBe(3)
const { DatabaseSync } = requireForTest('node:sqlite')
const db = new DatabaseSync(DB_PATH)
db.prepare(`UPDATE ai_queries SET output_status = '"InProgress"' WHERE conversation_id = 'conv-credits'`).run()
db.close()
expect(await calls()).toBe(2)
})