Skip to content

fix(cost): replay a session's journal unless its split covers its whole history - #735

Merged
huichen merged 1 commit into
mainfrom
fix/cost-split-partial
Sep 20, 2026
Merged

huichen merged 1 commit into
mainfrom
fix/cost-split-partial

Conversation

@huichen

@huichen huichen commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

fix(cost): replay a session's journal unless its split covers its whole history

#732 replayed a session's journal only when its session_info carried no split
at all. But the first build that accumulated a split (#729) started accumulating
wherever a session already was, so sessions that existed then got a split that
covers only the tail of their history — and a split that exists is exactly what
suppressed the replay.

A live example: a session showing ¥8.4141 when it was upgraded now reports rows
summing to ¥0.908176 against a ¥9.3223 total — and 9.322278 − 8.414102 is that
same ¥8.4141, i.e. the rows cover only what was spent after the upgrade.

Mark a split as covering the whole history (cost_split_complete) and replay
unless that mark is present, rather than unless the split is absent:

  • the replay path writes the mark together with the split it cached;
  • the run-end and manual-compaction writes carry it forward, so a load does not
    replay again;
  • a session built in this process starts from zero counters, so its split covers
    its whole history by construction and it carries the mark from its first write.

Against the local session database this turns every session into a replay (no
stored mark exists yet — the previous build never wrote one) and the session
above goes from ¥0.9082 to ¥9.6968 of rows for its ¥9.3223 total.

Still not matching, and why

Ten of those sixty sessions remain off by more than 50%, in the other direction:
their total is the undercount. They ran on azure/gpt-6-astra while that
model had no prices configured, so every one of those requests was charged at an
estimate of zero and the session's accumulated total never included them.
Replaying their journal now prices the same requests at today's rates for that
model (70 / 350 / 7 / 90 per 1M), which is the first time those requests have
been priced at all. That gap is not something this change can close: the total is
what was accumulated at the time, and re-deriving it would rewrite history rather
than report it. Worth a separate decision.

Tests

  • A session whose stored split covers only its tail (a partial input of 3.0
    next to a journal that prices to 101) is replayed and marked complete;
    ignoring the mark fails it with the stale 3.0.
  • A session whose split is marked complete keeps it, even when its journal would
    replay to something else.
  • A session with no split at all still replays (regression guard for fix(cost): price a legacy session's spend from its journal, not its totals #732).

cargo fmt -p future-agent --check, cargo clippy -p future-agent --all-targets -- -D warnings, cargo test -p future-agent (1795 passed).

…le history

#732 replayed a session's journal only when its `session_info` carried no split
at all. But the first build that accumulated a split (#729) started accumulating
wherever a session already was, so sessions that existed then got a split that
covers only the tail of their history — and a split that exists is exactly what
suppressed the replay.

A live example: a session showing ¥8.4141 when it was upgraded now reports rows
summing to ¥0.908176 against a ¥9.3223 total — and 9.322278 − 8.414102 is that
same ¥8.4141, i.e. the rows cover only what was spent after the upgrade.

Mark a split as covering the whole history (`cost_split_complete`) and replay
unless that mark is present, rather than unless the split is absent:

- the replay path writes the mark together with the split it cached;
- the run-end and manual-compaction writes carry it forward, so a load does not
  replay again;
- a session built in this process starts from zero counters, so its split covers
  its whole history by construction and it carries the mark from its first write.

Against the local session database this turns every session into a replay (no
stored mark exists yet — the previous build never wrote one) and the session
above goes from ¥0.9082 to ¥9.6968 of rows for its ¥9.3223 total.

## Still not matching, and why

Ten of those sixty sessions remain off by more than 50%, in the other direction:
their **total** is the undercount. They ran on `azure/gpt-6-astra` while that
model had no prices configured, so every one of those requests was charged at an
estimate of zero and the session's accumulated total never included them.
Replaying their journal now prices the same requests at today's rates for that
model (70 / 350 / 7 / 90 per 1M), which is the first time those requests have
been priced at all. That gap is not something this change can close: the total is
what was accumulated at the time, and re-deriving it would rewrite history rather
than report it. Worth a separate decision.

## Tests

- A session whose stored split covers only its tail (a partial `input` of 3.0
  next to a journal that prices to 101) is replayed and marked complete;
  ignoring the mark fails it with the stale 3.0.
- A session whose split is marked complete keeps it, even when its journal would
  replay to something else.
- A session with no split at all still replays (regression guard for #732).

`cargo fmt -p future-agent --check`, `cargo clippy -p future-agent --all-targets -- -D warnings`, `cargo test -p future-agent` (1795 passed).
@huichen
huichen enabled auto-merge (squash) September 20, 2026 02:36
@huichen
huichen merged commit be4e613 into main Sep 20, 2026
12 checks passed
@huichen
huichen deleted the fix/cost-split-partial branch September 20, 2026 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant