trace: Claude Code's `<synthetic>` notices count as requests and can make a Claude session price on the fallback curve
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 20/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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:
requestsis too high by one for every notice. This number is in the ledger and inte status.- If the notices outnumber the real replies,
modelbecomes<synthetic>.pricing.weights_forhas no entry for it, soaccounting.effectiveprices a plain Claude session on the fallback curve and recordspriced_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.
- Ngôn ngữ chính
- Python
- Star
- 5.6k
- Fork
- 344
- Merge trung bình
- 14 giờ 41 phút
- Pull request đã merge (30 ngày)
- 54
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/TokenEconomizer
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
microsoft/TokenEconomizer#193 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
pricing: Claude's 1-hour cache writes are priced at 1.25x, but billed at 2xCó thể đã có người làm @anascherif đã nhận hôm nay. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
microsoft/TokenEconomizer#191 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
microsoft/TokenEconomizer#186 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
plugin: the agent-output readers crash on a JSON line that is not an objectCó thể đã có người làm @rahul05ranjan đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
microsoft/TokenEconomizer#182 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
trace: the cursor readers crash on a JSON line that is not an objectCó thể đã có người làm @rahul05ranjan đã nhận 1 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 25/100
microsoft/TokenEconomizer#180 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của microsoft/TokenEconomizer
Issue tương tự
-
area: providers/aws priority: p2 size: S type: bug type: testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
finos/open-resource-broker#851 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
sandialabs/atlas-ui-3#1196 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
ShaftHQ/SHAFT_ENGINE#7902 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: GraphML export writes invalid XML when a value contains a control character (e.g. form feed)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
topoteretes/cognee#6646 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
DOI-USGS/pywatershed#428 ·