fix: write codex terminal completion in final outbox (#236)
This commit is contained in:
@@ -449,6 +449,12 @@ async function runCodexStdioTurnWithSession(options: CodexStdioTurnOptions, sess
|
|||||||
const emitEvents = (nextEvents: BackendEvent[]): void => {
|
const emitEvents = (nextEvents: BackendEvent[]): void => {
|
||||||
for (const event of nextEvents) emitEvent(event);
|
for (const event of nextEvents) emitEvent(event);
|
||||||
};
|
};
|
||||||
|
const appendResultEvent = (event: BackendEvent): void => {
|
||||||
|
events.push({ ...event, payload: redactJson(event.payload) });
|
||||||
|
};
|
||||||
|
const appendResultEvents = (nextEvents: BackendEvent[]): void => {
|
||||||
|
for (const event of nextEvents) appendResultEvent(event);
|
||||||
|
};
|
||||||
if (options.abortSignal?.aborted) {
|
if (options.abortSignal?.aborted) {
|
||||||
const cancelled = { status: "cancelled" as const, failureKind: "cancelled" as const, message: "cancel requested" };
|
const cancelled = { status: "cancelled" as const, failureKind: "cancelled" as const, message: "cancel requested" };
|
||||||
events.push({ type: "backend_status", payload: { phase: "turn-cancelled", failureKind: "cancelled" } });
|
events.push({ type: "backend_status", payload: { phase: "turn-cancelled", failureKind: "cancelled" } });
|
||||||
@@ -822,14 +828,14 @@ async function runCodexStdioTurnWithSession(options: CodexStdioTurnOptions, sess
|
|||||||
if (!terminal) terminal = { status: "failed", failureKind: "backend-response-invalid", message: "codex app-server finished without terminal status" };
|
if (!terminal) terminal = { status: "failed", failureKind: "backend-response-invalid", message: "codex app-server finished without terminal status" };
|
||||||
const pendingInterrupt: Promise<void> | null = interruptInFlight as Promise<void> | null;
|
const pendingInterrupt: Promise<void> | null = interruptInFlight as Promise<void> | null;
|
||||||
if (pendingInterrupt) await pendingInterrupt.catch(() => undefined);
|
if (pendingInterrupt) await pendingInterrupt.catch(() => undefined);
|
||||||
if (terminal.status !== "completed") emitEvents(await session.close());
|
if (terminal.status !== "completed") appendResultEvents(await session.close());
|
||||||
emitEvents(flushAssistantDeltaProgress(assistantDeltaProgress));
|
appendResultEvents(flushAssistantDeltaProgress(assistantDeltaProgress));
|
||||||
const finalAssistant = terminal.status === "completed" ? finalAssistantMessageForTurn(completedAssistantMessages, assistantText) : null;
|
const finalAssistant = terminal.status === "completed" ? finalAssistantMessageForTurn(completedAssistantMessages, assistantText) : null;
|
||||||
if (finalAssistant) emitEvent(assistantFinalResponseEvent(finalAssistant));
|
if (finalAssistant) appendResultEvent(assistantFinalResponseEvent(finalAssistant));
|
||||||
else if (completedAssistantMessages.length === 0) emitEvents(assistantMessageEventsForTurn(assistantText, false));
|
else if (completedAssistantMessages.length === 0) appendResultEvents(assistantMessageEventsForTurn(assistantText, false));
|
||||||
emitEvents(suppressedNotificationEvents(suppressedNotifications));
|
appendResultEvents(suppressedNotificationEvents(suppressedNotifications));
|
||||||
emitEvents(deferredTerminalEvents);
|
appendResultEvents(deferredTerminalEvents);
|
||||||
emitEvent({ type: "terminal_status", payload: { terminalStatus: terminal.status, failureKind: terminal.failureKind, message: terminal.message } });
|
appendResultEvent({ type: "terminal_status", payload: { terminalStatus: terminal.status, failureKind: terminal.failureKind, message: terminal.message } });
|
||||||
await liveEventWrite;
|
await liveEventWrite;
|
||||||
return { terminalStatus: terminal.status, failureKind: terminal.failureKind, failureMessage: terminal.message, events: events.map((event) => ({ ...event, payload: redactJson(event.payload) })), ...(threadId ? { threadId } : {}), ...(turnId ? { turnId } : {}) };
|
return { terminalStatus: terminal.status, failureKind: terminal.failureKind, failureMessage: terminal.message, events: events.map((event) => ({ ...event, payload: redactJson(event.payload) })), ...(threadId ? { threadId } : {}), ...(turnId ? { turnId } : {}) };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user