Repository navigation
Conversation
R6 follow-up. The sidecar has reported the children's share of a turn since R5 (`child*Tokens`, `children[]`, `unknownUsageChildren`), but nothing in the desktop UI read it. Each child row shows only THAT child's bill, so the parent's own spend appeared nowhere and "what did this turn cost, and how much of it was sub-agents" was unanswerable from the interface. - `turn_usage` SSE event, emitted at turn end just before `message_id` — the same slot and archival rule as `turn_files`, so it lands on the persisted message and hydrates after a reload. - The card now prints one line under the child board: the turn total and the sub-agents' slice with its share. Two readings are easy to get wrong and are pinned by tests: `usage.totalTokens` is the PARENT's own bill and `childTotalTokens` is the children's; they are additive, not total-and-part-of-it. The first implementation subtracted, which under-reported every turn. Writing the test against the sidecar source caught it. A turn whose children report no tokens at all (external ACP engines) still renders the line, marked `partial` — otherwise the smaller number reads as a complete bill, and a turn that delegated looks like one that didn't. Cost is deliberately not shown: `costUsd` estimates the parent's model only, and children may run on others, so presenting it as the turn's cost would understate it. Verified: web 973 passed, agent-shell ts 1646 passed; tsc clean in both. Signed-off-by: Wang Tai <i@wangtai.me>
Signed-off-by: Wang Tai <i@wangtai.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
sidecar 从 R5 起就在
stream.done.usage里报了子代理的花费(child*Tokens/children[]/unknownUsageChildren),但桌面端一个字段都没读。子代理看板每行只显示该子代理自己的 token,父代理的花费不在任何一行里——于是「这一轮花了多少、其中子代理占多少」在界面上无处可读。改动
turn_usageSSE 事件:回合收尾时发一次、赶在message_id之前,与turn_files同槽同归档规则,因此会落到持久化消息上、刷新后水合。两处容易读错的语义(都有测试钉住)
usage.totalTokens是父代理自己的账单,childTotalTokens是子代理那一部分,二者并列相加才是整轮成本——不是「总计与其中一部分」。第一版按后者实现,让每一轮都少报,写测试时对着 sidecar 源码才发现。一个子代理都没报 token 的回合仍然渲染那一行,标
partial。否则偏小的数字会被读成完整账单,而一个确实派过活的回合看起来像没派。刻意不做
不显示成本。
costUsd只估算父级模型,子代理可能跑在别的模型上,拿它当整轮成本会偏低。宁可只报 token,也不报一个错的钱。验证
agent-shell/web973 passed,agent-shell/ts1646 passed,两边tsc --noEmit干净turn-usage.test.ts(12)、TurnUsageLine.test.tsx(6)、router 两条(事件顺序 + 落库)Made with Cursor