Skip to content

Feat: Fold an agent's versions into one row wherever figures are keyed by agent - #1202

Merged
huang195 merged 1 commit into
rossoctl:mainfrom
huang195:feat/agent-fold-versions
Sep 30, 2026
Merged

huang195 merged 1 commit into
rossoctl:mainfrom
huang195:feat/agent-fold-versions

Conversation

@huang195

Copy link
Copy Markdown
Member

Summary

Every release of an agent was its own row. On a laptop running Claude Code across an update, the AGENTS pane showed:

 AGENT                  SESSIONS  REQUESTS  TOKENS  COST
 claude-code/2.1.285    2         6,251     802M    $540.85
 claude-code/2.1.284    2         5,033     775M    $480.30
 bob-shell/2.0.5        1         12        64k     0.01 Bobcoins

Now it shows one claude-code row and one bob-shell row. The same applies to abctl cost --by agent and each session's agent.

The rule

pipeline.AgentName(label) drops the version when the whole label is a single name/version token (^([^\s/]+)/[^\s/]+$). Anything else is returned unchanged. An unrecognised agent's label is its raw User-Agent, and cutting Claude-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.0 becomes curl), 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-code row would send agent=claude-code to a server that matches labels exactly and gets nothing back. The SESSIONS column compares against each session's agent in the same way. And every version would still count separately against the 16-series limit on a response.

  • Usage ring and each session's agent: through usage.AgentLabel.
  • Ledger, on read: in labelFor, which covers group=agent, FilterAgent and SeriesCurrenciesIn. The writer still stores the full name/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 what group=agent returned until now, matches every release of that agent, and the response names the agent ("agent": "claude-code").

Other changes

  • The sessions pane's AGENT column narrows from 19 to 11 characters. The old width existed to fit a version, so the column now also appears on narrower terminals.
  • Help text for abctl cost --agent, the agent= row in docs/pricing.md, and the godoc on the agent axis now describe the key without a version.

What does not change

  • Ledger files. Rows keep their version. The fold happens only when reading, so it can be undone or made optional later without a migration.
  • 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: ledger Fold and FilterAgent.
  • TestLedgerAndRingAgreeOnAVersionedAgent: the two sources produce the same key for the same client.
  • TestHandleUsage_AgentCoversEveryVersion: agent=claude-code and agent=claude-code/2.1.284 over both today and 1h.

Existing tests that asserted versioned keys were updated to expect plain names. TestSnapshot_GroupAgentBoundsCardinality generated its distinct agents with a / in the name; they now fold together, so it uses - to keep them distinct.

go vet passes for core, cmd/abctl and cmd/authbridge-{proxy,envoy,praxis}. go test passes for core and cmd/abctl, and go mod tidy -diff is clean for both.

Assisted-By: Claude (Anthropic AI) [email protected]

…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]>
@huang195
huang195 requested a review from a team as a code owner September 30, 2026 21:04
@coderabbitai

coderabbitai Bot commented Sep 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: a66466f8-5e3b-4ce7-8939-cb1f944ebd60

📥 Commits

Reviewing files that changed from the base of the PR and between c6ef2e9 and 753c1a9.

📒 Files selected for processing (17)
  • cmd/abctl/cmd_cost.go
  • cmd/abctl/tui/agents_pane.go
  • cmd/abctl/tui/sessions_pane.go
  • core/cost/ledger/currency_test.go
  • core/cost/ledger/query.go
  • core/cost/ledger/query_test.go
  • core/cost/usage/agent_snapshot_test.go
  • core/cost/usage/agent_test.go
  • core/cost/usage/currency_test.go
  • core/cost/usage/snapshot.go
  • core/cost/usage/usage.go
  • core/pipeline/client.go
  • core/pipeline/client_test.go
  • core/session/agent_test.go
  • core/sessionapi/usage.go
  • core/sessionapi/usage_agent_test.go
  • docs/pricing.md
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: same — the new GroupAgent doc lines exceed the file's usual wrap width.

@huang195
huang195 merged commit afb60cd into rossoctl:main Sep 30, 2026
27 checks passed
@huang195
huang195 deleted the feat/agent-fold-versions branch September 30, 2026 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants