Skip to content

Commit b690287

Browse files
fix(server): a thread title with an unpaired surrogate no longer stops linked calls
encodeURIComponent throws on an unpaired UTF-16 surrogate, and a thread title can hold one, so encoding the sender header turned every forwarded call from that thread into a defect before any request went out. Make each part well-formed before encoding it. AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c19021b commit b690287

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎apps/server/src/peer/PeerMcpClient.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ it.effect("tells the peer which thread a call is made for", () =>
9595
// A long title is cut to whole characters rather than breaking the call.
9696
const long = yield* call({ sender: { ...sender, title: "🧵".repeat(5000) } });
9797
expect(long.senderThread?.title).toBe("🧵".repeat(200));
98+
// A title holding an unpaired surrogate still lets the call through.
99+
const broken = yield* call({ sender: { ...sender, title: "Review \ud800" } });
100+
expect(broken.senderThread?.title).toBe("Review \ufffd");
98101
}),
99102
).pipe(Effect.provide(NodeHttpServer.layerTest)),
100103
);

‎apps/server/src/peer/PeerMcpClient.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ const make = Effect.gen(function* () {
177177
// Whole code points, so a cut never leaves half an emoji for encodeURIComponent.
178178
Array.from(input.sender.title).slice(0, SENDER_TITLE_MAX_LENGTH).join(""),
179179
]
180-
.map(encodeURIComponent)
180+
// encodeURIComponent throws on an unpaired surrogate, which a title can hold.
181+
.map((part) => encodeURIComponent(part.toWellFormed()))
181182
.join("/"),
182183
};
183184
const sessionKey = `${input.environmentId} ${resolved.url}`;

0 commit comments

Comments
 (0)