Skip to content

fix(cli): include subagent costs in ACP usage updates - #65618

Open
BambinoSK wants to merge 2 commits into
anomalyco:devfrom
BambinoSK:acp-subagent-cost
Open

BambinoSK wants to merge 2 commits into
anomalyco:devfrom
BambinoSK:acp-subagent-cost

Conversation

@BambinoSK

@BambinoSK BambinoSK commented Nov 22, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #65616

Type of change

  • Bug fix

What does this PR do?

usage_update reported only the root session's cost. Core stores each subagent's spend on its own session, so
ACP now adds up the session and all its descendants by paging session.list({ parentID }), the same way the
TUI computes a session family's cost. No core or protocol changes. Earlier attempts (#43645, #50737) added
the subagent costs inside core; this keeps the fix inside ACP.

The test fixture's fake session.list now filters by parentID like the real server does.

How did you verify your code works?

New test in test/acp/prompt.test.ts: root $1.50 + subagent $2 + its subagent $0.25, plus an unrelated $10
session, reports 3.75. Without the fix it reports 1.5. All ACP tests and the cli typecheck pass.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The change looks good. I ran the new wire test on the base branch: it reports 1.5 there and 3.75 with this change. All ACP tests and the cli tsc -b pass. The total adds up the session and all its descendants, the same way the TUI does for a root session, and it runs once per turn at settle, so the extra session.list calls are cheap.

Public API: unchanged. Only the value of the cost field in ACP usage_update changes.

One small concern is inline: if listing the subagent sessions fails, the whole usage update is now dropped.

Comment thread packages/cli/src/acp/turn.ts Resolved

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fix for my earlier point works: when the subagent lookup fails, the usage update is still sent with the session's own cost, interruptions still pass through, and the new 500 test covers it. I also ran the #65616 reproduction from source with a mock provider. A subagent spent $100, and usage_update reported $3 on base and $103 with this PR. test/acp/prompt.test.ts and the cli tsc -b pass.

Public API: unchanged. Only the value of the cost field in ACP usage_update changes.

No further concerns.

Core stores each subagent's spend on its own session, so the ACP
usage_update cost now sums the session and all its descendants,
the same way the TUI computes a session family's cost.

Closes anomalyco#65616

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The code is unchanged since my last review: the new commits have the same tree as 364efba and differ only in their messages. The earlier results still hold (#65616 reproduction: $3 on base, $103 with this PR; the prompt tests and the cli tsc -b pass).

Public API: unchanged. Only the value of the cost field in ACP usage_update changes.

No further concerns.

This branch has not been deployed

No deployments
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.

acp: usage_update cost leaves out subagent sessions

1 participant