zcbot/tests
caoqianming af2ad3cef1 feat(usage): 记账给前缀缓存命中折价 + 前端体现缓存命中/真实成本
排查"rust→PPT"task(flash,34 轮)发现累计 tokens_in 69.9 万里 88.6% 是缓存
命中,但 _fallback_chat_cost_cny 把命中段也按 input 全价算,记账虚高 2-3x。

- capabilities: 加 cache_hit_cny_per_mtoken(deepseek flash 0.1 / pro 0.2;
  0=不区分按全价兜底,绝不少记)
- usage: 成本公式拆三段「命中×缓存价 + (input−命中)×input价 + output×output价」;
  loop 把 cache_hit_tokens + 缓存单价透传进 record_chat_usage
- web: 不加 DB 列。app.py 加 _usage_aggregates(单查询 GROUP BY usage_events,
  复用列表 msg_counts 批量范式,无 N+1)on-the-fly 算每 task 真实成本 + 缓存命中,
  _task_dict 带出;dev.html 列表行显 ¥、顶栏 formatTaskUsage 显「tok·缓存命中%·¥」
- scripts: backfill_chat_cost_cache_discount.py 按 units 已存 token 重算历史
  cost_cny(只改成本列,默认 dry-run,--apply 落库)

折价只对新 chat 事件即时生效;历史走 backfill 脚本(部署后跑)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 08:26:09 +08:00
..
test_context_compaction.py perf(context): 压缩旧 assistant tool_call arguments + keep_recent 20→12 2026-06-05 08:25:56 +08:00
test_disk_quota.py Stage C 收尾包:资源 yaml + 磁盘配额 + 网络放开 + 容器内源持久化 2026-05-27 08:35:53 +08:00
test_executor_docker.py Reduce chat context token usage 2026-06-04 16:41:14 +08:00
test_load_skill.py fix(skill_tool): docker backend 下返回容器路径而非 host 绝对路径 2026-05-28 13:37:19 +08:00
test_run_python_script_path.py Reduce chat context token usage 2026-06-04 16:41:14 +08:00
test_sandbox_check.py Stage C Step 5: main.py sandbox check + lifespan fs quota WARN 2026-05-26 16:41:16 +08:00
test_secret_host_tools.py fix(tools): MP 工具改服务端限量查询,止血 IP 被封根因 2026-06-01 15:11:16 +08:00
test_static_vendor.py Reduce chat context token usage 2026-06-04 16:41:14 +08:00
test_tool_output_compaction.py Reduce chat context token usage 2026-06-04 16:41:14 +08:00
test_usage_accounting.py feat(usage): 记账给前缀缓存命中折价 + 前端体现缓存命中/真实成本 2026-06-05 08:26:09 +08:00