On one account Trae CN's desktop client's claim went through while the
plugin's, on a device id it had made up (digits(19)) with a hard-coded
brand and OS, came back 9074 every day (MiFaZhan on yetone/magpie#808;
aliceh1 on #1920, where Buddy Switch reads the local client). Now, for a
check-in (/trae/api/v2/ug/*) only, the account whose uid matches the
userId of this machine's Trae CN client sends the client's own device id,
the one Trae's device service registered: the digits in the client's
storage.json key iCubeAuthInfo://icube-dc:<id> (seen in real clients'
files, #808 and #1705). x-device-type and x-os-version are this machine's
(Windows' product name, else its build; elsewhere the kernel release),
and no brand is sent, as the client's fb leaves it out with no model.
The uid comes from the client's sign-in envelope
(iCubeAuthInfo://icube.cloudide), plain JSON or the client's fixed
AES-128-CBC codec, read as dingminhua/dsh-connect-trae (MIT) reads it;
only userId is looked at, the client's token is never used. The file is
only read, never written. Every other account keeps its own device; a
missing or unreadable file, one that can't be made out, a failed
integrity check, or zero or several icube-dc keys change nothing. No id
is made up, changed or rotated (the owner's ruling on #1705 stands).
Ran: bun test in packages/trae, 140 pass (11 new in ownclient.test.mjs);
bun scripts/check.mjs trae ok. Broken by hand: matching every account
instead of the client's uid fails "an account the client isn't signed in
as keeps its own device"; not passing the client's device to ugHeaders
fails the two matched-account tests. Tests never read this machine's
client (fake.mjs points ownClient.paths at nothing). Not tried: a real
Trae CN client or account (none here), so whether the claim now goes
through for the matched account is unproven; the Linux paths are guesses.
#106 merged as 0.2.12, which main had already published for the cache
fix (4df82ce), so it needs its own version to reach npm. Version bump
only. Ran: bun test in packages/trae, 129 pass.
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.
XcodeFish (trae-cn/glm-5.3-flash under Codex) saw eight texts of their own
beside real calls: ]</tool_call>, </tool_call>, }</tool_call>,
]}]}}"}}}}</tool_call>, }}</tool_call>, "></tool_call>. And an
exec_command's heredoc reached Codex cut wrong.
- After a call's JSON, braces, brackets, quotes, a > and blanks up to the
close are taken with the close (held while only those have come).
- A close with no call open is dropped with that leftover before it: when
nothing but blanks came since the start or the last call (the tail of a
call Trae's service read itself), or when the leftover is right before
it. A close a sentence names in passing, or one in backticks, stays.
- A call's object that ends early, with other text after it before the
close, is a quote inside a string left unescaped: the block is read up
to the close (quoteFix reads the heredoc whole), and when it can't be,
the turn fails as unreadable, so the gateway can try again, instead of
a cut command plus the rest as text.
Not reproduced: the issue's cmd that swallowed ","yield_time_ms":180000}.
No mutation of quotes and backslashes in a JSON or string-encoded call
(624 tried) gives it through this parser; it may have come from Trae's own
tool_calls. Asked the reporter for the raw stream.
Run: tailjunk.test.mjs (6 tests, the issue's tails at piece sizes 0/1/3/7,
a native call with its tail split across events, the heredoc) fails 5 of
6 on the old index.mjs; HOME=<tmpdir home> bun test for the repo, 1184
pass 0 fail; bun scripts/check.mjs green.
@shad70w0 on X: "magpie + Trae 插件实测没办法走企业订阅" - a Trae enterprise
subscription couldn't be used through this plugin. The sign-in URL sent
hide_saas_login=true (copied from the relays in 6c048c7), which hides the
enterprise/SSO sign-in on www.trae.cn/authorization and
www.trae.ai/authorization, so an enterprise user could only sign in as a
personal account.
What changed:
- the authorization URL sends hide_saas_login=false.
- traeHost: a host a sign-in names is taken only when it is a well-formed
https host (no port, credentials, query) on trae.cn, trae.ai or
mchost.guru; anything else is ignored and the consumer host used, as
before.
- Trae CN: a sign-in host on mchost.guru / trae-api-*, or another trae.cn
host than www/api/grow*, is the account's model host. Trae Global: a
trae.ai host other than www/api-*/grow* is too, after the existing
US/coresg rules. Personal hosts (api.trae.cn, api-us-east, api-sg-central,
growsg-normal, coresg-normal) route as before.
- the sign-in's host (host), a token host the callback names (authHost /
auth_host / userInfo.AuthHost, on the realm's own domain only) and the
userInfo's tenant/enterprise/login-type fields (account; no field that
looks like a secret) are kept in the auth record. Renewal (sign-in and
refresh) goes to authHost when one is kept. Nothing new is sent.
- README: enterprise sign-in is offered, not tried with a real enterprise
account.
Run: bun test in packages/trae (103 pass, 6 new in enterprise.test.mjs);
the whole repo's bun test with HOME under a scratch TMPDIR (1168 pass, 0
fail); bun scripts/check.mjs. Each change broken by hand turns
enterprise.test.mjs red: hide_saas_login back to true, no enterprise CN
host, no domain check, http allowed, refresh at the consumer host, no
account kept, api.trae.cn taken as a model host, a secret-looking field kept.
Not tried: no real enterprise account. Which host(s) and fields an
enterprise sign-in sends back is unknown; the hosts in the tests are made
up, and whether the callback ever names an auth host is a guess.
XcodeFish's two leaks on 0.2.6, still on 0.2.8: glm-5.3-flash wrote
<toolcall></toolcall>, and a reply ended at "<tool_call name". Both went
out as the answer with a 200.
- The opener, close, leftovers and held marks take <toolcall> and
</toolcall> too; an empty block is dropped as <tool_call></tool_call>
is, one with JSON or parameters is a call, one that can't be read is
the error it is for <tool_call>.
- At the end of a reply, an opener still open (<tool_call, <tool_call
name) outside backticks or a fence ends the turn with the cut-short
error.
Run: the issue's repro (A-G) on main and on this; the new test fails on
the old index.mjs (1 fail) and passes here; HOME=$(mktemp -d) bun test
for the repo, 1153 pass 0 fail; bun scripts/check.mjs green.
Asked to write each call as {"name":…,"arguments":{…}}, a model on Trae
sometimes wrote the arguments wrapped again, {"arguments":{…}}, and the
plugin passed that on: bee2an's agent got
{"arguments":{"content":"P\n\n","path":"…/trail2.txt"}} for its write and
wrote nothing useful.
Every call, from a block in the text or from Trae's native tool_calls,
streamed or not, now goes through one step in parts(): a lone arguments,
input, parameters or args key holding an object (or a JSON string of one)
is taken off, up to three layers, when the request's tool has no
parameter of that name. A tool whose own parameter is called input keeps
it, and a call to a tool the request doesn't list is left as it is.
Run: bun test in packages/trae, 96 pass. unwrap.test.mjs uses the
reporter's arguments byte for byte; its three tests fail with the step
stubbed out.
Trae's usage page books a request under the name of the list it was served
through, and its lists name a model differently: chat_v3 calls
deepseek-v4.1-flash "DeepSeek-V4-Flash 正式版", where the SOLO lists call it
"DeepSeek-V4.1-Flash" (yetone/magpie#681). On 2026-10-09 Trae renamed its
official entries — DeepSeek-V4-Flash-Official is "DeepSeek-V4-Flash" now —
which left chat_v3 the only list still calling deepseek-v4.1-flash by
another's name, so the collision the misnamed test leans on no longer
matches and chat_v3's entry won on list order alone: the page then showed
"DeepSeek-V4-Flash 正式版" for every request, where Trae's own client, served
through a SOLO list, shows "DeepSeek-V4.1-Flash".
A model's name is now the one most of its lists give it — the name Trae's
own client is served under — and the entry carrying it is preferred for the
model's window, reply limit and serving function, as is the Max entry asked
for it. deepseek-v4.1-flash goes back to "DeepSeek-V4.1-Flash", a 200K
window and a 32K reply limit (was 116K/16K from chat_v3's entry), asked
through the SOLO list that names its __dev/__max models.
Co-authored-by: 李 <oncwnuKMG1gRkPtw27nJROKWWRUM@git.weixin.qq.com>
* trae: one conversation keeps one session_id
The plugin gave every request a fresh `randomUUID()` for both `request_id`
and `session_id` (chatBody), so each request of one agent turn reached Trae
as a different session. Trae counts a conversation by the session its
requests name: a user send that takes several steps (a tool result sent back,
a retry, another function answering) was counted as several conversations,
each a row of its own in the usage detail with no conversation under it —
which is what showed as "Prompt" where the IDE's own sessions show their
title.
`session_id` is now the conversation's, as the IDE keeps one per
conversation: the session magpie (or OpenCode) names the request by, carried
from a new `chat.headers` hook, else the chat's first user message, which
every later turn repeats. Nothing is made up when neither names one — a
made-up conversation of the request's own is the splitting this ends — and
the caller then makes a fresh id per request, as before. The id is salted, so
it says nothing of the words it was made from, and keeps the UUID shape
`randomUUID()` returned. `request_id` stays the request's own.
The title column is not this fix: the IDE's titles are generated by its agent
(`session_title_message`) and reported through its hub, which has no call on
the path this plugin takes. With the session stable, Trae has one
conversation to hang a title on, once it is sent one.
* trae: a conversation is named with the account answering it too
The id a chat's session_id is made of was the conversation alone, so when
magpie failed over, or rotated, between two Trae accounts inside one
conversation, both accounts were sent the same session_id — an id the fresh
random one before it never linked, and one Trae can read one account's
conversation as another's. The account (its uid, else its name) is now part
of what the id is made of: conversationID(req, session, who), who being the
account already resolved just above the request.
The cost, as the comment says: a conversation answered by two accounts is
counted as two again, which is what it did before it was named at all.
Two tests: two accounts of one conversation (named by magpie's session and
by the chat's own first message, and an account named by its name alone) are
two conversations to Trae, and one account's two conversations stay two.
The first fails with the account left out of the id.
---------
Co-authored-by: tearslee <16331052+tearslee@users.noreply.github.com>
Co-authored-by: 李 <oncwnuKMG1gRkPtw27nJROKWWRUM@git.weixin.qq.com>
#38 (deepseek-v4.1-flash on trae-cn): 64 of 3112 turns came back with
the model's text-form <tool_call> block as the answer, no call made, as
a 200 with a normal finish, so the gateway had nothing to fail over on.
ARNO (trae-cn, Discord) sent two more: a write whose JSON is whole but
has no </tool_call> (the stream ended), and a closed write block.
ARNO's two replies, as sent (content redacted to xxxx), are read as calls
by 0.2.4 too, whole or one character at a time, with the tool declared
as write or Write; prose before the block and arguments as an object
don't matter. What breaks the closed one is in its content: a written-out
analysis with a quote left unescaped ("官方"), a backslash JSON doesn't
know (\| \_ C:\Users) or a JSON sample of its own makes JSON.parse fail,
and 0.2.4 then printed the block as text. Those are the fixtures here.
TextTools now:
- reads a block as models get its JSON wrong: every quote escaped
({\"name\":…}, #38's most common shape), unknown backslash escapes
doubled, and quotes inside a string escaped unless they end it (a key's
before its colon, a value's before closing braces and the end or a
comma and the next key);
- takes an opener with attributes, <tool_call name="bash"> with
<parameter name="k">v</parameter>, and DeepSeek's {"name":"x"}> head
with parameters (magpie's paramCall, #917), its values typed by the
tool's schema;
- when a block is closed but can't be read, or is cut short at the end
(JSON not whole, a parameter not closed), returns an error instead of
the text: parts() yields it, so a stream ends with the error event and
[DONE] and no finish, and a body is a 502;
- leaves a <tool_call> in backticks or a code fence, or named in prose
with no JSON after it, as text.
Not done: #38's fourth point (text on done/response_done events): there
is no raw event showing Trae puts text there, and reading it blind could
send a whole reply twice.
textcall.test.mjs builds from ARNO's literal bytes and #38's repro cases.
Against 0.2.4's index.mjs 4 of its 6 tests fail (the two that pass are
ARNO's literal replies, which 0.2.4 already reads). HOME=$(mktemp -d)
bun test: 870 pass, 0 fail; bun scripts/check.mjs passes. Not tried with
a real Trae CN account.
magpie's host builds a provider's models from the plugin's config first
(internal/plugin/host.js: the config's flat fields are spread into
capabilities), then lets the provider.models hook replace the list. The
hook handed back each model without capabilities, and magpie reads
capabilities.reasoning alone for a model a plugin lists, so every model
the site's fallback table doesn't have was listed as one that doesn't
reason. On Trae CN that was every model but the table's six; on Trae
Global every model but its five. A routing group with one of them in it
lost reasoning for the whole group (magpie's groups take a member that
thinks), and the agent turned thinking off for it.
modelOf now gives each model it builds capabilities: the fallback table's
own where it has an entry, else MODEL's flat fields (reasoning,
temperature, tool_call, the input modalities) with an empty variants, as
Trae's request takes no effort or thinking level. The Max twin takes them
through the same path.
packages/trae/models.test.mjs (5 tests) fails without the change:
capabilities.reasoning is undefined for deepseek-v4-flash-0731-max, for
the whole list, and for the Max twin; the fallback table's own entry and
Trae Global's models pass either way. bun test packages/trae: 79 pass.
bun scripts/check.mjs: every package ok. The whole suite has the same 40
failures before and after (Windows-only, other packages).
mintonight found the cause on #808: a JWT renewed at /cloudide/api/v3/trae/oauth/ExchangeToken carries no device, and Trae CN answers its check-in claim 9074 every time, while the client's own token is let through. Trae CN now renews as its clients do: POST /trae/api/v3/oauth/ExchangeToken with DeviceInfo (the device id, machine id and a per-account ECDSA P-256 public key, PEM) and DeviceProof (the key's ECDSA-SHA256 signature, base64, of POST, the path, ClientID, RefreshToken, Timestamp and Nonce, one to a line), as TRAE SOLO CN (en1oxy7wnw8j9n, SOLO_PC) first, then Trae CN's IDE (ono9krqynydwx5, IDE_PC). That renewal keeps the refresh token. The key pair is made at sign-in, or at the first renewal of an account signed in before, and kept with the sign-in through auth.refresh's fields; a sign-in's token is bound at once. When Trae turns the bound renewal away, the plugin renews at /cloudide/ as before. Since the refresh token can stay the same, a renewal made here is told from the sign-in by its token rather than by the refresh token. Trae Global is unchanged. device.test.mjs is new: 5 of its 6 tests fail on 0.2.2 (the Trae Global one passes on both). No Trae account to test with; mintonight is asked to verify on #808.
Trae's llm_utils_chat streams a call's arguments as snapshots, and may send
the whole call again written apart from the partial one (U+2212 for -,
U+2032 for '), which neither extends it nor follows a whole one, so
NativeCalls joined the two and the call's arguments came out twice. A
whole JSON object under the same first key as the partial arguments, which
the two joined don't make whole, now replaces them. A piece that is a
JSON value of its own (12, "ls", {}) still joins the call: it doesn't
open with the call's first key. The new test of the resent snapshot fails
without the change; the one of pieces that are values of their own
passes either way. bun test (trae: 68) and bun scripts/check.mjs pass.
Trae CN's check-in answered magpie with 9074 「当前参与用户太多,请稍后再试」
every time: whqtian's three accounts never got in (the fourth only when
checked in by hand in Trae), Moody-Sin's never did. magpie retried every
30 minutes and got 9074 again. The plugin sent the check-in with Bun's own
User-Agent (Bun/1.x), the chat's headers (x-uid, x-ide-token, versions…)
and {}. Trae CN's IDE 3.3.104 (main.js, read from the official linux
build) sends /trae/api/v2/ug/checkin_credits/status and /claim with only
its Cloud-IDE-JWT and its device (fb: x-device-id, x-device-brand,
x-device-type, x-os-version, x-app-version) through its own client, body
{req_source: 1}; qilimixingkong/trae-checkin found that a check-in without
a real client's User-Agent is taken for a script and answered 9074. A
growth page (/trae/api/v2/ug/…) now goes with those headers, a TRAE SOLO
CN Electron User-Agent and {req_source: 1} for an empty body; Trae's
other pages still go with the chat's headers. 0.1.7 tried the IDE's
headers and body without a User-Agent and was put back in 0.1.9; the
User-Agent is what neither had. No device id is changed to get round a
9074 or a 9095. No Trae CN account was at hand, so it isn't tried
against a real one: api.trae.cn answers the new request without a token
with its usual 1001. checkin.test.mjs checks the body, the IDE's headers,
the User-Agent and none of the chat's (fails on 0.2.0), a body given as
is, and Trae's other pages unchanged; bun test (66) and
bun scripts/check.mjs trae pass.
* trae: one package, two realms — Trae Global folds into packages/trae
The review asked for this and it is the right shape: the two deployments
share one implementation. 86 of the 89 top-level names were already the
same code; what differed was a table's worth of values (hosts, client,
versions, usage page, fallback models, error codes) and two realm-only
branches. A separate copy meant every request, stream and tool-call fix
had to be made twice, and it had already drifted (the 0.1.15 Max fix
came back as a bug there).
packages/trae now holds a SITES table with two entries — trae-cn and
trae-global — and makePlugin(site) builds a provider from one. Exported
as TraeCNAuthPlugin and TraeGlobalAuthPlugin. The CN values are moved
verbatim, not re-derived: same hosts, client id, app id, IDE/client
versions, plugin version, brand, functions, fallback models, credits
page, and its own check-in pages. The international entry carries what
only it has: the second (US) deployment and the region that selects it,
the dollar billing's entitlements page, its own model names, and its
extra lapse/quota codes (20101, 4011).
The CN plugin needs the stream fix too (the review's point), so the
AbortController the loader now builds per request, openai()'s abort, and
sse()'s finally are in this one implementation for both realms — as is
the wrong-function retry releasing the read it leaves behind.
fake.mjs takes a realm id, defaulting to CN so every test written before
the fold is unchanged. The global tests move to global.test.mjs, plus
new ones for what only the international realm does: the US/SG routing
of a request and of a saved sign-in, its own error codes and error name,
the dollar usage page, and its fallback model list. chatModel gains the
picker's invisible-entry filter (paygo/auto twins, search agents) and
the config hook names the realm's own provider.
The acceptance test: packages/trae/*.test.mjs' 48 CN tests are untouched
and green — that is the proof the refactor changed no CN behaviour, with
its constants verified line by line against HEAD. bun test: 63 pass
(48 CN + 15 global); bun scripts/check.mjs trae: ok.
registry.json: one entry, providers [trae-cn, trae-global]. README: both
realms, each realm's endpoints, usage page and codes; the verification
range stated honestly (CN never run live; Global on one Free SG account,
no Pro and no US account).
* trae: Trae CN's model lists stay whole; only Global hides is_invisible_to_user
The fold filtered is_invisible_to_user for both realms, which took 40 of
Trae CN's 76 models out of its list. CN is served as before; Global (a
site flag, hidesInvisible) keeps the filter. Also: the unsupported-request
error names the realm, and two duplicated/merged comments are tidied.
---------
Co-authored-by: yetone <yetoneful@gmail.com>
0.1.2 still showed no DeepSeek V4.1 Flash: its lists came from get_detail_param, one function at a time, sent as the Trae CN IDE 3.3.65 (version code 20260401). The reporter's TRAE SOLO CN 0.1.69 (version code 20260917, same app id) asks POST /api/ide/v1/batch_get_detail_param on trae-api-cn.mchost.guru (its ai-agent log, get_model_list -> batch_get_model_detail_param; 290 configs cached), and picks deepseek-v4.1-flash from it; two other open tools that list it (smart-open/TraeWorkAssistant, zhengwuji/Jet-Hub) ask the same batch, as a 0.1.5x SOLO client, and find it under solo_agent with model_name deepseek-v4.1-flash__dev.
Now the lists come from batch_get_detail_param (functions chat_v3, solo_work_lite, solo_agent, solo_agent_lite; agent_type "", access_type 0, show_custom_model), with get_detail_param per function when the batch gives none; the model host is told the client is 0.1.69 / 20260917 (x-ide-version, x-app-version and their codes). A model several functions list is asked through the first whose entry names a __dev model, and that model goes as model_name. The IDE's helpers (usage other than chat_completion: summary, fast_apply...), configs switched off and custom-model slots are left out of the list; names come from display_config.display_name, context from context_window_tokens.dev (max is Max mode's), output from the __dev model's max_tokens.
usage.test.mjs: the batch test (one ask, its body and version headers, DeepSeek-V4.1-Flash listed with 200000/64000 and asked through solo_agent as deepseek-v4.1-flash__dev) and the signed-out batch test fail on 0.1.2 and pass; bun test (24 pass) and scripts/check.mjs trae pass. Not tried with a real Trae CN account (none here).
Trae CN 3.3.104's agent-type map (libai_agent.dylib manifests/mapping.json)
files deepseek-v4.1-flash under the "trae" agent only, which is function
solo_agent; solo_work_lite (SOLO Work) lists DeepSeek-V4-Flash-Official and
the custom_model_deepseek_* ones the issue shows. get_detail_param is now
asked for chat_v3, solo_work_lite and solo_agent, merged, and a model is
asked through the function that lists it. Not tried with a real account.
DeepSeek-V4.1-Flash, which Trae CN's SOLO picker offers, was missing from
magpie's list: the plugin read the account's models from
/api/ide/v1/get_detail_param for chat_v3 (the classic IDE's chat) only, and
SOLO's models (the user's list showed DeepSeek-V4-Flash-Official and the
custom_model_* entries of chat_v3, no V4.1) come under solo_work_lite. Now
the list is asked for every chat function (chat_v3, solo_work_lite) and put
together, chat_v3's first; one list failing leaves the other's, a lapsed
sign-in still throws. A model only SOLO lists is asked through
solo_work_lite first, the 4001/4023/1005 fallback kept.
usage.test.mjs "SOLO's models are listed too" fails on 0.1.0 (V4.1 absent)
and passes; bun test: 21 pass. Not tried with a real Trae CN account (none
signed in here).
Sign-in is trae.cn's authorization page back to a 127.0.0.1 /authorize
callback (userJwt + userInfo, or a refresh token exchanged), with a device
made at sign-in and kept for the account. ExchangeToken renews the JWT
through auth.refresh (refreshLead 10 min, one renewal per refresh token).
Requests go to the IDE agent's llm_utils_chat (chat_v3, then
solo_work_lite on 4001/4023/1005), its SSE events turned into OpenAI
chunks; tools named natively and as <tool_call> blocks. Usage is the
entitlement packs' credits. Worked out from wangqi233/trae2api and
autumnsentiment/Trae2api-cn; not run against a real account.