moxuanchen's change for #361 (a second Trae CN account can't check in).
- Every Trae CN client profile is read (Trae CN, TRAE SOLO CN, trae-cn):
the one signed in as the account gives its device. A profile signed in
as someone else, or one that doesn't parse, no longer hides the rest.
- A claim's code 0 is read back from the status. Not in after the claim
is `ineligible` for the day (no repeat claims); a failed read-back is
ineligible too.
- 9074's message says Trae did not take the check-in for this account's
device, and no longer sends people to Trae CN's app.
- Credit: the claim's credits, else its extra_credits, else the
read-back's credits; never summed (matches 0.2.21).
- Version 0.2.22, README updated.
Run at the reviewed head 4006fef51 (rebased on ba9801c), sandbox HOME:
- packages/trae: bun test, 213 pass, 0 fail. bun scripts/check.mjs: trae ok.
- Broken by hand, each red: first profile decides (2 red), no read-back
(2 red), failed read-back reported as failed (1 red), credits summed
(2 red), TRAE SOLO CN folder dropped (1 red). Restored after.
Not tried: a real second Trae CN account, and TRAE SOLO CN's real
storage.json (its folder and keys are inferred, as the README says).
A status that lags a claim that did land would read ineligible once
that day; the README names it.
zhujiu (magpie Discord #feedback, 10-25): "trae签到的积分为100而不是200 …
显示错误了". The card showed a claimed Trae CN check-in as 200 credits;
the account got 100.
Cause: auth.checkin's claimed outcome was the claim's credits +
extra_credits, falling back to the status's credits + extra_credits.
Trae CN's real claim answer names no credit at all ({"code":0,
"message":"success"}, plugins#194), so the fallback always ran, and a
real account's status carries both fields at 100 ({"checked_in": false,
"code": 0, "credits": 100, "did_checked_in": false, "enable": true,
"extra_credits": 100}, yetone/magpie#808): 100 + 100 = 200. magpie's own
Go check-in (internal/provider/trae_checkin.go, used only for plugins
before 0.2.17) fell back to the status's credits alone, and its real run
recorded credit 100 (plugins#194).
Now the credit is the claim's credits, else its extra_credits when it
names only that (#260's case), else the status's credits; the two are
never added. The done outcome already read credits alone. Trae Global
has no check-in, so this is CN only. What extra_credits means on Trae's
side is not known; nothing seen shows it granted on top.
Tests (native-checkin.test.mjs): the real status and claim answers give
credit 100; a claim naming both gives 100; a checked-in day with
extra_credits is done with 100. On origin/main's index.mjs the first two
fail (Expected credit 100, Received 200). HOME=<scratch> bun test in
packages/trae: 206 pass, 0 fail; bun scripts/check.mjs trae: ok.
Not tried with a real Trae CN account (none here); the shapes are the
real ones quoted in #808 and plugins#194. PR #333 touches the same
fallback line and needs a rebase.
Every chat function's roster is read, so each model's reasoning levels come from Trae's own config, and a model keeps its levels in magpie and in plain OpenCode (#300, sphuang1030-prog).
- A model in the fallback table keeps the levels its entry names, even though the host hands every model `variants: {}`.
- A variant's value is OpenCode's name (low/high/xhigh); effortOf takes either spelling and sends Trae's (light/high/extra_high), and nothing for a level the model doesn't name.
- The token-keyed record check that never fired is gone; the host's strict refresh reads the list again after a re-sign-in.
Reviewed at 4b968adb: bun test in packages/trae (temp HOME/TMPDIR) 203 pass / 0 fail on bun 1.4.2; bun scripts/check.mjs exit 0. The three new tests go red on the previous head 41904d9. Probes through the loader's fetch: low→light, high→high, xhigh→extra_high; medium/__proto__ send nothing; glm-5.2 fallback gives high, xhigh (was []). merge-tree against main clean; npm latest trae 0.2.19.
Not tried: a real Trae account; OpenCode's own source (whether it fills default variants first).
01huadalang (magpie's Discord, trae 0.2.18, dsh, Kimi K3 and MiMo 2.6
Pro, sometimes): tool calls came back as the reply's text. The two
screenshots show the shapes:
<function=compress><parameter=content>[{"endId": "m03680", …
<function_calls><invoke name="mcp__magpie-image__generation_result">
<parameter name="id">image-6636-24</parameter> </invoke> … </function_calls>
Root cause: TextTools only knew <tool_call> blocks (JSON, GLM's
arg_key/arg_value, name-attribute + <parameter>) and DeepSeek's DSML.
Neither shape opens with <tool_call>, so both went through as text; a
Qwen <function=…> inside <tool_call> lost the opener and leaked too.
- TextTools.xmlCall reads <function_calls> around one or more
<invoke name="…"><parameter name="k">v</parameter></invoke> (each
invoke a call; closes left off between invokes still split them), and
Qwen's <function=name><parameter=k>v</parameter></function>, bare or
in <tool_call>. Values go through paramArgs: text where the tool's
schema says string, else JSON (compress's content array is an array).
- Only for a tool the request declared (toolNamed's match); an
undeclared name, no tools at all, a tag in backticks or a code fence,
or a tag with no parameter and no close stays text. This is stricter
than <tool_call>, whose block is a call under any name: these tags
are common in prose about the formats.
- Held back while streaming (MARKS, XML_HOLD), so a tag split across
chunks never reaches the text; the closes and the wrapper are dropped
as leftovers after a call. A parameter left open when the stream ends
is cut short: the turn ends with the error plugins#38 gives, never text.
- README says so.
Sibling: qoder has its own Splitter that reads <function=…> only inside
<tool_call> and neither shape bare; not changed here, filed as
plugins#323. No other package parses text-written calls.
Run at this commit (base origin/main 1b06308), sandbox HOME/TMPDIR:
- packages/trae: bun test, 183 pass 0 fail (20 files; new
xmlcall.test.mjs, 8 tests). Fixtures are the reporter's literal bytes:
both samples whole and in pieces of 1/2/3/5/7/13/64, each split in two
at every offset, sample 1 as shown (cut) and closed, a cut inside the
second invoke, undeclared tools, prose/backticks/fence mentions, and
sample 2 through the plugin over the fake Trae streamed and not
(finish tool_calls, no text).
- bun scripts/check.mjs: 21 packages ok.
- Broken by hand, each red then restored: XML_AT never matching (6 of 8
red), the declared-tool check removed (undeclared test red), the
closes dropped from LEFTOVER (samples test red), XML_AT/XML_HOLD left
out of the stream hold (5 of 8 red).
Not tried: a real Kimi K3 or MiMo 2.6 Pro turn on Trae; dsh's compress
tool schema wasn't found locally, so the test declares content as an
array (a string schema would keep it as text, as declared).
Cause: "a stream that breaks off" errored the fake's response body with
ctl.error(new Error("connection reset")). Bun prints a response body's
error on every run, even with an error handler on the server, so every
run of the file printed "error: connection reset" at that line while the
test passed. #268 read that print as a red. It was never a failure: 40
of 40 printed it and passed under load on origin/main.
The fake now stops its server mid-body, a real broken connection: the
plugin still ends with Trae CN's error and [DONE], and nothing is printed.
Run on macOS arm64, bun 1.4.2:
- origin/main: 8 parallel `bun test --rerun-each 40 -t "breaks off"`:
every run printed the error, 0 fail.
- This change: 6 parallel `bun test --rerun-each 30
packages/trae/stream.test.mjs` at load average ~55: 6 x 420 pass,
0 fail, 0 printed.
- `HOME=$(mktemp -d) bun test` from the root: 1920 pass, 0 fail.
`bun scripts/check.mjs`: ok.
Test-only, no version bump.
Releases #257 (WuJian1421), #260 and #273 (moxuanchen), with three fixes on
top of #257's native tool turns:
- A tool result with no text went out as an empty text part. wangjianjq
measured on live Trae CN (#251) that Trae then refuses the whole request
with 4027 ("insufficient tool messages following tool_calls message"),
for either of two parallel results; " " or "0" passes. An empty result
now goes as "(no output)", or "(the result's image follows)" when its
image rides the user turn after the run. Credit wangjianjq (#251).
- A request whose body names no tools (none sent, or tool_choice "none",
such as a summary) still sends past calls and results as text, as 0.2.17
did: every live run of the native turns carried the tools in the body.
- A tool result answering no call the history sends goes back as a user
text turn ("Result of ... (call id)"), not as a tool turn naming no call.
- A Windows APPDATA spelled with other case, separators or a trailing
separator is the same root as the home's AppData\Roaming (test for #273's
fix; it fails on 0.2.17's clientStoragePaths).
Run at this commit on origin/main c7a7379: bun test in packages/trae 175
pass 0 fail; bun scripts/check.mjs trae ok. Broken by hand: with the
merged #257 index.mjs, the three new request tests and the image placeholder
test fail (4 of 28 in request+images); with 0.2.17's index.mjs the new
APPDATA case fails. Not tried against a live Trae account (none here); the
live evidence is the PR authors'.
clientStoragePaths compares its two Windows roots (APPDATA and the home's
AppData\Roaming) ignoring separator, trailing separator and case, so the same
storage.json isn't read twice; the path test compares with this system's
separator, so it passes on Windows.
Run at the reviewed head 08b52ad, merged with #257 and #260 on main 68170b3:
bun test in packages/trae 173 pass 0 fail; check.mjs trae ok. Not run on
Windows here. A case/separator test that fails on main follows on main.
A check-in claim answering extra_credits alone is credited (NaN before); an
empty reasoning_content no longer hides the event's reasoning; a native call's
name snapshot that grows takes the place of its first piece; a Global reply's
error names Trae Global.
Run at the reviewed head 2a0a835, merged with #257 and #273 on main 68170b3:
bun test in packages/trae 173 pass 0 fail; check.mjs trae ok. The new tests
fail on main's index.mjs. Not tried against a live Trae account.
Trae accepts an assistant tool_calls turn and a role:"tool" result turn on
llm_utils_chat, and answers such a history with native calls; the text-form
bridge prompt is dropped. Assistant text folds into the calls turn after it,
consecutive calls turns join one list, a nameless call is dropped with its
result, and a tool result's images ride a user turn after the run of results
(Doubao-Seed doesn't read an image_url in a tool turn). Refs #38.
Run at the reviewed head d5d755a, merged with #260 and #273 on main 68170b3:
bun test in packages/trae 173 pass 0 fail; bun scripts/check.mjs trae ok.
Not tried live here (no Trae account); the live runs are the author's (CN and
Global, multi-turn, parallel calls) and wangjianjq's on #251. Follow-up on main:
an empty result's 4027, a request without tools, and a result answering no call.
#178's README called 9095 done and 9074 failed. The code answers both as
ineligible, the same as magpie's built-in check-in, so that 9074 isn't
asked again that day. The test asserting ineligible was named "is failed".
Docs and a test name only, so no version bump. bun test
packages/trae/native-checkin.test.mjs gives 9 pass, and check.mjs trae is ok.
Trae CN's daily check-in moves into the plugin as auth.checkin. It asks
/trae/api/v2/ug/checkin_credits/status and then /claim through ownRequest,
so it carries the same JWT renewal, IDE headers, {req_source: 1} body and
16-digit ugDevice (#194) as every other ug page. Trae Global answers
inactive. 9095 on the claim is ineligible, the same as magpie's built-in
traeRefused. 9074 on the claim is an answer for the day: ineligible, with a
hint to check in in the Trae CN app. The built-in calls that own-app, which
the plugin protocol doesn't have. trae 0.2.17.
Run at the reviewed head 4e9bb87 (on top of origin/main 63a3d2a..c397e96):
- bun test packages/trae: 160 pass, 0 fail. The global.test.mjs and
stream.test.mjs failures the author saw did not reproduce.
- bun scripts/check.mjs trae: ok.
- Broken by hand, one at a time, and each turned native-checkin.test.mjs red:
9074 mapped to failed; the ugDevice line in ownRequest removed; the
unreadable-claim guard removed.
- magpie's plugin host (yetone/magpie 85eef5d87 build, sandbox HOME, a copy
of the package pointed at a fake Trae on 127.0.0.1:18764), via
`magpie accounts checkin --json`. The results were claimed 100, 9074
ineligible with the app hint, 9095 ineligible, and checked_in done 100
with no claim sent. Status and claim both went out with
x-device-id 2866487253502651 and {"req_source":1}.
XcodeFish's A/B on one account (#194): with the same Cloud-IDE-JWT,
headers and body, Trae CN answered a claim 9074 on the plugin's
19-digit x-device-id and took it (code 0, +100) on a 16-digit one.
The IDE's own id is server-issued: Trae's main process registers at
log.snssdk.com/service/2/desktop/device_register (read in Trae.app's
out/main.js, iCubeDeviceRegisterMainService). Real clients keep it as
iCubeAuthInfo://icube-dc:<id>, and the ids seen in #808 and #1705 are
15 or 16 digits.
- A new Trae CN sign-in names a 16-digit device_id. Trae Global keeps
19 digits, since nothing says its ids are shaped otherwise.
- ugDevice: a check-in from an account the local client isn't signed
in as goes on the account's own id when that is 15 or 16 digits.
Otherwise (19 digits, signed in before 0.2.16) it goes on a 16-digit
id hashed from that account's device id and uid. The id is the same
on every check-in, never rotated and never another account's. A 9095
is still the day's answer. Chat pages and the renewal keep the
device the account signed in with.
- README: the Sign-in and Daily check-in sections say this.
Run:
- bun test packages/trae: 151 pass, 0 fail. Breaking it by hand: with
the ugDevice line removed, 7 tests fail; with newDevice back to
digits(19), 4 fail.
- bun scripts/check.mjs: ok.
- magpie's plugin host (origin/main 7660399a1, sandbox HOME), with the
plugin's web/auth hosts pointed at a local fake:
- signed in on 0.2.15 (device 9375744633732288271), claim on 19 digits;
- added 0.2.16 over it: status/claim/claim all went on 2849759837088686,
and the pay page kept 9375744633732288271;
- a new 0.2.16 sign-in named 2348824360597085 (16 digits) and used it
for check-in and chat.
- Not tried against the real api.trae.cn; there are no real accounts
here. The 16-digit claim being taken is the reporter's measurement.
Reported on magpie's Discord (#help): through magpie, Trae CN's doubao
model said it couldn't read images, while in Trae it reads them.
Every model was listed as text-only (MODEL's modalities), and partText
put "[an image, which this model can't see]" in every image's place, so
no image ever reached Trae.
What changed:
- Trae's lists mark each entry `multimodal` true or false
(config_info_list). A listed model's flag now decides
capabilities.input.image, attachment and modalities, over a fallback
entry's word. Doubao-Seed, Kimi K3/K2.6, Qwen 3.7 Plus and MiniMax M3
are true; GLM-5.x and DeepSeek V4 are false.
- An image sent to a model that takes images goes to llm_utils_chat as
an OpenAI image_url part ({url}) after the text part. That is the
shape TRAE's ai-agent carries (LLMRawMultiContent/LLMRawChatImageURL,
in the ai-agent binary's strings) and what autumnsentiment/Trae2api-cn
passes llm_utils_chat unchanged.
- A model marked false still gets the placeholder.
- The fallback list marks kimi-k2.6 and qwen-3.7-plus as taking images,
as Trae's SOLO list does.
The list fixture is two entries of a relay's capture of the SOLO list
(wangqi233/trae2api scripts/_solo-models-clean.json).
Run:
- images.test.mjs: 6 pass on this change; 5 of 6 fail on 0.2.14's
index.mjs (only the text-only case passes there).
- packages/trae: 146 tests, 0 fail.
- HOME=$(mktemp -d) bun test across the repo: 1616 pass, 0 fail.
- bun scripts/check.mjs: ok.
Not tried: a real Trae account. Magpie's owner has none signed in, so no
real image request was sent to Trae.
checkIn() opened a fake over the one the test had already opened; closing
the second put the first's 127.0.0.1 origin back as trae-cn's hosts, so
global.test.mjs, run after it in one process, read a fake host. The
publish run for 2009f49 went red on it and 0.2.14 never reached npm.
checkIn now closes the fake before it opens another.
Ran: HOME=$(mktemp -d) bun test at the repo root: 1509 pass, 0 fail.
Broken by hand: without the close, `bun test ./ownclient.test.mjs
./global.test.mjs` fails "the realm's table is its own" (26 pass, 1 fail),
as the publish run did.
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.
The test's fake server sent one event, waited 30 ms and errored the body.
The plugin reads its first part before it answers. Under the whole repo's
`bun test` that read sometimes started after the reset, and Bun then drops
the event it had already received. The read threw ECONNRESET out of the
plugin's fetch instead of reaching the mid-stream path the test covers
(1259 pass, 1 fail at a6bed5e). The reset now waits until the caller has
read "half", so the plugin has always read it first. Only the test
changed. index.mjs is untouched, so there's no version bump.
Run at a6bed5e + this change, TMPDIR and HOME set to a scratch dir:
- before the change, repo-root `bun test`: 1259 pass, 1 fail (this test).
A 200 ms pause put by hand before the plugin's first read failed it
every time when run alone.
- after: repo-root `bun test` 1259 pass, 0 fail, 1 skip (exit 0);
packages/trae `bun test` 129 pass; stream.test.mjs alone 3/3;
`bun scripts/check.mjs` exit 0.
- with the same 200 ms pause in place: passes.
- broke it by hand: index.mjs ending a broken stream with finish "stop"
and no error turns this test red.
- grep found no other test that resets a body on a timer.
Not tried: CI's Linux runner. CI's publish runs had passed this test so
far (e.g. 38572309548). Their red was the zed and zen-free Trusted
Publisher 404s.
#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.
trae-cn/glm-5.3 under DSH (2026-10-13): over three turns, 28 of 54 native calls
arrived with the model's call in `function.name` instead of `function.arguments`
— the JSON wrapper the tool prompt asks for, with GLM's own
<arg_key>/<arg_value> tags where Trae's service stopped reading it, and a value
whose close left off:
{"name":"bash","arguments":{"command</arg_key><arg_value>ls -la</arg_value>
{"name":"bash","arguments":{"command":"grep -n x a.ts | head -3</arg_value>
{"name":"bash","arguments":{"command":"grep -n "x" a.ts","description":"…"}}
bash_abstract_command_0>{"name":"bash","arguments":{"command":"…scan.mjs</description>Re-run scan</arg_value>
Each went out under a name no request declares, so the agent answered "unknown
tool" and the call was lost — twelve steps in a row before the model recovered.
All 28 sit in the context the session compacted at the end of turn 8: turn 9's
input went from ~5k to 94.5k tokens. Whether the compaction is what makes the
service hand a call back this way is not established — only that the two line
up, and that the session's earlier turns on workbuddy-ai/hy4-preview-f and
group/auto-hy4-preview-f sent 270 whole calls and none of this shape. No
workbuddy/glm-5.3 call was routed that day, so nothing is claimed about it.
- A name holding the wrapper is read as the call: the tool, then the fields the
text between the tags still spells out. The tags are the service's own
handoff, so what stands between them is the model's text as the model wrote
it: a quote left unescaped is read as the quote it is, a value the service
cut at its tag keeps the text it got, a comma inside a value is the model's
own (`sed -n 1,9p` reads whole), and a closing tag that is a field's own
(`</description>`) ends the value before it — what follows such a tag is the
service's text, not the model's.
- A field the tool's schema says is no string is its JSON where the text is
one, and its text where it isn't.
- The native call's own arguments are kept, and the name's fields are filled in
beside them: the service moves the arguments it read into the call and leaves
the rest in the name, so the two halves are one call (command in the name,
description/workdir in the call).
- A name whose tool the request doesn't have, or one no field can be read from,
goes on as written, as any other unknown tool does — including one the
service cut before it wrote a value (at a key, at a colon, at an open quote),
where an empty call read out of it would be a call the model never wrote.
Calls already written into a session's history under a mangled name still go
back on as that name; the plugin reads what it is handed and cannot rewrite
what was already sent.
- What main already read of a whole name keeps reading the same (`input`,
`parameters`, arguments given as a string, the flat fields, a wrapper written
with a space), and a call's own arguments that are not a set of fields — text
the service cut, a value that isn't a call's fields — go on as they stand, as
main passed them, for the agent to answer.
The wrapper and the tags are upstream's; the plugin reads what it was handed.
The same shapes are already handled by the DSH-ecosystem relays (trae2api's
_ARG_KEY_VALUE_RE takes a key whose opening <arg_key> was dropped) and by
@ai-sdk-tool/parser's GLM-5 name resolution (a declared name followed by a
structural tag is that tool), which is where the fail-closed reading of an
unknown name comes from.
Run: namecall.test.mjs (16 tests; the real payloads, a name in front of the
wrapper, a field's closing tag cut into a value, a comma inside a value, the
whole-name shapes main reads, the shapes the reader must leave alone, and the
streamed path) — 11 of 16 fail on main's index.mjs, the five that pass being
the ones that pin what main reads.
HOME=<tmp> bun test, 125 pass 0 fail; bun scripts/check.mjs trae green. The 28
payloads this was drawn from were replayed through NativeCalls.take: 28
recovered into calls to tools the request declares, and the 270 calls that
arrived whole in the same session unchanged, byte for byte. Against the same
names and calls main can take (187 pairs) the only differences are the fields
the name's side fills in beside the call's own, and the names main could not
read at all.
Co-authored-by: yu <wowyuarm@users.noreply.github.com>
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.