Skip to content

Commit fad0794

Browse files
fix(server): keep Codex response turns that a user event cannot replace
A user event with no text, such as an inline image alone, hid every response copy in its turn, so an image-only conversation imported nothing. Such events no longer stand in for their copies. An interrupted turn ends without an assistant message, so its prompt merged into the next event-backed turn and was hidden; turn_aborted and task_complete now end a turn too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 111bfe8 commit fad0794

2 files changed

Lines changed: 96 additions & 46 deletions

File tree

‎apps/server/src/project/AgentSessionScanner.test.ts‎

Lines changed: 81 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,52 +1856,75 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
18561856
}),
18571857
);
18581858

1859-
it.effect("imports a Codex prompt whose inline image exceeds the history budget", () =>
1860-
Effect.gen(function* () {
1861-
const path = yield* Path.Path;
1862-
const nowMs = Date.parse("2026-08-24T12:00:00.000Z");
1863-
yield* TestClock.setTime(nowMs);
1864-
const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
1865-
const codexHomePath = yield* makeTempDir("t3code-codex-home-");
1866-
const workspace = yield* makeTempDir("t3code-workspace-");
1867-
yield* writeTranscript({
1868-
filePath: path.join(codexHomePath, "sessions", "2026", "08", "24", "rollout-image.jsonl"),
1869-
contents: [
1870-
encodeTranscriptRecord({
1871-
type: "session_meta",
1872-
payload: { id: "image-session", cwd: workspace },
1873-
}),
1874-
encodeTranscriptRecord({
1875-
type: "event_msg",
1876-
payload: {
1877-
type: "user_message",
1878-
message: "Describe this screenshot",
1879-
images: [`data:image/png;base64,${"A".repeat(17 * 1024 * 1024)}`],
1880-
},
1881-
}),
1882-
encodeTranscriptRecord({
1883-
type: "response_item",
1884-
payload: {
1885-
type: "message",
1886-
role: "assistant",
1887-
content: [{ type: "output_text", text: "A login form." }],
1888-
},
1889-
}),
1890-
].join("\n"),
1891-
mtimeMs: nowMs,
1892-
});
1859+
it.effect(
1860+
"imports an image-only Codex prompt whose inline image exceeds the history budget",
1861+
() =>
1862+
Effect.gen(function* () {
1863+
const path = yield* Path.Path;
1864+
const nowMs = Date.parse("2026-08-24T12:00:00.000Z");
1865+
yield* TestClock.setTime(nowMs);
1866+
const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
1867+
const codexHomePath = yield* makeTempDir("t3code-codex-home-");
1868+
const workspace = yield* makeTempDir("t3code-workspace-");
1869+
const context = "<environment_context>\n<cwd>/tmp/project</cwd>\n</environment_context>";
1870+
const image = `data:image/png;base64,${"A".repeat(17 * 1024 * 1024)}`;
1871+
yield* writeTranscript({
1872+
filePath: path.join(
1873+
codexHomePath,
1874+
"sessions",
1875+
"2026",
1876+
"08",
1877+
"24",
1878+
"rollout-image.jsonl",
1879+
),
1880+
contents: [
1881+
encodeTranscriptRecord({
1882+
type: "session_meta",
1883+
payload: { id: "image-session", cwd: workspace },
1884+
}),
1885+
encodeTranscriptRecord({
1886+
type: "response_item",
1887+
payload: {
1888+
type: "message",
1889+
role: "user",
1890+
content: [{ type: "input_text", text: context }],
1891+
},
1892+
}),
1893+
encodeTranscriptRecord({
1894+
type: "event_msg",
1895+
payload: { type: "user_message", message: "", images: [image], local_images: [] },
1896+
}),
1897+
encodeTranscriptRecord({
1898+
type: "response_item",
1899+
payload: {
1900+
type: "message",
1901+
role: "user",
1902+
content: [{ type: "input_image", image_url: image }],
1903+
},
1904+
}),
1905+
encodeTranscriptRecord({
1906+
type: "response_item",
1907+
payload: {
1908+
type: "message",
1909+
role: "assistant",
1910+
content: [{ type: "output_text", text: "A login form." }],
1911+
},
1912+
}),
1913+
].join("\n"),
1914+
mtimeMs: nowMs,
1915+
});
18931916

1894-
const threads = yield* runRecentThreads({
1895-
claudeHomePath,
1896-
codexHomePath,
1897-
workspaceRoot: workspace,
1898-
});
1917+
const threads = yield* runRecentThreads({
1918+
claudeHomePath,
1919+
codexHomePath,
1920+
workspaceRoot: workspace,
1921+
});
18991922

1900-
expect(threads[0]?.messages.map((message) => message.text)).toEqual([
1901-
"Describe this screenshot",
1902-
"A login form.",
1903-
]);
1904-
}),
1923+
expect(threads[0]?.messages.map((message) => message.text)).toEqual([
1924+
context,
1925+
"A login form.",
1926+
]);
1927+
}),
19051928
);
19061929

19071930
it.effect("suppresses duplicate session copies without reporting a skipped import", () =>
@@ -3381,6 +3404,16 @@ describe("parseAgentSessionTranscript", () => {
33813404
item: { type: "UserMessage", content: [{ type: "text", text: "Ship it" }] },
33823405
},
33833406
}),
3407+
assistant("Shipped."),
3408+
responseUser("Review the old code"),
3409+
encodeTranscriptRecord({ type: "event_msg", payload: { type: "turn_aborted" } }),
3410+
encodeTranscriptRecord({ type: "event_msg", payload: { type: "task_started" } }),
3411+
encodeTranscriptRecord({
3412+
type: "event_msg",
3413+
payload: { type: "user_message", message: "Review the new code" },
3414+
}),
3415+
responseUser("Review the new code"),
3416+
assistant("Done"),
33843417
].join("\n"),
33853418
source: "codex",
33863419
providerInstanceId: ProviderInstanceId.make("codex"),
@@ -3399,6 +3432,10 @@ describe("parseAgentSessionTranscript", () => {
33993432
"[Image #1]",
34003433
"Nice screenshot.",
34013434
"Ship it",
3435+
"Shipped.",
3436+
"Review the old code",
3437+
"Review the new code",
3438+
"Done",
34023439
]);
34033440
});
34043441

‎apps/server/src/project/AgentSessionScanner.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,14 @@ function codexUserText(text: string): string {
404404
.join("\n\n");
405405
}
406406

407+
// An interrupted turn ends without an assistant message.
408+
function isCodexTurnEnd(record: DecodedTranscriptRecord): boolean {
409+
return (
410+
record.type === "event_msg" &&
411+
(record.payload?.type === "turn_aborted" || record.payload?.type === "task_complete")
412+
);
413+
}
414+
407415
// Codex shows a prompt's images as these placeholders; an image-only prompt is only them.
408416
function codexImagePlaceholders(text: string, imageCount: number): string {
409417
if (text.trim().length > 0) return text;
@@ -588,8 +596,12 @@ function parseAgentSessionRecords(
588596
turnHasUserEvent = false;
589597
};
590598
for (const record of records) {
591-
if (codexUserEventText(record) !== null) {
592-
turnHasUserEvent = true;
599+
const eventText = codexUserEventText(record);
600+
if (eventText !== null) {
601+
// An event with nothing to show, like an inline image alone, cannot stand in for its copies.
602+
if (eventText.trim().length > 0) turnHasUserEvent = true;
603+
} else if (isCodexTurnEnd(record)) {
604+
finishTurn();
593605
} else if (record.type === "response_item" && record.payload?.type === "message") {
594606
if (record.payload.role === "assistant") finishTurn();
595607
else if (record.payload.role === "user") turnResponseUsers.push(record);
@@ -713,6 +725,7 @@ function shouldRetainDecodedRecord(
713725
record.type === "session_meta" ||
714726
record.type === "turn_context" ||
715727
codexUserEventText(record) !== null ||
728+
isCodexTurnEnd(record) ||
716729
(record.type === "response_item" &&
717730
record.payload?.type === "message" &&
718731
(record.payload.role === "user" || record.payload.role === "assistant"))

0 commit comments

Comments
 (0)