@devries-cameron20 / t3code Mirror · read-only / commits / e01ca01ade
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 03:15 UTC

fix(fx): preserve literal unicode escape text in clipped replies (#30701)

Johan Vaz committed Nov 6, 2026 at 12:37 UTC e01ca01ade8128b98283b58c902638ffb9fb102b
2 files changed +49 -2
packages/provider-fx/src/server/adapter.test.ts new
+44
@@ -0,0 +1,44 @@
1 +import { describe, expect, it } from "@effect/vitest";
2 +
3 +import { fxSubagentOutcome } from "./adapter.ts";
4 +
5 +describe("fx subagent replies", () => {
6 + it.each(["", "1", "12", "123"])("preserves literal Unicode spelling ending in u%s", (digits) => {
7 + for (const slashes of [1, 2]) {
8 + const suffix = "\\".repeat(slashes) + "u" + digits;
9 + const padding = "x".repeat(
10 + 200 - '{"ok":true,"result":"'.length - JSON.stringify(suffix).length + 2,
11 + );
12 + const reply = padding + suffix + "4 more text";
13 + const whole = JSON.stringify({ ok: true, result: reply });
14 + expect(fxSubagentOutcome(whole)).toEqual({ ok: true, result: reply });
15 + expect(fxSubagentOutcome(Buffer.from(whole).subarray(0, 200).toString("utf8"))).toEqual({
16 + ok: true,
17 + result: padding + suffix + "…",
18 + });
19 + }
20 + });
21 +
22 + it.each([0, 1, 2])(
23 + "recovers incomplete Unicode escapes after %i literal backslashes",
24 + (slashes) => {
25 + for (const digits of ["", "0", "00", "000"]) {
26 + const prefix = "reply" + "\\".repeat(slashes * 2);
27 + expect(fxSubagentOutcome('{"ok":true,"result":"' + prefix + "\\u" + digits)).toEqual({
28 + ok: true,
29 + result: "reply" + "\\".repeat(slashes) + "…",
30 + });
31 + }
32 + },
33 + );
34 +
35 + it.each([
36 + ['{"ok":true,"result":"hello', { ok: true, result: "hello…" }],
37 + ['{"ok":false,"result":null}', { ok: false, result: null }],
38 + ['{"ok":true,"result":"hello"', { ok: true, result: "hello" }],
39 + ['{"unexpected":"body"}', undefined],
40 + ['{"ok":true,"result":"\\q', { ok: true, result: null }],
41 + ])("retains existing normalization for %s", (text, expected) => {
42 + expect(fxSubagentOutcome(text)).toEqual(expected);
43 + });
44 +});
packages/provider-fx/src/server/adapter.ts
+5 -2
@@ -102,14 +102,17 @@ const decodeJsonString = Schema.decodeUnknownOption(Schema.fromJsonString(Schema
102 * fx clips every tool result to 199 bytes, so a long sub-agent reply arrives
103 * as cut-off `{"ok":…,"result":"…` JSON. Keeps the readable prefix and marks the cut.
104 */
105 -function fxSubagentOutcome(
105 +export function fxSubagentOutcome(
106 text: string,
107 ): { readonly ok: boolean; readonly result: string | null } | undefined {
108 const whole = decodeFxSubagentResult(text);
109 if (Option.isSome(whole)) return whole.value;
110 const clipped = /^\{"ok":(true|false),"result":"((?:[^"\\]|\\.)*)/.exec(text);
111 if (clipped === null) return undefined;
112 - const prefix = decodeJsonString(`"${(clipped[2] ?? "").replace(/\\u[0-9a-fA-F]{0,3}$/, "")}"`);
112 + const fragment = clipped[2] ?? "";
113 + const prefix = decodeJsonString(`"${fragment}"`).pipe(
114 + Option.orElse(() => decodeJsonString(`"${fragment.replace(/\\u[0-9a-fA-F]{0,3}$/, "")}"`)),
115 + );
116 const cut = text[clipped[0].length] !== '"';
117 return {
118 ok: clipped[1] === "true",