Repository navigation
fix(cost): replay a session's journal unless its split covers its whole history - #735
Merged
Merged
Conversation
…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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(cost): replay a session's journal unless its split covers its whole history
#732 replayed a session's journal only when its
session_infocarried no splitat 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 replayunless that mark is present, rather than unless the split is absent:
replay again;
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-astrawhile thatmodel 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
inputof 3.0next to a journal that prices to 101) is replayed and marked complete;
ignoring the mark fails it with the stale 3.0.
replay to something else.
cargo fmt -p future-agent --check,cargo clippy -p future-agent --all-targets -- -D warnings,cargo test -p future-agent(1795 passed).