Repository navigation
fix(dash): count every call, so a called tool is never "unused" - #733
Conversation
A tool's call count and its last-used time disagreed: the server row showed calls: 0 while last_used showed the call. lastUsedOf reads every session in scope; Calls counted a call only in a session that also declared the tool. A call made where the tool had no declaration row (deferred, or a session that began before the proxy) therefore set last_used and left calls at 0. Calls 0 files a tool as never used, so the report could suggest removing a tool the user had called. - buildToolReport: Calls is the total over every session in scope, the same set lastUsedOf reads. SessionsUsed and the unused figures stay per session: a session that carried a tool without calling it still paid for it. - The skills summary, the server rollup's ToolsUsed and the toolfilter suggestion use the verdict's own test of "invoked" (SessionsUsed > 0 || Calls > 0). A called tool is never suggested. /api/adapt/tools already counted every call and is unchanged. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Vitaly Zabershinsky <[email protected]>
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (claude, user of @vz-ibm) | Claude Code 2.1.310 | offload-review skill, @vz-ibm's session | fresh | 2 of 2 | 1 of 2 | 5387d77b5e6e |
blocking |
Verdict: blocking
The Go change is correct. Calls now agrees with last_used, and nothing is double counted. But the dashboard UI and one Go counter still use the old test of "used" (sessions_used only). So the dashboard still tells the user to remove a tool they called. That is the defect this PR says it fixes.
Findings
-
dash/ui/tools.js:2312-2314 (and 574-576) — the Tools tab still lists a called tool as removable, with a command to paste
- What fails: take the PR's own case.
context7tool is declared only in s2 and called only in s1. After this PR the row hascalls: 2,sessions_used: 0,sessions_declared: 1, andunused_reads > 0(the s2 carry).removableRowskeeps it because!t.sessions_usedis true. The row then goes intogroupRemovable→renderInvTopandctaBlock, so the user gets a "remove this" card and a paste-ableclaude mcp remove/ settings snippet.renderUnused(line 575) uses the same filter. - Proof:
removableRowsfilter is!t.sessions_used && t.sessions_declared > 0 && !t.builtin && t.kind !== 'server_tool'. It never readst.calls.renderInventory(line 2286) passes these rows to the top cards and toctaBlock(line 2295). - Fix: use the same test as the Go side:
!t.sessions_used && !t.calls && ...in both filters. Also lines 1254/1258 and 1376/1383 mark the rowcg-row-unusedand show the "never" pill next to a non-zero Calls cell. Use the same test there, or show the call count.
- What fails: take the PR's own case.
-
dash/ui/app.js:1825 — the Overview "remove" list still recommends a called skill
- What fails: the PR's skill case (
datavizdeclared in s2, called in s1). The skill row hassessions_used: 0andunused_usd > 0from the s2 carry. The Overview filtert.sessions_used === 0 && t.unused_usd > 0keeps it, so the Overview card says to remove a skill the user ran. The server line above it (line 1823) is now right, because it readstools_used, which this PR fixed. - Proof: line 1825 reads only
sessions_usedandunused_usd. Neither changes in this PR, by design (the commit keeps them per session). - Fix: add
&& !t.callsto the skills filter.
- What fails: the PR's skill case (
-
dash/toolsuggest.go:442 —
Withheldstill counts a called item as "never used"- What fails: a called tool with
SessionsUsed == 0now failssuggest(correct). Theelse if st.SessionsUsed == 0 && st.Tokens > 0branch then adds it toWithheld. The field's own doc (line 386) says it counts "never-used items" that did not reach the bar. So the toolfilter doc tells the reader that more never-used items exist than do. - Proof:
suggestat line 527 now rejects onst.Calls > 0. Line 442 does not have the same clause. - Fix:
else if st.SessionsUsed == 0 && st.Calls == 0 && st.Tokens > 0. Add one assertion onWithheldtoTestSuggestNeverOffersACalledTool, or a test throughToolFilterDocFor.
- What fails: a called tool with
Non-blocking
dash/insightsshape.go:428—verdictForfor an item invoked only through calls now says "invoked in 0 sessions — it earns the weight it carries". This path existed before (the|| r.Calls > 0was already there), but this PR makes it common. Quote the call count whenSessionsUsed == 0, asinsights.py:1301does.dash/toolapi_calls_test.go:47-51—TestCallsInADeclaringSessionAreNotDoubleCountedpasses when the tool is missing fromrep.Tools. Assert that the row was found, as the first test does.- No test covers the UI filters. There are no JS tests in
dash/ui, so a Go-side test cannot catch findings 1 and 2. Consider one Playwright or unit check, or state in the PR that the UI is unverified. - The PR text says "a called tool is never suggested". That is true for
/api/toolfiltersuggestions only. Findings 1 and 2 are other routes to the same advice.
What I checked
- Read the full diff (3 files, +111/-3) and the commit message and PR body.
buildToolReport(dash/toolapi.go:787-1073):allCallssumsusedInover every session, the sameusesset thatlastUsedOfreads. The per-declarationst.Calls += calls(line 881) is now overwritten, so no double count.SessionsUsed,UnusedReads,UnusedUSD,unusedTokand the per-session rows still use the per-session test, which matches the stated design.statsholds only declared items, so the override never creates a row for an undeclared tool. TheKindTool/KindMCPTool/KindSkillkeys fromusedBySessionmatch thestatKeyof each declaration.- Skills summary (line 1012) and
serverRollup(line 1143): the new test matchesinsightsshape.go:283/298.Skills.Callsonly adds calls of an invoked skill, and every skill with calls is now invoked, so the total is consistent. suggest(dash/toolsuggest.go:527): the new clause is correct. The test sets the window abovesuggestMinSessions/suggestMinSpan, so it fails only onCalls.- Every other reader of
sessions_used/tools_used:dash/ui/tools.js,dash/ui/app.js,context-guru-plugin/scripts/insights.py(already usescalls or sessions_used, fine),dash/insightsshape.go. carriedCoststill keys onusedBySessionper session (line 546). That is consistent with the per-session unused figures.- Fail open and reversibility: not touched. This is a read-side report change only. Data dependence: no change, as the PR says.
- I did not run Go or the UI. Live tests are not approved.
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @vz-ibm) | Claude Code 2.1.310 | offload-review skill, @vz-ibm's session | fresh | 1 of 2 | 1 of 2 | 5387d77b5e6e |
blocking |
Verdict: blocking
The Go fix in buildToolReport is correct. But it creates a new state: SessionsUsed == 0 && Calls > 0. Before this PR, that state could not occur, because Calls grew only together with SessionsUsed (old toolapi.go:879-881). The PR updates 3 consumers. Other consumers still test only sessions_used, so they still call a called tool "never used".
Findings
-
dash/ui/tools.js:575, dash/ui/tools.js:2314, dash/ui/app.js:1825 — the dashboard still lists a called tool or skill as removable
- What fails: use the PR's own test input.
mcp__context7__resolve-library-idis declared only in s2 and called 2 times only in s1./api/toolsnow returnscalls: 2, sessions_used: 0, sessions_declared: 1, unused_usd > 0.renderUnused(tools.js:574-576) keeps rows with!t.sessions_used && t.sessions_declared > 0. The tool shows in "Every removable group, with its evidence".removableRows(tools.js:2312-2315) has the same filter. It feedsrenderInvTopandgroupRemovable(tools.js:2286-2288), so the Overview ranks the tool for removal.- app.js:1825 keeps skills with
sessions_used === 0 && unused_usd > 0. The s2 carry givesunused_usd > 0, so a called skill is a top-5 "Recommendation" to remove. - The tool and skill tables (tools.js:1254-1259, 1376-1384, 1636-1637) mark the row
cg-row-unusedand print a "never" pill next tocalls: 2.
- Proof: the PR title is "a called tool is never 'unused'". The server panel at app.js:1823 now works, because
tools_usedmoved. The per-row filters did not move, so the same tool is "used" in the server row and "removable" in the tool row. - Fix: use the same test as Go in each filter, for example
!t.sessions_used && !t.calls. Make the "never" pill and thecg-row-unusedclass follow it too.
- What fails: use the PR's own test input.
-
dash/toolsuggest.go:442 —
Withheldcounts a called tool as a "never-used item below the bar"- What fails:
suggestnow refuses a tool withCalls > 0(toolsuggest.go:527). Then theelse if st.SessionsUsed == 0 && st.Tokens > 0branch runs and doesout.Withheld++. The field doc (toolsuggest.go:386) says Withheld counts "never-used items" that did not reach the bar. The plugin prints it assuggest_withheld(insights.py:772). So the report says "N items are not used yet, wait for more evidence", and N includes tools the user called. - Proof: same input as finding 1.
suggestreturns false on thest.Calls > 0clause.st.SessionsUsed == 0andst.Tokens == 9, soWithheldbecomes 1. Before this PR,Callswas 0 for this tool, so it was a real never-used item. Now it is not. - Fix:
else if st.SessionsUsed == 0 && st.Calls == 0 && st.Tokens > 0. Add a test with the PR's input that assertsWithheld == 0.
- What fails:
-
dash/insightsshape.go:428 and context-guru-plugin/scripts/insights.py:1301 — the verdict text says "invoked in 0 sessions"
- What fails: for the new state,
verdictForreturns"invoked in 0 sessions — it earns the weight it carries". The plugin returns"invoked: 2 call(s) in 0 session(s), ...". Both are wrong evidence. This report claims that everywhytraces to a measurement. - Proof:
invokedis true fromr.Calls > 0(insightsshape.go:298).plural(r.SessionsUsed, "session")withSessionsUsed == 0gives "0 sessions" (insightsshape.go:443-448). This text was unreachable before this PR. - Fix: when
SessionsUsed == 0, quote the calls, for example "called N times in sessions that did not declare it". Add one case to the insights shape test.
- What fails: for the new state,
Non-blocking
- dash/toolapi.go:881 —
st.Calls += callsis now dead. The loop at 925-928 overwritesCallsfor every stat. Remove it, or say in a comment that the later loop ownsCalls. - dash/toolapi.go:916-924 —
allCallsreads every session inusedIn. The declaration loop skips sessions with nosessionsentry (line 806-808). Both come from the same scope today, so this is only a note. - dash/toolapi_calls_test.go:47-51 —
TestCallsInADeclaringSessionAreNotDoubleCountedpasses if the tool is missing fromrep.Tools. Assert that the row was found, as the first test does. ServerStat.SessionsUsedis the maximum oft.SessionsUsed(toolapi.go:1152-1154). It can now be 0 while the server'scallsis above 0. The plugin prints both facts (insights.py:890-891). Not wrong, but a reader can be confused.
What I checked
- The full diff (3 files) and the commit message of 5387d77. The PR body.
buildToolReportin full,usedBySession,lastUsedOf,scopedUses,serverRollup,suggestand theWithheldloop inToolFilterDocFor.- That
allCallskeys match the stat keys:usedBySessionwritesKindTool,KindMCPToolorKindServerTool, andKindSkillkeys. Each stat has one kind, so no double count. - That
SessionsUsed,UnusedReads,UnusedUSDand the totals stay per session. They do. - Every consumer of
sessions_used/SessionsUsedandcallsindash/*.go,dash/ui/*.jsandcontext-guru-plugin/scripts/insights.py. - The 5 new tests. I read them only. Live tests are not approved, so I did not run Go.
- Data dependence: the PR reads the same rows and stores nothing new. No update to docs/data-dependence.md is needed.
Review round 1 on #733 (both reviewers): the Go side counted every call, but the dashboard kept its own rule, `!t.sessions_used`. A tool called in a session that did not declare it has sessions_used 0 and calls > 0, so the UI still listed it as removable: a remove card with a command to paste, a "never" pill, the unused row style, and an Overview top-5 entry. - app.js: neverCalled(t), the server's own test (no sessions_used and no calls). Every unused filter, row class and pill in app.js and tools.js now uses it. TestTheDashboardUsesOneNeverCalledRule reads the source and fails if any of them tests sessions_used alone. - ToolFilterDoc.Withheld no longer counts a called tool as a never-used item below the bar. - The verdict text no longer says "invoked in 0 sessions" (Go) or "2 call(s) in 0 session(s)" (plugin): for a tool called only where it was not declared it quotes the calls. - Removed the now-dead `st.Calls += calls`; the later loop owns Calls. - The double-count control test now fails if its row is missing. Live: on main the Overview told the user to remove context7 and dataviz, which they had called; with this branch it lists only playwright. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Vitaly Zabershinsky <[email protected]>
Reply to review round 1Both reviewers blocked, with the same main finding. All fixed in a3f5525. Finding: the dashboard still lists a called tool or skill as removable (both reviewers)Correct. I fixed the Go side and missed that the UI repeats the rule in JavaScript, as Fixed with one rule.
Test: Live check. I ran a proxy built from
Finding:
|
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (claude, user of @vz-ibm) | Claude Code 2.1.310 | offload-review skill, @vz-ibm's session | resumed | 2 of 2 | 2 of 2 | a3f55251ee85 |
approve |
Verdict: approve
Commit a3f5525 fixes all round-1 findings from both reviewers. The dashboard, the toolfilter doc and both verdict texts now use one test of "never used": SessionsUsed == 0 && Calls == 0. I found no new defect.
Findings
None.
Earlier findings
- Reviewer 2, finding 1 (tools.js removable lists, row class, "never" pill): fixed.
renderUnused(575),removableRows(2314), bothcg-row-unusedclasses (1254, 1376) and all 3 pills (1258, 1383, 1636) now callneverCalled(t).grepfinds no othersessions_usedtest indash/ui/*.js. The remaining reads only print the number (1260, 1384, 1637) or are the column list (72). - Reviewer 2, finding 2 (app.js Overview skills): fixed. Line 1829 uses
neverCalled(t) && t.unused_usd > 0. - Reviewer 2, finding 3 / reviewer 1, finding 2 (
Withheld): fixed. toolsuggest.go:442 now also needsst.Calls == 0.TestWithheldDoesNotCountACalledToolgoes throughToolFilterDocForwith the PR's own input, and assertsWithheld == 0. - Reviewer 1, finding 1: same as my findings 1 and 2. Fixed, as above.
- Reviewer 1, finding 3 (verdict "invoked in 0 sessions"): fixed.
verdictForhas a new first case,invoked && r.SessionsUsed == 0, that quotesplural(r.Calls, "time"). It sits before the generalinvokedcase, so it wins. The plugin_verdicthas the same split. Each has a test that checks the text has "2 call"/"2 times" and does not have "0 session". - Non-blocking, dead
st.Calls += calls: removed. The comment says the later loop ownsCalls. TheSessionsUsed++/continuelogic is unchanged. - Non-blocking, control test passes with a missing row: fixed with
foundandt.Fatalf. - Non-blocking,
allCallsscope andServerStat.SessionsUsed(reviewer 1): the author did not change them. Both reasons are correct.usesanddeclscome from the same scope query. Both server facts are true. - Non-blocking, no UI test (mine): partly closed.
TestTheDashboardUsesOneNeverCalledRulechecks the source. The author also reports a live check ofmainagainst the branch. I accept that.
Non-blocking
dash/uicalls_test.go:25: the regex catches!t.sessions_used,t.sessions_used === 0andt.sessions_used ?. It does not catch other forms, such ast.sessions_used > 0or a different variable name (r.sessions_used). That is enough for today's code. A future edit can get past it.neverCalledis a top-level function in app.js, and tools.js calls it. That is correct: both files are classicdeferscripts (index.html:1041, 1044), app.js loads first, and tools.js already calls other app.js helpers such asnum()the same way.
What I checked
- Last review: round 1, 5387d77, 2026-10-26T10:17:24Z
- New commits read: 1 (a3f5525 fix(dash,plugin): use one "never used" rule everywhere, UI included)
- Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review:
- Reviewer 1 round-1 review (10:17:25Z): I read it and checked each finding against the new commit (see "Earlier findings").
- Author reply (vz-ibm, 10:29:44Z): I checked each claim against the diff. All match. I accept the two "no change" reasons. I did not repeat the live check, because live tests are not approved.
- Read the full diff 5387d77..a3f5525 (9 files, +135/-20), and the code around each change:
buildToolReport,ToolFilterDocFor,verdictFor,_verdict, and the UI functions that changed. - Checked every
sessions_used/tools_usedreader indash/ui/*.jswith grep.insights.jsandhistory.jshave none. - Checked that the new test helpers exist:
stripComments,readUI,mkEvent,day,invWriter{db, seen}(other tests already build it this way),requireTool,scriptsDir. TestWithheldDoesNotCountACalledTool: s2 declares the tool and s1 only calls it, soSessionsUsed == 0andCalls == 2. The window has 1 session, sosuggestreturns false. Without the fix,Withheldis 1. The author reports that the test first failed with exactly that.- Fail open and reversibility: not touched. This is a read-side report change and UI only. Data dependence: no change.
- I did not run Go, Python or the UI. Live tests are not approved.
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @vz-ibm) | Claude Code 2.1.310 | offload-review skill, @vz-ibm's session | resumed | 1 of 2 | 2 of 2 | a3f55251ee85 |
approve |
Verdict: approve
Commit a3f5525 fixes every blocking finding from both reviewers in round 1. All code that decides "never used" now uses one rule: SessionsUsed == 0 && Calls == 0. This includes the dashboard UI. I found no new defects.
Findings
None.
Status of round-1 findings
- Reviewer 1, finding 1 / reviewer 2, findings 1 and 2 (the UI lists a called tool or skill as removable): fixed.
neverCalled(t)(app.js:61) is!t.sessions_used && !t.calls.- All 8 places now use it:
renderUnused(tools.js:575),removableRows(tools.js:2314), the Overview skills filter (app.js:1829), the 2cg-row-unusedclasses (tools.js:1254, 1376) and the 3 "never" pills (tools.js:1258, 1383, 1636). app.jsloads beforetools.js(index.html:1041, 1044). Both are classic scripts, sotools.jscan callneverCalledas a global.grep sessions_used dash/ui/*.jsfinds only the helper, the column list (tools.js:72) and 3num(t.sessions_used)display calls. None of these decides "unused".
- Reviewer 1, finding 2 / reviewer 2, finding 3 (
Withheldcounts a called tool): fixed at toolsuggest.go:442.TestWithheldDoesNotCountACalledTooluses the real store path (invWriter.write→ToolFilterDocFor).- s1 has
Tools = 1, so ther.tools > 0filter inscopedUseskeeps its use row. The tool reachesrep.ToolswithCalls = 2andSessionsUsed = 0. The old code would giveWithheld = 1, so the test can fail.
- Reviewer 1, finding 3 (verdict says "invoked in 0 sessions"): fixed.
- Go: a new
case invoked && r.SessionsUsed == 0at insightsshape.go:426 comes beforecase invoked. Its only invoked caller is insightsshape.go:330. - Plugin: insights.py:1301-1304 has the same change.
- Both have tests. The tests check for "2 call" / "2 times" and check that "0 session" is absent.
- Go: a new
- Non-blocking notes:
- Dead
st.Calls += calls(reviewer 1): removed. A comment now says the later loop setsCalls. - The control test passed when its row was missing (both reviewers): fixed with
foundandt.Fatalf. allCallsscope (reviewer 1): the author did not change it. The reason is correct. Both lists come from the same scope query.ServerStat.SessionsUsed(reviewer 1): the author did not change it. The reason is correct. Both facts are true.- No UI test (reviewer 2): partly closed by the source-scan test. The author checked the browser live and says so in the reply.
- Dead
Non-blocking
TestTheDashboardUsesOneNeverCalledRule(uicalls_test.go:26) finds only 3 text patterns. A new form such ast.sessions_used == 0or!rep.x.sessions_usedwould not be caught. This is acceptable as a guard against regressions.stripCommentsremoves a line only when it starts with a comment. A trailing// ... !t.sessions_usedcomment on a code line can make the test fail when no code is wrong. It does not occur today.
What I checked
- Last review: round 1, 5387d77, 2026-10-26T10:17:25Z
- New commits read: 1. a3f5525, "fix(dash,plugin): use one "never used" rule everywhere, UI included" (9 files, +135/-20).
- Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files).
- New items since my last review:
- Reviewer 2's round-1 review (10:17:24Z). I compared it with mine. Its findings 1-3 are the same as my findings 1-2. I checked each one against the new commit, as listed above.
- The author's reply comment (10:29:44Z). I checked every claim in it against the diff and the code. The "Live check" and "Checks" sections report runs that I cannot repeat (live tests are not approved). I accept them as the author's report.
- The full diff 5387d77..a3f5525, with the code around each change:
buildToolReport,ToolFilterDocFor,verdictForand its callers,_verdictand_stale_days,invWriter.write,scopedUses, and thereadUI/stripComments/requireTool/scriptsDirtest helpers. - Every other reader of
sessions_used/SessionsUsedin Go, JS and Python. No other code decides "unused" fromsessions_usedalone. - Fail open and data dependence: not touched. This is read-side reporting only, and nothing new is stored.
- I did not run Go, Python or the UI. Live tests are not approved.
Summary
A tool's call count and its last-used time disagreed in
/api/tools. A server row could showcalls: 0while its tool showed a last-used time.calls: 0is what files a tool as never used, so the report could suggest removing a tool the user had called. This PR makes the call count include every call in scope, as last-used already does.What we found
lastUsedOfreads every session in scope.buildToolReportadded a call toCallsonly in a session that also declared the tool (usedIn[dr.session][k]).last_usedand leftcallsat 0. That happens when the tool was deferred and not yet recorded (see fix(dash): record deferred MCP tools in the tool inventory #728), or when the session began before the proxy.Found while testing #728: after calling
mcp__context7__resolve-library-id, the context7 server row readcalls: 0while last-used showed the call.What changed
buildToolReport:Callsis the total over every session in scope, the same setlastUsedOfreads.SessionsUsedand the unused figures stay per session. A session that carried a tool without calling it still paid for it, so its cost is unchanged.SessionsUsed > 0 || Calls > 0, whichinsightsshape.goalready uses:suggest(toolfilter suggestions): a called tool is never suggested for removal. Before, it could be.serverRollup:ToolsUsedcounts a called tool.InvokedandCallscount a called skill./api/adapt/toolsalready counted every call (usedTool[u.name]over all uses) and is unchanged.How it was tested
Five new tests in
dash/toolapi_calls_test.go. Each failed first for the intended reason:TestCallsCountEveryCallInScope: wascalls=0 last_used=20. It also checks thatSessionsUsedstays 0, and that the unused carry of the declaring session stays.TestCallsInADeclaringSessionAreNotDoubleCounted: the control. It passed before and after.TestSkillsSummaryCountsACallWithoutADeclaringSession: wasinvoked=0 calls=0.TestServerRollupCountsACalledTool: wasToolsUsed: 0.TestSuggestNeverOffersACalledTool: it suggested removing a tool that was called.Suites:
go build ./...andmake lint: clean.go test ./dash/... ./proxy/...: all pass exceptTestCalculatorPricesFromTheRowsModelNotABlend, which also fails on cleanmainon this machine. No existing test changed its result.Data dependence
This PR changes only how stored rows are counted on read. It stores nothing new.
What it does at each level (see docs/data-dependence.md):
tool_usesandtool_declarationsrows.Open questions
Tools = 0, andscopedUseskeeps only sessions withr.tools > 0. So a skill used only before install keepscalls == 0. The plugin warns ("used Nd ago - check first") but still lists it.TestAnImportedInvocationStopsTheRemovalAdvice, which names this behaviour, skips every time, so it never asserts it. A follow-up can count imported uses too.dash/toolapi.go(toolReportFor,deferredNames). This PR edits onlybuildToolReport,serverRollupandsuggest. I expect no conflict.Assisted-By: Claude (Anthropic AI) [email protected]