Commit Graph
4 Commits
Author SHA1 Message Date
yetone 4578b11de2 trae 0.2.31: a token_usage counting 0 read and 0 written is unknown, not a 0% miss
feng2787 on magpie's Discord: Trae through magpie shows cache hits always
zero. The plugin passes on what Trae's token_usage says. Since 10-27 Trae
answers cache_read_input_tokens 0 (and cache_creation_input_tokens 0) on
every turn while it still bills the turn at its cache price: a real Trae CN
account on 10-29, deepseek-v4.1-flash, a 146k prompt, 5.84 credits cold and
0.12 warm, cache_read 0 on both (dingminhua/dsh-connect-trae,
docs/ISSUE69_DIAGNOSIS.md; the ratio matches Trae's cache-read/input price,
0.006/0.30). 0.2.26 made a token_usage with no cache field unknown, but a
named 0 still went on as a counted miss, so magpie showed 0%.

Now a token_usage whose cache read and write are both 0 goes on with
magpie_cache_unknown: true, which magpie (v0.1.2396 and later) shows as
unknown, not 0%. A nonzero read or a write alone (a first turn that
wrote the cache) goes as before. The cache itself was never missed; magpie
cannot make Trae report it again.

Run: bun test in packages/trae on mote, 240 pass. Broken by hand: without
the new line, "a cache read and write of 0 is unknown" fails (8 pass, 1
fail in cache.test.mjs).
Not tried: a real Trae account (none here); the 0/0 shape and the billing
come from the third-party measurement above. A real cold, short turn that
Trae caches nothing of also shows unknown now, not 0%.

Reported-by: feng2787
2026-11-06 15:02:08 +08:00
yetone 8693d77c00 trae 0.2.26: a token_usage naming no cache count is unknown, not a 0% miss (yetone/magpie#3991, #3979)
Trae CN users see cache read 0 / write 0 on every call since 10-28
(modeyang: 786 trae-cn calls on 10-29 all 0, 77 hits on 10-27; an
identical resend also 0). The plugin passes on what token_usage says:
cache_read_input_tokens / cache_creation_input_tokens. A token_usage
with no cache field at all (chansee97's real super_completion_query
capture in #455: {"prompt_tokens":1717,"completion_tokens":2,
"total_tokens":1719}) came out as a usage with no cache field, which
magpie can only read as a counted miss. CDX-5 (#434) reports Trae's
chat replies switched to that shape at 10-27 23:07; not verified with
raw bytes. Trae's own client (3.5.20, libai_agent.dylib) still has the
9-field TokenUsageEvent, so the fields exist in the protocol.

Now:
- no cache field named at all -> magpie_cache_unknown: true (as the
  Kiro plugin does), so magpie shows the cache as unknown;
- DeepSeek's prompt_cache_hit_tokens, cached_tokens and
  prompt/input_tokens_details.cached_tokens are read as cache reads
  (largest of them, so a 0 in one spelling never hides a hit);
- an explicit 0 stays a counted miss.

This cannot make Trae cache; if Trae no longer reports cache, the
plugin cannot know the hit rate.

Run (mote, bun 1.4.2):
- packages/trae bun test: 230 pass, 0 fail
- whole repo HOME=$(mktemp -d) bun test: 4324 pass, 9 skip, 0 fail
- bun scripts/check.mjs: exit 0
Broken by hand: the old index.mjs with the new tests fails 4 (3 new
cases + request.test's stream usage).

Not tried: a real Trae CN account (none available), so whether Trae
now omits the cache fields or sends 0 is not confirmed.
2026-10-31 20:21:40 +08:00
yetone 50e99c2524 trae: the token_usage TRAE CN's own client got keeps its cache read (#455)
chansee97's capture of TRAE CN's llm_utils_chat answer, byte for byte:
an id line and no space after any colon (id:30 / event:token_usage /
data:{...cache_read_input_tokens:4096...}). The plugin already reads it:
cache_read_input_tokens 4096 of prompt_tokens 4122 goes on to magpie,
streamed and not. No change to the plugin, so no version bump.

Run (mote, bun 1.4.2, sandbox HOME): bun test cache.test.mjs, 6 pass.
Broken by hand: an "event:" line with no space read as unknown makes both
new cases red (2 fail); the four older cases, built with a space, stay
green, so this is the only test of the no-space form.
Not tried: a real Trae CN account (none here).
2026-10-29 09:33:56 +08:00
yetone 4df82ce1b5 trae 0.2.12: what Trae's token_usage says the prompt cache read and wrote reaches magpie (01huadalang on magpie's Discord: K3, 53 calls, every one 0 cache hits)
tokensOf kept only prompt_tokens, completion_tokens and total_tokens of
Trae's token_usage, so every request reached magpie with no cache count
and Usage/Routing showed 0 hits. Trae's event carries more: TRAE SOLO
CN 3.5.20's ai-agent (libai_agent.dylib, the serde field list of
infrastructure/adapter/llm/event.rs's TokenUsageEvent, read from the
binary's __DATA_CONST) is name, prompt_tokens, completion_tokens,
total_tokens, reasoning_tokens, cache_creation_input_tokens,
cache_read_input_tokens, prompt_tokens_total, completion_tokens_total.

cache_read_input_tokens and cache_creation_input_tokens now go on in the
OpenAI usage under those names; magpie's gateway (chat.go cUsage) reads
them beside prompt_tokens as it reads a relay's in front of Claude, and
judges there whether prompt_tokens counts them too. An OpenAI
prompt_tokens_details.cached_tokens, if Trae sends one, is kept as it
came, and reasoning_tokens goes as completion_tokens_details. No cache
count adds no field.

cache.test.mjs (stream and single answer with the TokenUsageEvent's
fields, OpenAI's details, none) fails 3 of 4 on 0.2.11 and passes;
bun test (113 pass) and bun scripts/check.mjs trae under a temp HOME pass.
Not tried with a real Trae account (none here): that Trae fills the
cache fields for K3 in particular is not known.
2026-10-14 17:05:06 +08:00