Repository navigation
Closed
Labels
area:sessionThe engine — turns, tasks, the toolbelt, checkpointsbugSomething the code does that it should notsev:seriousWrong or missing behaviour a person meets in ordinary use
Description
What happened
On app/v3 (a687c92), reopening or refreshing a chat with no model-call receipts books its spend a second time in the spending ledger (usage.jsonl). This covers the chat's own paid turns and any folded task spend. Reopening runs cellindex.Rebuild or cellindex.Refresh.
- The doubling is bounded. It happens once per row, on the first reopen that rebuilds the usage index. After that the count stays put.
- It still matters: the desktop app shows doubled spend for that chat, and the daily spending limit (
/budget day) can trip when real spend is only half the limit.
Each line below is one variant, showing the ledger row count before any reopen and then after each of five reopens (Rebuild, then four Refresh calls):
parent-paid=false/fold-marked=false 23 → 46 46 46 46 46
parent-paid=false/fold-marked=true 23 → 46 46 46 46 46
parent-paid=true/fold-marked=false 24 → 24 48 48 48 48
parent-paid=true/fold-marked=true 24 → 24 48 48 48 48
Replication
This is deterministic and needs no model or key.
- Copy
internal/cellindex/usage_folded_reopen_test.gofromdevinto a checkout ofapp/v3at a687c92. - Run:
go test -count=1 -v -run '^TestReopeningFoldedTaskSpendNeverRebillsWorkerCalls$' ./internal/cellindex/All four subtests fail, for example reopen rebilled worker calls: before=23 after=46.
Where
session.RecordUsagestamps every live row as modern (SharedID=true, with a generatedID). That is app/v3 A take no longer loses or double-counts cost #2332's rule.- A chat with no receipts falls back to its transcript's usage lines (
session.Digest.Usage). Those lines carry no row id. - So nothing in
cellindex.missingUsagecovers them. It matches lines by explicit id. For lines without one it uses an ordered prefix, butlegacyUsageRowscounts only!SharedIDrows. Every transcript line therefore reads as missing and is booked again throughRecordImportedUsage. - The re-booked rows stop the growth. They are written without
SharedID, so the next reopen counts them. - The folded-summary half:
foldUsageininternal/session/digest.goalso kept legacy unmarked cost-only fold summaries, which dev skips.
The fix
The fix is in #2561, which lands app/v3 on dev; its merge commit is 6ed333e.
foldUsageskips folded and legacy cost-only fold summaries, and keepsCallIDandRemoteEventon direct lines.- One identity rule,
session.UsageCallID, whichChargeIDdelegates to:- an explicit id first (
CallID,remote:+RemoteEvent, or the rowID); - otherwise the eight-field fingerprint (
At,Session,Model,Role,Calls,Input,Output,USD); - a line with neither is still counted against its session's uncovered rows.
- an explicit id first (
- For a chat with no receipts, the transcript lines are covered by the session's row count, as on dev. A chat with receipts keeps A take no longer loses or double-counts cost #2332's strict matching, so a row recorded for a different call never covers an imported call.
Acceptance
All of these are in internal/cellindex on land/app-v3:
TestReopeningFoldedTaskSpendNeverRebillsWorkerCallspasses in all four variants: the ledger row count is unchanged by a reopen.TestReopeningAReceiptlessChatManyTimesLeavesTheLedgerAlone: the ledger row count and the rows themselves are unchanged across five reopens.TestATakeImportsExactlyTheOtherCopysCallsandTestTwoCallsWithDifferentExplicitIdsAreBothBilledEvenWhenAlike: a take still imports exactly the other copy's calls.
Closes when #2561 merges.
Metadata
Metadata
Assignees
Labels
area:sessionThe engine — turns, tasks, the toolbelt, checkpointsbugSomething the code does that it should notsev:seriousWrong or missing behaviour a person meets in ordinary use
Activity
Land app/v3 on dev: one trunk (Agent-Field#2561)