Commit Graph
3 Commits
Author SHA1 Message Date
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