Repository navigation
fix(plugin): insights shows savings with the right sign - #583
Merged
Merged
Conversation
In the /api/stats waterfall a saving is a negative delta_usd. levers() negated compaction only. A keep-alive that saved $120 and cost $60 showed as -$180 instead of +$60, and the rows did not add up to total_saved. cachesplit_saved and decl_filter_saved had the same defect; self_removed too, but it is outside total_saved and is now left out of the rows. Same change in the Codex copy of cg.py. Test fixtures now use the real sign. New tests: the rows add up to total_saved; a keep-alive that costs more than it saves stays negative. Fixes #582 Assisted-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: DAVID AMID <DAVIDA@il.ibm.com>
Collaborator
Author
|
Decision on the open question (from the repo owner): the |
amiddavid
commented
Oct 15, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
Review, round 1
Verdict: approve.
What I checked
- Signs. I read
waterfall()indash/overview.go. Savings are-X(compaction,cachesplit_saved,keepalive_saved,decl_filter_saved,self_removed). Costs are+X(cg_llm,keepalive_ping). The newlevers()matches every key. - Net loss. No
abs()is left. A keep-alive that costs more than it saves, or a cachesplit with a negative value, still shows as negative. - Fixtures. The changed fixtures now match the real shape. The live
/api/statsof the local proxy (read-only) haskeepalive_saved-127.69,keepalive_ping+65.46,compaction-90.03,cg_llm+6.24. - Sum. The live rows give 90.03 + (127.69 - 65.46) - 6.24 = 146.03. This equals
total_saved. - Other readers. I grepped every key in the plugin and in Codex.
cg.levers()is the only reader of the waterfall.tv.py:185callscg.levers(), so it is fixed too.statusline.py,insights.pyand the skills do not read the waterfall. No other reader has the defect. - Copies. The two
cg.pyfiles are byte-identical.
Tests
go test ./context-guru-plugin -run 'Insights|Levers|CG'on box 1: pass.- Full
go test ./context-guru-pluginon box 1: pass (313 s). test_tv.pyrun direct (pytest is not installed here): 36 tests, OK.- My own mutations, one at a time, each caught:
cachesplit_savedsign flipped: sum test fails.decl_filter_savedsign flipped: sum test and goldens fail.- keep-alive ping sign flipped: both new tests and goldens fail.
cg_llmsign flipped: sum test and goldens fail.keepalive_savedsign flipped: both new tests and goldens fail.
self_removed
- The old row showed the waterfall value as is. That value is
-SelfRemovedUSD, so it showed negative. The row was wrong, and it broke the sum. cg.pyshows no other place for this number.total_reducedis not shown either.- Removing the row is correct for the "Saved" table. I suggest a follow-up, not a change here: a separate line below the table, such as "You removed this yourself, not counted above: $X". It must stay outside the sum.
Non-blocking
test_tv.pystill hasself_removedat 0, so no test checks thatlevers()ignores a non-zeroself_removed.TestInsightsLeversAddUpToTotalSavedcovers it on the Go side.
amiddavid
commented
Oct 15, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
Review, round 1 (update)
- Withdrawn: my follow-up idea of a separate
self_removedline. The row stays removed, as decided. Nothing blocks on it. - Checked: no other insights output adds
self_removedto a context-guru saving.cg.levers()andtv.pydo not read the key. Ininsights.pyit is a separate finding ("self-removed-credit", severity ok). It is used for ranking only and is never added to a saved total. - Verdict: approve.
This was referenced Oct 15, 2026
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.
Summary
/context-guru:insightsnow shows the right sign for every saving. Keep-alive pings show +$60 where they showed -$180.What changed
In
/api/stats, a saving is a negativedelta_usdand a cost is positive (dash/overview.go,waterfall()).levers()read each key like this:levers()beforecompactioncachesplit_savedkeepalive_savedkeepalive_pingabs()decl_filter_savedcg_llm-abs()-valueself_removedtotal_savedabs(): a keep-alive that costs more than it saves still shows as a loss.self_removedis the account's own doing. The waterfall keeps it out oftotal_saved(it is intotal_reduced). With it in the rows, they could not add up to the headline. Open question: do you want it back as a separate line, labelled as not ours?codex-marketplace/plugins/context-guru/scripts/cg.py. The two files stay byte-identical.stats_*.json,test_tv.py) had positive savings. They now use the real sign. Goldens did not change.How it was tested
cg_test.go:TestInsightsLeversAddUpToTotalSaved: every key non-zero, rows sum tototal_saved.TestInsightsKeepAliveLossStaysNegative: saved 10, spent 40 shows -30.keepalive_savedsign reverted (the old code): 4 tests fail, both new tests among them.cachesplit_savedsign reverted: the sum test fails.decl_filter_savedsign reverted: the sum test and the goldens fail.abs()on the keep-alive: both new tests fail.self_removedrow restored: the sum test fails.go test ./context-guru-pluginpasses on box 1 (318 s).total_saved. Keep-alive shows +$62.34 =keepalive_net_usd.Fixes #582
🤖 Generated with Claude Code