fix(codex): reject unscoped bound turn events

This commit is contained in:
Lucenx9
2026-04-25 02:48:39 +02:00
committed by Peter Steinberger
parent f7caf83da4
commit cc87c9b120
2 changed files with 52 additions and 1 deletions

View File

@@ -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");

View File

@@ -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<string, unknown> | undefined {