Repository navigation
Replies: 2 comments 1 reply
|
Same file, same shape. I filed #1886 in August for two other holes in Your subagent case is the third one, with the same root cause. Two numbers from my own measurements, in case they help size it: one compaction cost 48,895 tokens that never reached the total, and a forked session double-counted its seed prefix by 5.18× and 23.05×. Checker and fixtures: https://github.com/lizhuojunx86/token-accounting-conformance/dsh-probe What I would ask for is one decision, not three fixes: is |
|
🇬🇧 English translation at the end 👇
Important 两组对账数据。2026-10-25,主会话的用量显示只有平台用量的 65%(1,443,035 vs 2,209,642),缺的部分正好是一个子代理的用量。2026-11-04,我按 @Minggle 上面提出的口径(本会话日志 + 后代会话日志,跳过 fork 继承的前缀,计入 compaction)把全部会话日志相加,与平台用量只差 0.02%。也就是说,对本地子代理,「会话成本」可以从现有的持久日志算出来。 🔍 问题根因楼主已经分析清楚:用量显示只折叠本会话日志中的 📊 实测环境:DSH 0.2.1 预发布版;平台数据来自 DeepSeek 平台用量页。
✅ 验证0.02% 的差距说明三点:
脚本按 UTC 日分组;平台用量页的日期边界我没有确认。 🧭 范围
📦 复现用法:
|
| Comparison | Result |
|---|---|
| Main-session usage display vs platform usage (2026-10-25, one session) | 1,443,035 vs 2,209,642: the display shows only 65%; the gap of 766,607 is exactly the journal usage of one subagent in that session (254,848 + 511,360 + 399) |
| All session journals incl. subagents vs platform usage (2026-11-04, the day's 5 sessions) | 8,749,503 vs 8,751,425: gap of 1,922 (0.02%) |
✅ Verification
The 0.02% gap shows three things:
- Subagent usage is completely recorded in the child journals. Only the display is missing it.
- The fork-prefix rule holds. The script cuts at the
session/end-seedmarker withinherited: truewhen the session header saysisSeeded(session). This matches @Minggle's rule: by seedLength, not byorigin. Without the cut, a forked subagent counts the parent's history twice. - I counted the
usageofassistant/messageandcompaction/summary. Two kinds are not counted: failed or retried requests (assistant/attempt, usage inside their stream) and title generation, which records no usage (session/title, session-title). The 0.02% by which the journals stay below the platform usage most likely comes from title generation: in a separate test, the platform showed exactly 1 request and 304 tokens more than the journal, and the 1,922 tokens on 2026-11-04 match one title generation per session in magnitude.
The script groups by UTC day; I have not checked the day boundary of the usage page.
🧭 Scope
- The data supports the definition proposed in this thread: session cost = own journal + descendant journals (fork prefix skipped), compaction included. For local subagents the data is already in durable journals, so the host does not need to report anything extra. One-shot external backends have no local session and were not part of this measurement.
- Until an official implementation lands, community plugins cover it: @Minggle's
dsh-token-breakdown-stats(replaces the usage pill below the composer, subagents included),dsh-cost-meterfrom Show dsh-cost-meter: per-session & daily API cost, budget and official balance in the Web GUI #692, and @kestiny18'sdsh-usage(dsh-usage:为 DeepSeek Harness 增加 Token 用量、费用估算和 52 周热力图 #1169; counts the subagents' own model calls and subtracts the seed events a fork inherits, see its README). - I can share redacted journal excerpts for a controlled repro.
📦 Reproduce
Run bash dsh-journal-usage.sh 2026-11-04 (the script is in the collapsible block above). It reads only local journals under ~/.dsh/sessions, makes no network calls, and needs bash, zstd, jq, awk and column. It prints three tables: per UTC day and model (to compare with the usage page), per session origin (main session or subagent), and the sessions with the largest volume. Each table shows the cache hit rate and a cost estimate at list prices (pricing).
更正(2026-11-09): 环境一行原写为 rc.5 / deepseek-flash,并不适用于全部数据(10-25 的子代理用的是 deepseek-v4-pro)。补充: 10-25 的差值正好等于一个子代理的用量;0.02% 的余差应来自标题生成(单独测试中,平台比日志多 1 次请求、304 token)。
🇬🇧 Correction (2026-11-09): the environment line first said rc.5 / deepseek-flash, which does not hold for all data (the subagent on 2026-10-25 ran on deepseek-v4-pro). Added: the 2026-10-25 gap is exactly one subagent's usage, and the 0.02% remainder most likely comes from title generation (in a separate test, the platform showed 1 request and 304 tokens more than the journal).
Uh oh!
There was an error while loading. Please reload this page.
一句话说明预期结果
父会话输入框下方的用量统计(token 总量、缓存命中率)应能反映该会话委派给 subagent 所消耗的 token —— 要么默认归并,要么提供明确的归并口径,并在界面上说明当前口径。
背景与调研
环境
resources/app.asar(数据段起点经文件自带 SHA256 标定)直接读取 0.2.0-rc.2 产物,并与 master(d743267)源码交叉对照现状:记账单位是一条 session log
UsagePill读useProjection('tokenUsage'),ActivityPill读useProjection('sessionStats'),两者都是单会话投影deriveTurnTokenUsage()折本会话该轮的事件tokenUsage只折叠本会话日志的用量事件(rc.2 为assistant/message/assistant/attempt;master 另含流式assistant/chunk用量分片)meta: { parentSession, origin: 'subagent' }),其assistant/message用量只进子会话日志subagent/catalog,payload 为{ version, childId, childCreatedAt, mode, label },无任何 token 字段对安装包全量扫描确认:不存在任何把子级用量归并进父会话的代码路径(token-meter 产物中
subagent出现 0 次;没有任何文件同时包含subagent/catalog与用量桶字段)。所以这是架构设计而非 fold 漏字段;缺的是「后代用量归并」这一口径及其展示。
用户影响
fork后端的子会话以父日志已完成轮次前缀为种子,子会话自身统计含有继承来的父会话用量,父子两侧数字相加会双计目前可用的查看途径
tokenUsage桶之和)与活跃轮次耗时,见 packages/client/ui-subagent/README.zh.md可行性旁证
社区插件 dsh-cost-meter(#692)已实现「Billing is taken from the usage block of every model call (including subagents, compaction, title generation)」,说明 host 侧按会话拿全量子级用量完全可行,缺的只是官方 UI 的归并口径。
关联讨论(已查重,1200 条讨论中无同一问题)
建议方向(不限定实现)
A. host 侧记账:在
subagent/catalog或结算事件中携带子级 usage 四桶,token-meter 增加一类「归并用量」事件 / fold。需处理:递归深度(descendants)、重试 attempt 去重、fork 种子的继承去重、一次性后端无本地会话时的上报路径、跨进程(SDK / ACP)场景。
B. client 侧聚合:
UsagePill同时消费subagentCatalog投影,并按需拉取子会话tokenUsage。代价:子会话未必已加载,需要按需查询,时序更复杂。
C. 仅展示层说明:在用量弹层标注「不含 subagent 用量」并给出跳转入口。成本最低,可作为 A/B 落地前的过渡。
验收与细节
All reactions