Skip to content

Commit 86d2045

Browse files
committed
fix(codex): retain image inputs when cancelling generation
1 parent 7ba6f83 commit 86d2045

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4217,6 +4217,8 @@ describe("CodexAdapterV2 post-settle continuation", () => {
42174217
item: {
42184218
type: "imageGeneration",
42194219
id: image,
4220+
revisedPrompt: "A friendly green tree",
4221+
transparentBackground: true,
42204222
status: phase === "started" ? "inProgress" : "completed",
42214223
result: "",
42224224
...(phase === "completed" ? { savedPath: `/tmp/${image}.png` } : {}),
@@ -4306,6 +4308,11 @@ describe("CodexAdapterV2 post-settle continuation", () => {
43064308
outcome === "complete" ? "completed" : "cancelled",
43074309
);
43084310
assert.strictEqual(updates[1]?.ordinal, updates[0]?.ordinal);
4311+
assert.deepEqual(updates[1]?.input, updates[0]?.input);
4312+
assert.deepEqual(updates[1]?.input, {
4313+
prompt: "A friendly green tree",
4314+
transparent_background: true,
4315+
});
43094316
}
43104317
// Run ingestion follows these updates, so they must bracket the terminal and the images.
43114318
const indexOf = (predicate: (event: ProviderAdapter.ProviderAdapterV2Event) => boolean) =>

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,13 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
19811981
const imageTurns = new Map<
19821982
string,
19831983
{
1984-
readonly running: Set<string>;
1984+
readonly running: Map<
1985+
string,
1986+
{
1987+
readonly revisedPrompt: string | null;
1988+
readonly transparentBackground: boolean | null;
1989+
}
1990+
>;
19851991
readonly saved: Map<string, string>;
19861992
pending: boolean;
19871993
answer?: { readonly id: string; readonly text: string };
@@ -1990,7 +1996,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
19901996
const imageTurn = (nativeTurnId: string) => {
19911997
let state = imageTurns.get(nativeTurnId);
19921998
if (state === undefined) {
1993-
state = { running: new Set(), saved: new Map(), pending: false };
1999+
state = { running: new Map(), saved: new Map(), pending: false };
19942000
imageTurns.set(nativeTurnId, state);
19952001
}
19962002
return state;
@@ -2075,12 +2081,13 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
20752081
const clearImageWork = Effect.fn("CodexAdapterV2.clearImageWork")(function* (
20762082
context: ActiveCodexTurnContext,
20772083
) {
2078-
for (const id of imageTurns.get(context.nativeTurnId)?.running ?? []) {
2084+
for (const [id, input] of imageTurns.get(context.nativeTurnId)?.running ?? []) {
20792085
yield* emitImageGenerationItem(
20802086
context,
20812087
{
20822088
type: "imageGeneration",
20832089
id,
2090+
...input,
20842091
status: "cancelled",
20852092
result: "",
20862093
},
@@ -5042,7 +5049,10 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
50425049

50435050
if (payload.item.type === "imageGeneration") {
50445051
if (!(yield* Ref.get(interruptingNativeTurns)).has(payload.turnId)) {
5045-
imageTurn(payload.turnId).running.add(payload.item.id);
5052+
imageTurn(payload.turnId).running.set(payload.item.id, {
5053+
revisedPrompt: payload.item.revisedPrompt ?? null,
5054+
transparentBackground: payload.item.transparentBackground ?? null,
5055+
});
50465056
yield* emitImageGenerationItem(context, payload.item, false);
50475057
yield* emitImageWorkState(context, true);
50485058
}

0 commit comments

Comments
 (0)