Skip to content

app/v3: reopening a chat with no receipts books its spend a second time (once per row) #2585

Closed

Description

@AbirAbbas

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.

  1. Copy internal/cellindex/usage_folded_reopen_test.go from dev into a checkout of app/v3 at a687c92.
  2. 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.RecordUsage stamps every live row as modern (SharedID=true, with a generated ID). 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.missingUsage covers them. It matches lines by explicit id. For lines without one it uses an ordered prefix, but legacyUsageRows counts only !SharedID rows. Every transcript line therefore reads as missing and is booked again through RecordImportedUsage.
  • The re-booked rows stop the growth. They are written without SharedID, so the next reopen counts them.
  • The folded-summary half: foldUsage in internal/session/digest.go also 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.

  • foldUsage skips folded and legacy cost-only fold summaries, and keeps CallID and RemoteEvent on direct lines.
  • One identity rule, session.UsageCallID, which ChargeID delegates to:
    1. an explicit id first (CallID, remote:+RemoteEvent, or the row ID);
    2. otherwise the eight-field fingerprint (At, Session, Model, Role, Calls, Input, Output, USD);
    3. a line with neither is still counted against its session's uncovered rows.
  • 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:

  • TestReopeningFoldedTaskSpendNeverRebillsWorkerCalls passes 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.
  • TestATakeImportsExactlyTheOtherCopysCalls and TestTwoCallsWithDifferentExplicitIdsAreBothBilledEvenWhenAlike: a take still imports exactly the other copy's calls.

Closes when #2561 merges.

Activity

  1. added
    bug
    area:session
    sev:serious
    on Nov 10, 2026
  2. added a commit that references this issue on Nov 12, 2026
    ce47988
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:sessionbugsev:serious

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions