offload-gain: savings math prices every re-send at full input — with prompt caching held for N turns it overstates ~5.6x - #1
Open
roy-tong wants to merge 1 commit into
Conversation
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.
Tested at commit
9b3aacc(main, 2026-09-09),scripts/offload-gain+ README "The money" section.What the report claims
would_haveprices the context the main model would have held as full input rate × amp turns:The README's worked example spells out the same arithmetic: Opus holds a 20K-token file for 10 turns →
$1.000, delegated to Sonnet costs$0.070, "that is the 93%".Why that overstates in the tool's own target environment
Claude Code (the host this hooks into) keeps the conversation prefix in the prompt cache: the first send is a cache write (1.25x input) and every re-send is a cache read (0.1x input — e.g. models.dev lists Opus 4.5/5 at $5 input / $0.50 cache read). So holding 20K tokens for 10 turns actually costs:
Net saving becomes 0.215 − 0.045 (worker) − 0.00225 (the 500-token answer re-read) ≈ $0.165, vs the reported $0.930 — about 5.6x overstated, and the headline "93% saved" is ~78%. The worker side is billed at full input rate (conservative), but it's an order of magnitude smaller than
would_have, so it doesn't offset this.The flat-rate model is the honest one only when consecutive turns are more than a cache TTL apart (5m), so the prefix really is re-bought every turn — worth saying, since that's when offloading helps most.
Reproduction (real script, synthetic ledger row matching
offload_ledger's schema inscripts/lib/common.sh):Suggested fix
Keep the flat figure (right when the cache expires between turns) and print the cache-aware one beside it. Patch (14 lines, verified against the repro above):
plus a
With prompt cachingline in the-vmoney block,usd_saved_cachedin--json, and a "Prompt caching" bullet in the README's "What the number does not include" (it currently lists follow-up verification, bytes/4 and media, but not this). With the patch the repro prints:Happy to turn this into a PR if the approach sounds right. The fixture I used is one synthetic ledger line — no external tooling needed to check it.