Repository navigation
Feat: Fold an agent's versions into one row wherever figures are keyed by agent - #1202
Conversation
…d by agent Every release of an agent was its own row: claude-code/2.1.284 and 2.1.285 split one agent's spend across two lines in the AGENTS pane and `abctl cost --by agent`. The key is now pipeline.AgentName of the label, which drops the version of a label that is exactly one name/version token and leaves any other User-Agent as sent. Applied where the key is built and matched, not only where it is drawn: the usage ring and a session's agent (usage.AgentLabel), the ledger on read (labelFor; rows on disk keep the version, so existing rows fold too), and /v1/usage?agent=, which reads a versioned label as its agent. The sessions pane's AGENT column narrows to fit a name. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Hai Huang <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 20 minutes. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (17)
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 |
pdettori
left a comment
There was a problem hiding this comment.
Reviewed the version-fold across every surface that keys by agent.
Verified the two sources stay in agreement: the ring keys through usage.AgentLabel → pipeline.AgentName, the ledger on read through labelFor → pipeline.AgentName (which FilterAgent and SeriesCurrenciesIn also delegate to), and session agent naming stores usage.AgentLabel — so no path was missed, and TestLedgerAndRingAgreeOnAVersionedAgent pins the ring/ledger key agreement. The agent= param is folded after the length check, so both a plain and a versioned value match folded keys over ring and ledger windows, and the writer keeping full labels means existing rows fold with no migration.
Nice touch on the versionedAgent regex: only folding a whole-label name/version token avoids naming rows after half of a User-Agent comment, and the test table covers the tricky forms (a/b/c, claude-code/, the Claude-User comment, multi-token SDK UAs).
Two comment-wrapping nits inline; nothing blocking.
Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (core + abctl), tests, docs
Agent/IDE config (.claude/.vscode): none
Commits: 1, signed-off
CI status: all passing
| // The label is pipeline.EventClient.Label — "claude-code/2.1.270", or the raw User-Agent for | ||
| // an agent the parser did not recognise. CLIENT-ASSERTED AND SPOOFABLE, like every other use | ||
| // The label is pipeline.AgentName of pipeline.EventClient.Label — "claude-code", every release | ||
| // together — or the raw User-Agent for an agent the parser did not recognise. CLIENT-ASSERTED AND SPOOFABLE, like every other use |
There was a problem hiding this comment.
nit: this line runs ~200 chars; the surrounding comments are wrapped to the usual width. Worth re-wrapping for consistency.
| // GroupAgent breaks totals down by the coding agent that made the request, as | ||
| // "name/version" — the axis #952 asks for, since "what did today cost" is only | ||
| // GroupAgent breaks totals down by the coding agent that made the request, by | ||
| // name with its version dropped (pipeline.AgentName) — the axis #952 asks for, since "what did today cost" is only |
There was a problem hiding this comment.
nit: same — the new GroupAgent doc lines exceed the file's usual wrap width.
Summary
Every release of an agent was its own row. On a laptop running Claude Code across an update, the AGENTS pane showed:
Now it shows one
claude-coderow and onebob-shellrow. The same applies toabctl cost --by agentand each session'sagent.The rule
pipeline.AgentName(label)drops the version when the whole label is a singlename/versiontoken (^([^\s/]+)/[^\s/]+$). Anything else is returned unchanged. An unrecognised agent's label is its raw User-Agent, and cuttingClaude-User (claude-code/2.1.284; …)at the first slash would name a row after half a comment. A single-token unrecognised agent does fold (curl/8.4.0becomescurl), which follows from the same rule.Where it applies
It has to run on the server, where the agent key is built and matched, not only in abctl's table. Otherwise choosing the
claude-coderow would sendagent=claude-codeto a server that matches labels exactly and gets nothing back. The SESSIONS column compares against each session'sagentin the same way. And every version would still count separately against the 16-series limit on a response.agent: throughusage.AgentLabel.labelFor, which coversgroup=agent,FilterAgentandSeriesCurrenciesIn. The writer still stores the fullname/version, so no history is lost and today's existing rows fold straight away./v1/usage?agent=: the value is folded after the length check. A versioned label, which is whatgroup=agentreturned until now, matches every release of that agent, and the response names the agent ("agent": "claude-code").Other changes
abctl cost --agent, theagent=row indocs/pricing.md, and the godoc on the agent axis now describe the key without a version.What does not change
abctl cost --agent claude-code/2.1.285. It scopes on the client, so it now fails with the usual "no agent … seen: bob-shell, claude-code" instead of showing zeros.Tests
New tests:
TestAgentName: a recognised agent, a bare name,unknown, the Claude-User comment form, a browser User-Agent, a multi-token User-Agent,a/b/c, and empty or half-empty labels.TestSnapshot_GroupAgentFoldsAnAgentsVersionsIntoOneSeries: the ring.TestFold_GroupAgentFoldsAnAgentsVersions: ledgerFoldandFilterAgent.TestLedgerAndRingAgreeOnAVersionedAgent: the two sources produce the same key for the same client.TestHandleUsage_AgentCoversEveryVersion:agent=claude-codeandagent=claude-code/2.1.284over bothtodayand1h.Existing tests that asserted versioned keys were updated to expect plain names.
TestSnapshot_GroupAgentBoundsCardinalitygenerated its distinct agents with a/in the name; they now fold together, so it uses-to keep them distinct.go vetpasses forcore,cmd/abctlandcmd/authbridge-{proxy,envoy,praxis}.go testpasses forcoreandcmd/abctl, andgo mod tidy -diffis clean for both.Assisted-By: Claude (Anthropic AI) [email protected]