Skip to content

Comments

Add 5 new client metrics event types: ToolCall, McpInvocation, NewMessage, SkillUsed, SubagentEvent#572

Open
svarlamov wants to merge 2 commits intomainfrom
devin/1771642821-add-client-metrics-events
Open

Add 5 new client metrics event types: ToolCall, McpInvocation, NewMessage, SkillUsed, SubagentEvent#572
svarlamov wants to merge 2 commits intomainfrom
devin/1771642821-add-client-metrics-events

Conversation

@svarlamov
Copy link
Member

@svarlamov svarlamov commented Feb 21, 2026

Add 5 new client metrics event types for agent telemetry

Summary

Adds client-side support for 5 new metrics event types: ToolCall (5), McpInvocation (6), NewMessage (7), SkillUsed (8), and SubagentEvent (9). These are emitted from the checkpoint command based on hook context passed through a new HookMetadata struct on AgentRunResult.

Key changes:

  • metrics/types.rs / metrics/events.rs: New MetricEventId variants and corresponding value structs (ToolCallValues, McpInvocationValues, NewMessageValues, SkillUsedValues, SubagentEventValues) with full PosEncoded/EventValues trait implementations.
  • checkpoint.rs: Event emission logic keyed on hook_event_name strings. Also moves build_checkpoint_attrs outside the !entries.is_empty() guard so hook-only events (no file changes) can still emit metrics. AgentUsage pings now fire on message hooks too (gated by should_emit_agent_usage).
  • agent_presets.rs: New HookMetadata { hook_event_name, tool_name } struct. Claude preset extracts subagent_id/subagent_model into agent_metadata. Cursor preset extracts MCP server/tool names on beforeMCPExecution.
  • Agent hook installers updated: Claude Code (+UserPromptSubmit, Stop, SubagentStart, SubagentStop), Cursor (+beforeMCPExecution), Gemini (+BeforeModel, AfterModel, BeforeMCPExecution, AfterMCPExecution).
  • parse_mcp_tool_name helper parses mcp__server__tool convention.
  • Unit tests for all new event structs (builder, sparse, roundtrip). Integration tests via TmpRepo verify checkpoint execution doesn't panic with various hook metadata.

Note: Server-side work (ClickHouse migrations, metrics_parser, worker-metrics) is not included in this PR. Events will buffer client-side but be rejected server-side until that lands.

Review & Testing Checklist for Human

  • Verify build_checkpoint_attrs move is safe. Previously only called when !entries.is_empty(). Now runs unconditionally so hook-only events can use attrs. Check if this causes issues when repo state is unusual (e.g., detached HEAD, no commits).
  • Check for duplicate MCP events. MCP invocations can fire from both PostToolUse (if tool name has mcp__ prefix) AND explicit beforeMCPExecution hooks. If both trigger for the same call, you'll get two McpInvocationValues events. Confirm this is acceptable or needs deduplication.
  • Confirm should_emit_agent_usage gating is intentional. Function currently always returns false, so AgentUsage pings on messages won't fire until rate-limiting is enabled. Is this expected?
  • Review hook event name string matching. Logic uses hardcoded strings like "UserPromptSubmit", "PostToolUse", "beforeMCPExecution". Handles multiple casing variants but may miss some. Verify coverage for all agents.
  • Test end-to-end with real agent hooks. Integration tests are shallow (just verify no panic). Manually trigger hooks from Claude Code/Cursor/Gemini and verify events appear in observability log (~/.git-ai/internal/logs/{PID}.log) and metrics DB.

Notes

  • Link to Devin run: https://app.devin.ai/sessions/ed389a486416455b9dc36faf30f7c6c3
  • Requested by: @svarlamov
  • All 1092 existing tests pass + 13 new integration tests added
  • parse_mcp_tool_name only handles mcp__server__tool format (2 underscores). Extra segments would be misparsed.
  • Cursor test fix: Changed .get(*hook_name).unwrap() to .and_then(...).unwrap_or_default() to gracefully handle missing hook keys (changes production behavior from panic to silent empty).

Open with Devin

…sage, SkillUsed, SubagentEvent

- Add MetricEventId variants (5-9) and event value structs with PosEncoded/EventValues traits
- Add HookMetadata struct to AgentRunResult for tracking hook context
- Emit new metrics events in checkpoint command based on hook_event_name
- Add AgentUsage pings on message hooks (UserPromptSubmit, Stop, BeforeModel, etc.)
- Update Claude Code hooks: UserPromptSubmit, Stop, SubagentStart, SubagentStop
- Update Cursor hooks: beforeMCPExecution support
- Update Gemini hooks: BeforeModel, AfterModel, BeforeMCPExecution, AfterMCPExecution
- Extract subagent_id/subagent_model from Claude hook data into agent_metadata
- Extract MCP server/tool names from Cursor beforeMCPExecution hook data
- Add parse_mcp_tool_name helper for mcp__server__tool pattern
- Add integration tests for all new event types via TmpRepo harness
- Add unit tests for all new event value structs (builder, sparse, roundtrip)

Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@git-ai-cloud-dev
Copy link

No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits.

Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 6 additional findings.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants