trace: Claude Code's `<synthetic>` notices count as requests and can make a Claude session price on the fallback curve

オープン
#189 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@1AbdullahButt がすでに取り組んでいます。

2026年11月9日 から。

  • #190 @1AbdullahButt による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
20/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
ai, backend

調査の方向性

Read tokeneconomizer/trace/claude.py around claude_session_usage and the linked accounting code in tokeneconomizer/plugin/accounting.py. The issue includes a reproduction and expected output; compare how synthetic assistant entries affect request counting and model selection. Done means the reproduction reports one request, the real Claude model, and model pricing. A linked pull request is already open.

索引モデルが issue の本文から書いたものです。

説明

When a request fails, or there is nothing to answer, Claude Code writes its own notice into the session log as an assistant entry. The entry has "model": "<synthetic>", its own message id, and a usage object of zeros. For example:

{"type": "assistant", "isApiErrorMessage": true, "message": {"id": "046e4526-...", "model": "<synthetic>", "role": "assistant", "usage": {"input_tokens": 0, "output_tokens": 0, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0, ...}, "content": [{"type": "text", "text": "API Error: Can't reach the API server ..."}]}}

I see these in my own logs for "API Error: ..." and "No response requested.".

claude_session_usage (trace/claude.py#L298-L315) counts each of these entries as a request and as a vote for <synthetic> as the session's model. So:

  • requests is too high by one for every notice. This number is in the ledger and in te status.
  • If the notices outnumber the real replies, model becomes <synthetic>. pricing.weights_for has no entry for it, so accounting.effective prices a plain Claude session on the fallback curve and records priced_by: "fallback". The accounting docstring says Claude ids never need the fallback. The fallback weighs output at 6x, where Claude's curve uses 5x.

The token totals are right, because the notices carry zeros.

Repro (on main at 264e7a7): one real reply, then two notices.

import json, os, tempfile
from tokeneconomizer import trace
from tokeneconomizer.plugin import accounting

def asst(mid, model, usage):
    return json.dumps({"type": "assistant", "message": {"id": mid, "model": model,
        "role": "assistant", "content": [{"type": "text", "text": "x"}], "usage": usage}})

zero = dict.fromkeys(("input_tokens", "output_tokens", "cache_creation_input_tokens",
                      "cache_read_input_tokens"), 0)
real = {"input_tokens": 10, "output_tokens": 200, "cache_creation_input_tokens": 1000,
        "cache_read_input_tokens": 5000}
p = os.path.join(tempfile.mkdtemp(), "s.jsonl")
open(p, "w").write("\n".join([asst("msg_1", "claude-sonnet-4-5", real),
                              asst("u-1", "<synthetic>", zero),
                              asst("u-2", "<synthetic>", zero)]) + "\n")
u = trace.claude_session_usage(p)
print(u["requests"], u["model"], accounting.effective(u))

Expected: 1 claude-sonnet-4-5 (2760.0, 'model')
Actual: 3 <synthetic> (2960.0, 'fallback')

I have a fix with a regression test and will open a PR.

主要言語
Python
スター
5.6k
フォーク
344
平均マージ
14時間 41分
マージ済み PR(30日)
54

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/TokenEconomizer のほかの issue

microsoft/TokenEconomizer の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。