Repository navigation
feat(insights): tool usage analytics per provider (#1133) - #1164
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (25)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Closes #1133 Adds a `tool_usage` insight that rolls up canonical action_events into per-(provider, tool, action_kind) entries with call counts, conversation counts, distinct tool ids, and affected-path / output-text density. The same envelope carries a per-provider coverage map that distinguishes "data unavailable" (provider exposes no tool events at all) from "zero observed" so coverage gaps never collapse into silent zeros. Surface: - `polylogue insights tool-usage` (CLI, with `--tool`, `--mcp-server`, `--action-kind` filters; root-level `--provider` inherited) - MCP `tool_usage` tool on the standard `{items, total}` envelope - `Polylogue.list_tool_usage_insights(query)` async facade method and its sync counterpart - Operation `query-tool-usage` and artifact `tool_usage_results` registered in the runtime catalog / artifact graph MCP tool names of the form `mcp__<server>__<tool>` have their server segment extracted as a first-class `mcp_server` field, so analytics can distinguish GitHub vs Polylogue vs Context7 MCP fanout without ad-hoc prefix parsing in callers. The aggregator (`build_tool_usage_insight`) is a pure function over the two typed substrate rows so filters, coverage, and MCP-server derivation are testable without standing up a database. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5c353e390a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
5c353e3 to
367b559
Compare
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Adds a
tool_usageinsight that rolls up canonicalaction_eventsinto per-(provider, tool, action_kind)entries with call counts, conversation counts, distinct tool ids, and affected-path / output-text density. The same envelope carries a per-provider coverage map that distinguishes "data unavailable" (provider exposes no tool events at all) from "zero observed" so coverage gaps never collapse into silent zeros.Closes #1133.
Problem
Per #1133 (parent #994 / W11 of #827), Polylogue had no per-tool, per-session, per-provider analytics over the canonical action-event substrate even though that substrate already carries normalized tool names, action kinds, tool ids, affected paths, and output text. Consumers wanting "which tools fire most from claude-code?" or "does my Codex session use
apply_patchmore thanshell?" had to roll their own SQL overaction_events.The harder requirement was honesty about coverage. ChatGPT exports do not surface tool calls; aggregating a "zero" for ChatGPT next to "8,000" for Claude Code without flagging the difference would lie to readers. The issue called this out explicitly: the envelope must distinguish "data unavailable" from "zero observed".
Solution
Substrate-first, per the architecture rule (
docs/architecture.md):polylogue/storage/sqlite/queries/tool_usage.py— two typedTypedDictquery results:get_tool_usage_rows()groups by(provider, normalized_tool_name, action_kind)overaction_events, summing call/conversation/message/tool-id/path/output-text counts.get_tool_usage_provider_coverage_rows()left-joinsconversationsagainstaction_eventsso every provider with at least one conversation is in the result — providers with zero events surface asaction_event_count=0.Insight model (
polylogue/insights/tool_usage.py):ToolUsageInsightis a single envelope returned bylist_tool_usage_insights. It carriesentries,provider_coverage, totals, andhas_coverage_gaps.ToolUsageCoverageEntry.data_availableis the load-bearing flag:Trueiff the provider has any action-event rows.extract_mcp_server()parsesmcp__<server>__<tool>and stores the server segment as a first-class field on each entry. Non-MCP tools getNone— the catalog stays honest.build_tool_usage_insight()is a pure function so filters, sorting, MCP-server derivation, and coverage flags are unit-testable without standing up a database. Query filters narrowentries;provider_coveragestays exhaustive so a narrowed query never hides gaps.Surfaces (all auto-wired via the registry-driven insight machinery, no per-surface boilerplate):
polylogue insights tool-usagewith--tool,--mcp-server,--action-kindfilters. Root-level--provideris inherited.tool_usagetool registered automatically byserver_insight_tools.register_insight_toolsiteratingINSIGHT_REGISTRY. Wire schema regenerated intests/data/witnesses/mcp-tool-schemas.json.Polylogue.list_tool_usage_insights(query)+ syncSyncPolyloguecounterpart.polylogue.operations.list_tool_usage_insights(*, services, db_path, query)for ad-hoc callers.query-tool-usage+ artifacttool_usage_results+ pathtool-usage-query-loopregistered in the runtime catalog and artifact graph; scenario coverage map pointslist_tool_usage_insights→query-tool-usage.Rejected alternatives:
tool_usagetable behind a rebuild was rejected becauseaction_eventsis already the canonical materialized substrate and the per-provider rollup is small enough to compute on read. Same shape asprovider_analytics. TheTOOL_USAGE_INSIGHT_VERSIONfield on the envelope still gives consumers a hook to invalidate caches if the aggregation contract changes.readiness_exempt=Truein the registry and gates onaction_eventsindirectly through the coverage map it returns.Verification
Full suite (
devtools verify --all) shows 9 pre-existing failures on master (message_type_backfilltopology cells,test_check.pyrepair fixtures, terminal snapshots, scenario-coverage maintenance-target list) — unchanged on this branch; not introduced by #1133.Test plan
data_available=False.mcp__<server>__<tool>prefixes (andNonefor non-MCP tools and malformed prefixes).replace_action_events.insight_kind,materializer_version,provenance,entries,provider_coverage).