diff --git a/extensions/codex/src/conversation-turn-collector.test.ts b/extensions/codex/src/conversation-turn-collector.test.ts index 1f2806ab4e8..49b61f652ab 100644 --- a/extensions/codex/src/conversation-turn-collector.test.ts +++ b/extensions/codex/src/conversation-turn-collector.test.ts @@ -72,6 +72,57 @@ describe("codex conversation turn collector", () => { await expect(completion).resolves.toEqual({ replyText: "right" }); }); + it("ignores unscoped deltas once the active turn is known", async () => { + const collector = createCodexConversationTurnCollector("thread-1"); + collector.setTurnId("turn-1"); + const completion = collector.wait({ timeoutMs: 1_000 }); + + collector.handleNotification({ + method: "item/agentMessage/delta", + params: { threadId: "thread-1", itemId: "wrong", delta: "wrong" }, + }); + collector.handleNotification({ + method: "item/agentMessage/delta", + params: { threadId: "thread-1", turnId: "turn-1", itemId: "right", delta: "right" }, + }); + collector.handleNotification({ + method: "turn/completed", + params: { threadId: "thread-1", turn: { id: "turn-1", status: "completed", items: [] } }, + }); + + await expect(completion).resolves.toEqual({ replyText: "right" }); + }); + + it("does not complete from unscoped turn completion once the active turn is known", async () => { + const collector = createCodexConversationTurnCollector("thread-1"); + collector.setTurnId("turn-1"); + const completion = collector.wait({ timeoutMs: 1_000 }); + + collector.handleNotification({ + method: "turn/completed", + params: { + threadId: "thread-1", + turn: { + status: "completed", + items: [{ type: "agentMessage", id: "wrong", text: "wrong" }], + }, + }, + }); + collector.handleNotification({ + method: "turn/completed", + params: { + threadId: "thread-1", + turn: { + id: "turn-1", + status: "completed", + items: [{ type: "agentMessage", id: "right", text: "right" }], + }, + }, + }); + + await expect(completion).resolves.toEqual({ replyText: "right" }); + }); + it("rejects failed turns with the app-server error message", async () => { const collector = createCodexConversationTurnCollector("thread-1"); collector.setTurnId("turn-1"); diff --git a/extensions/codex/src/conversation-turn-collector.ts b/extensions/codex/src/conversation-turn-collector.ts index 5e76ef95aa1..d582007936b 100644 --- a/extensions/codex/src/conversation-turn-collector.ts +++ b/extensions/codex/src/conversation-turn-collector.ts @@ -142,7 +142,7 @@ function isNotificationForTurn( return directTurnId === turnId; } const turn = isJsonObject(params.turn) ? params.turn : undefined; - return !turn || readString(turn, "id") === turnId; + return readString(turn, "id") === turnId; } function readRecord(value: unknown): Record | undefined {