Skip to content

Commit 5e057f4

Browse files
steipeteobviyus
authored andcommitted
fix(codex): ignore commentary raw assistant completions
1 parent 9c96e93 commit 5e057f4

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

extensions/codex/src/app-server/event-projector.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,15 @@ export class CodexAppServerEventProjector {
709709
return;
710710
}
711711
const itemId = readString(item, "id") ?? `raw-assistant-${this.assistantItemOrder.length + 1}`;
712+
const phase = readString(item, "phase");
713+
if (phase) {
714+
this.assistantPhaseByItem.set(itemId, phase);
715+
}
712716
this.rememberAssistantItem(itemId);
713717
this.assistantTextByItem.set(itemId, text);
718+
if (phase === "commentary") {
719+
this.emitCommentaryProgress({ itemId, text });
720+
}
714721
}
715722

716723
private recordNativeGeneratedMedia(item: CodexThreadItem | undefined): void {

extensions/codex/src/app-server/run-attempt.test.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,6 +2613,82 @@ describe("runCodexAppServerAttempt", () => {
26132613
});
26142614
});
26152615

2616+
it("does not release or return commentary raw assistant response items", async () => {
2617+
let notify: (notification: CodexServerNotification) => Promise<void> = async () => undefined;
2618+
const request = vi.fn(async (method: string) => {
2619+
if (method === "thread/start") {
2620+
return threadStartResult("thread-1");
2621+
}
2622+
if (method === "turn/start") {
2623+
return turnStartResult("turn-1", "inProgress");
2624+
}
2625+
return {};
2626+
});
2627+
setCodexAppServerClientFactoryForTest(
2628+
async () =>
2629+
({
2630+
request,
2631+
addNotificationHandler: (handler: typeof notify) => {
2632+
notify = handler;
2633+
return () => undefined;
2634+
},
2635+
addRequestHandler: () => () => undefined,
2636+
}) as never,
2637+
);
2638+
const params = createParams(
2639+
path.join(tempDir, "session.jsonl"),
2640+
path.join(tempDir, "workspace"),
2641+
);
2642+
params.timeoutMs = 200;
2643+
2644+
const run = runCodexAppServerAttempt(params, {
2645+
turnAssistantCompletionIdleTimeoutMs: 5,
2646+
});
2647+
await vi.waitFor(
2648+
() =>
2649+
expect(request).toHaveBeenCalledWith("turn/start", expect.anything(), expect.anything()),
2650+
{ interval: 1 },
2651+
);
2652+
await notify({
2653+
method: "rawResponseItem/completed",
2654+
params: {
2655+
threadId: "thread-1",
2656+
turnId: "turn-1",
2657+
item: {
2658+
type: "message",
2659+
id: "raw-commentary-1",
2660+
role: "assistant",
2661+
phase: "commentary",
2662+
content: [{ type: "output_text", text: "I am checking the workspace." }],
2663+
},
2664+
},
2665+
});
2666+
await new Promise((resolve) => setTimeout(resolve, 20));
2667+
2668+
expect(request).not.toHaveBeenCalledWith("turn/interrupt", expect.anything());
2669+
await notify({
2670+
method: "turn/completed",
2671+
params: {
2672+
threadId: "thread-1",
2673+
turnId: "turn-1",
2674+
turn: { id: "turn-1", status: "completed" },
2675+
},
2676+
});
2677+
2678+
const result = await run;
2679+
expect({
2680+
aborted: result.aborted,
2681+
timedOut: result.timedOut,
2682+
promptError: result.promptError,
2683+
assistantTexts: result.assistantTexts,
2684+
}).toEqual({
2685+
aborted: false,
2686+
timedOut: false,
2687+
promptError: null,
2688+
assistantTexts: [],
2689+
});
2690+
});
2691+
26162692
it("releases the session after a raw assistant response item without turn completion", async () => {
26172693
let notify: (notification: CodexServerNotification) => Promise<void> = async () => undefined;
26182694
const request = vi.fn(async (method: string) => {

extensions/codex/src/app-server/run-attempt.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,6 +2852,7 @@ function isRawAssistantCompletionNotification(notification: CodexServerNotificat
28522852
item &&
28532853
readString(item, "type") === "message" &&
28542854
readString(item, "role") === "assistant" &&
2855+
readString(item, "phase") !== "commentary" &&
28552856
readRawAssistantTextPreview(item),
28562857
);
28572858
}

0 commit comments

Comments
 (0)