@devries-cameron20 / t3code Mirror · read-only / commits / 30b9c4a956
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, 07:00 UTC

fix(codex): a background command's wake no longer hangs when its output tail splits an emoji (#29168)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>

Alex Southwell committed Nov 3, 2026 at 01:43 UTC 30b9c4a956a6c595fda5c8b2c439a6aaebc861b0
2 files changed +61 -5
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+52
@@ -4064,6 +4064,58 @@ describe("CodexAdapterV2 post-settle continuation", () => {
4064 ],
4065 });
4066
4067 + it.effect("wakes with well-formed text when the cuts split an emoji", () =>
4068 + Effect.scoped(
4069 + Effect.gen(function* () {
4070 + const harness = yield* makeCodexReplayHarness(
4071 + makeCodexReplayTranscript({
4072 + scenario: "codex-bg-wake-surrogate",
4073 + entries: [
4074 + ...backgroundExecTranscript.entries.slice(0, -1),
4075 + {
4076 + type: "emit_inbound",
4077 + label: "item/completed/command-late",
4078 + frame: {
4079 + method: "item/completed",
4080 + params: {
4081 + item: {
4082 + ...backgroundCommandItem("completed"),
4083 + command: `${"c".repeat(199)}🚀`,
4084 + aggregatedOutput: `🚀${"x".repeat(999)}\n`,
4085 + },
4086 + threadId: BG_NATIVE_THREAD,
4087 + turnId: BG_NATIVE_TURN,
4088 + completedAtMs: 1782622465500,
4089 + },
4090 + },
4091 + },
4092 + ],
4093 + }),
4094 + );
4095 + yield* harness.runtime.startTurn(
4096 + makeCodexTestTurnInput({
4097 + threadId: harness.threadId,
4098 + providerThread: harness.providerThread,
4099 + now: yield* DateTime.now,
4100 + attemptId: RunAttemptId.make("attempt-codex-bg-wake-surrogate"),
4101 + text: BG_PROMPT,
4102 + }),
4103 + );
4104 + yield* harness.until(() => harness.continuationRequests.length > 0);
4105 + assert.isTrue(harness.continuationRequests[0]?.detail?.isWellFormed());
4106 + }).pipe(
4107 + Effect.provide(
4108 + Layer.mergeAll(
4109 + IdAllocator.layer,
4110 + McpProviderSessions.layer,
4111 + NodeServices.layer,
4112 + NodeCrypto.layer,
4113 + ),
4114 + ),
4115 + ),
4116 + ),
4117 + );
4118 +
4119 it.effect.each([false, true])(
4120 "keeps commands interrupted after native thread closure (persistent tool: %s)",
4121 (retainContext) =>
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+9 -5
@@ -430,17 +430,21 @@ function codexBackgroundCommandDetail(item: {
430 readonly exitCode?: number | null | undefined;
431 readonly aggregatedOutput?: string | null | undefined;
432 }): string {
433 + // Codex rejects a turn/start with a lone surrogate and never answers it, so cut on code points.
434 + let commandEnd = BACKGROUND_COMMAND_DETAIL_COMMAND_MAX_LENGTH;
435 + const finalCommandUnit = item.command.charCodeAt(commandEnd - 1);
436 + if (finalCommandUnit >= 0xd800 && finalCommandUnit <= 0xdbff) commandEnd -= 1;
437 const command =
438 item.command.length > BACKGROUND_COMMAND_DETAIL_COMMAND_MAX_LENGTH
435 - ? `${item.command.slice(0, BACKGROUND_COMMAND_DETAIL_COMMAND_MAX_LENGTH)}...`
439 + ? `${item.command.slice(0, commandEnd)}...`
440 : item.command;
441 const exit =
442 item.exitCode === null || item.exitCode === undefined ? "" : ` (exit ${item.exitCode})`;
443 const output = (item.aggregatedOutput ?? "").trimEnd();
440 - const outputTail =
441 - output.length > BACKGROUND_COMMAND_DETAIL_OUTPUT_TAIL_MAX_LENGTH
442 - ? `...${output.slice(-BACKGROUND_COMMAND_DETAIL_OUTPUT_TAIL_MAX_LENGTH)}`
443 - : output;
444 + let outputStart = output.length - BACKGROUND_COMMAND_DETAIL_OUTPUT_TAIL_MAX_LENGTH;
445 + const firstOutputUnit = output.charCodeAt(outputStart);
446 + if (firstOutputUnit >= 0xdc00 && firstOutputUnit <= 0xdfff) outputStart += 1;
447 + const outputTail = outputStart > 0 ? `...${output.slice(outputStart)}` : output;
448 const header = `Background command completed${exit}: ${command}`;
449 return outputTail.length === 0 ? header : `${header}\n\nOutput tail:\n${outputTail}`;
450 }