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.