Commit Graph
2 Commits
Author SHA1 Message Date
yetone 0e2a52efdc trae 0.2.9: <toolcall> without the underscore is read as <tool_call>, and a reply that ends inside an opener is cut short, not the answer (#38)
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.
2026-10-13 04:40:26 +08:00
yetone e2c01edc83 trae 0.2.5: a tool call written into the text that can't be read ends the turn as an error, never as the answer (#38) (#46)
#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.
2026-10-08 11:23:03 +08:00