fix(insights): count mixed tool usage across sessions - #9896
Closed
MonkeyLeeT wants to merge 1 commit into
Closed
MonkeyLeeT wants to merge 1 commit into
MonkeyLeeT wants to merge 1 commit into
Conversation
MonkeyLeeT
force-pushed
the
codex/issue-9814-insights-undercount
branch
13 times, most recently
from
April 21, 2026 21:25
d1a86bc to
f73b5fa
Compare
MonkeyLeeT
force-pushed
the
codex/issue-9814-insights-undercount
branch
14 times, most recently
from
April 26, 2026 06:16
3d6345b to
1e7b089
Compare
MonkeyLeeT
force-pushed
the
codex/issue-9814-insights-undercount
branch
6 times, most recently
from
April 27, 2026 22:36
717252f to
430558c
Compare
MonkeyLeeT
force-pushed
the
codex/issue-9814-insights-undercount
branch
from
April 28, 2026 16:44
430558c to
a3cb4e3
Compare
3 tasks
teknium1
pushed a commit
that referenced
this pull request
Sep 12, 2026
…urces `_get_tool_usage()` merged `tool_name` rows and assistant `tool_calls` JSON with a GLOBAL per-tool max. That is right inside one session (both columns describe the same call) but wrong across sessions: a gateway session recording `tool_name` only plus a CLI session recording `tool_calls` only for the same tool reported 1 use instead of 2. Group both queries by (session_id, tool_name), reconcile with max per session, then sum across sessions. Port of PR #9896 by @MonkeyLeeT onto the `_scoped` query layout; one invariant test covering disjoint sessions AND a paired session. Fixes #9814
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.
What does this PR do?
Fixes insights tool-usage undercounting when one session records tools via
tool_namerows and another records them only via assistanttool_calls. The merge now happens per(session_id, tool_name)so mixed datasets add across sessions without double-counting duplicate representations inside a single session.Related Issue
Fixes #9814
Type of Change
Changes Made
agent/insights.py: aggregate tool usage by(session_id, tool_name)before collapsing to repo-wide totals.tests/agent/test_insights.py: add regression coverage for onetool_name-only session plus onetool_calls-only session for the same tool.How to Test
uv run --extra dev python -m pytest tests/agent/test_insights.py -q.toolrow containingtool_name="search_files".tool_callsforsearch_filesand confirm insights reports a count of2.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
uv run --extra dev python -m pytest tests/agent/test_insights.py -q→55 passeduv run --extra dev python -m pytest tests/ -qis not green in this environment because of unrelated existing failures and missing optional dependencies such asacp,fastapi, andfaster_whisper