feat(telemetry): normalize agent tag into structured agent/version/role fields#896
feat(telemetry): normalize agent tag into structured agent/version/role fields#896
Conversation
|
Codecov Results 📊✅ 6461 passed | Total: 6461 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
All tests are passing successfully. ❌ Patch coverage is 63.75%. Project has 13258 uncovered lines. Files with missing lines (2)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 75.98% 75.95% -0.03%
==========================================
Files 295 295 —
Lines 55045 55120 +75
Branches 0 0 —
==========================================
+ Hits 41819 41862 +43
- Misses 13226 13258 +32
- Partials 0 0 —Generated by Codecov Action |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c848aba. Configure here.
| expect(result.version).toBe(version); | ||
| }), | ||
| { numRuns: DEFAULT_NUM_RUNS } | ||
| ); |
There was a problem hiding this comment.
Property tests flake when arbitrary generates garbage names
Medium Severity
The agentNameArb arbitrary can generate strings that match GARBAGE_NAME_RE (e.g., "no", "on", "off", "yes", "true", "false") since they are 2–5 lowercase letters satisfying the filter. When such a name appears in the compound property tests, normalizeAgent short-circuits to { name: "unknown" } without extracting version or role, causing the unconditional expect(result.version).toBe(version) and expect(result.role).toBe(role) assertions to fail. These tests will flake in CI whenever fast-check happens to generate a garbage name.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit c848aba. Configure here.
c848aba to
24cd11f
Compare
…le fields Raw AI_AGENT and AGENT env var values like 'claude-code/2.1.123/agent' or '1' were passed through to the Sentry 'agent' tag without normalization. This caused fragmented data — 'claude', 'claude-code', and 'claude-code/2.1.123/agent' all appeared as separate tag values. Add normalizeAgent() that parses compound slash-separated values, resolves aliases (claude-code → claude), and detects garbage values (1, true, yes → 'unknown'). Change detectAgent() and detectAgentFromProcessTree() to return structured AgentInfo with name, version, and role fields. Telemetry now sets three tags: agent, agent.version, agent.role.
24cd11f to
5620fc7
Compare
## Summary - Excludes boolean-ish garbage names (`no`, `on`, `off`, `yes`, `true`, `false`, `0`, `1`) from `agentNameArb` in `detect-agent.property.test.ts` ## Problem Follow-up to #896. The `agentNameArb` arbitrary could randomly generate short strings like `"no"` or `"on"` that match `FALSY_GARBAGE_RE` / `TRUTHY_GARBAGE_RE`. When these appeared in compound property tests (e.g. `"no/1.2.3/agent"`), `normalizeAgent` would short-circuit without extracting version/role, causing the unconditional `expect(result!.version).toBe(version)` assertion to fail. Caught by [Cursor BugBot](#896 (comment)).


Summary
normalizeAgent()to parse compound slash-separated agent values (e.g.claude-code/2.1.123/agent), resolve aliases (claude-code→claude), and handle boolean-ish garbage valuesdetectAgent()anddetectAgentFromProcessTree()to return structuredAgentInfo { name, version?, role? }instead of raw stringsagent(canonical family name),agent.version,agent.roleMotivation
The
agentSentry tag was receiving raw, unvalidated values fromAI_AGENTandAGENTenv vars. This caused fragmented tag data —claude,claude-code, andclaude-code/2.1.123/agentall appeared as separate tag values.Boolean-ish garbage handling
Boolean-ish values are split into two classes:
1,true,yes,on{ name: "unknown" }0,false,no,offundefined(no agent)For
AI_AGENT, falsy values fall through to the next detection level (e.g.AI_AGENT=false+CLAUDE_CODE=1→claude). ForAGENT(lowest priority), falsy values result in no detection, which then falls through to process tree detection ininitSentry.Example transformations
agenttagagent.versionagent.roleclaude-code/2.1.123/agentclaude2.1.123agentclaude-codeclaudeclaudeclaude1unknownfalsecoworkcoworkTest plan
detectAgentanddetectAgentFromProcessTreetest assertions forAgentInforeturn typenormalizeAgent(): compound values, alias resolution, truthy garbage →unknown, falsy garbage →undefinedCLAUDE_CODE_IS_COWORKalone →undefined,AI_AGENT=falsefalls through to next levelAGENT_ALIASESstructural testsdetect-agent.property.test.ts) for 11 invariants: lowercase, non-empty, truthy garbage →unknown, falsy garbage →undefined, version format, idempotency, alias resolution, compound extraction