Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

fix(openai-codex): render an exec output answered after a user message

Jack Rudenko4a751f0cd35d
diff --git a/packages/cli/src/code-mode/input-builder.ts b/packages/cli/src/code-mode/input-builder.ts
index 392412fa..afac8eab 100644
--- a/packages/cli/src/code-mode/input-builder.ts
+++ b/packages/cli/src/code-mode/input-builder.ts
@@ -404,15 +404,20 @@ class InputBuilder {
// ─── exec outputs ───────────────────────────────────────────────────
- /** True when message `i` answers the group's LAST round (the script ended there). */
+ /**
+ * True when message `i` (which carries a result of this group) answers the
+ * group's LAST round. Usually the first user message after that round; a
+ * later one when a user message without its results came between —
+ * `closeMovedOnGroups` leaves the group open then (its results exist), so
+ * the output must land here or the `custom_tool_call` has none at all.
+ * `emitOutput` emits once, so a later duplicate result changes nothing.
+ */
private completesAt(group: ExecGroup, i: number): boolean {
const last = group.rounds[group.rounds.length - 1];
if (!last || last.assistantIndex >= i) return false;
- // Only the first user message after the last round answers it.
- for (let j = last.assistantIndex + 1; j < i; j++) {
- if (this.messages[j]?.role === "user") return false;
- }
- return true;
+ return blocksOf(this.messages[i]).some(
+ (b) => b.type === "tool_result" && last.blocks.some((use) => use.id === b.tool_use_id)
+ );
}
private maybeCompleteGroup(execKey: string, i: number): void {