Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
fix(openai-codex): name the legs bound in the code-mode stop text
Jack Rudenko0eda3241fe64
diff --git a/ai-docs/architecture/code-mode.md b/ai-docs/architecture/code-mode.mdindex 1e0a59c7..276c631d 100644--- a/ai-docs/architecture/code-mode.md+++ b/ai-docs/architecture/code-mode.md@@ -157,8 +157,9 @@ downstream Claude message) — the same mechanism that retries a degenerate legtool_use`. Claude Code runs the tools under its own permissions.- **finished** without blocking → its output is stored and another leg is issued: the currentleg's body with this leg's items and the exec call + output appended to `input`.-- `MAX_LEGS_PER_TURN = 6` and `MAX_INTERSTITIAL_EXECS = 6` (legs count continuations AND retries)- end the message with `[claudish: stopped after 6 code-mode attempts]`. A retry inside a code-mode+- `MAX_LEGS_PER_TURN = 6` (legs count continuations AND retries; each exec answered inside the+ message adds a leg, so it bounds those too) ends the message with `[claudish: stopped after 6+ upstream requests in one code-mode turn]`. A retry inside a code-modeturn re-sends the CURRENT leg's body; retries count per leg position.- Usage stays honest: the context figure is the LAST leg's input, output is summed over legs, theearlier legs' input is billed once (cost only) before the one `onTokenUpdate` that fires thediff --git a/packages/cli/src/handlers/shared/stream-parsers/responses/responses-turn.ts b/packages/cli/src/handlers/shared/stream-parsers/responses/responses-turn.tsindex d480c6de..9dc9ef19 100644--- a/packages/cli/src/handlers/shared/stream-parsers/responses/responses-turn.ts+++ b/packages/cli/src/handlers/shared/stream-parsers/responses/responses-turn.ts@@ -41,22 +41,39 @@* - continue: the script finished without blocking → another leg whose body* is the previous leg's body with this leg's items and the exec call +* output appended to `input`.- * Bounded by MAX_LEGS_PER_TURN and MAX_INTERSTITIAL_EXECS. A retry inside a- * code-mode turn re-sends the CURRENT leg's body, not the first one.+ * Bounded by MAX_LEGS_PER_TURN. A retry inside a code-mode turn re-sends the+ * CURRENT leg's body, not the first one.*/+import {+ type CodeModeTurnHooks,+ type ExecTurnStep,+ type ResponsesItem,+ relayNestedInput,+} from "../../../../code-mode/types.js";+import { log } from "../../../../logger.js";+import type { LegResponse } from "../../responses-leg-issuer.js";+import type { UsageCacheDetail } from "../../token-tracker.js";+import type { ClaudeSseSink } from "./claude-sse-sink.js";+import {+ type LegOutcome,+ type ResponsesLegContext,+ type Usage,+ parseResponsesLeg,+} from "./responses-leg.js";+import { type StallClock, type StallPolicy, systemStallClock } from "./stall-guard.js";+/** Retries per leg position: 3 attempts in all. */export const MAX_LEG_RETRIES = 2;/**- * Code mode: upstream legs one downstream message may use (continuations- * after an exec that did not block, plus retries), and exec calls answered- * inside one message. Either bound ends the message with- * {@link CODE_MODE_STOP_TEXT}.+ * Code mode: upstream legs one downstream message may use — continuations+ * after an exec that did not block AND retries. It also bounds the execs+ * answered inside one message, since each of those adds a leg. Reaching it+ * ends the message with {@link CODE_MODE_STOP_TEXT}.*/export const MAX_LEGS_PER_TURN = 6;-export const MAX_INTERSTITIAL_EXECS = 6;-export const CODE_MODE_STOP_TEXT = `\n\n[claudish: stopped after ${MAX_INTERSTITIAL_EXECS} code-mode attempts]`;+export const CODE_MODE_STOP_TEXT = `\n\n[claudish: stopped after ${MAX_LEGS_PER_TURN} upstream requests in one code-mode turn]`;type RetryDecision =| { action: "finish" }@@ -86,24 +103,6 @@ function sum(values: number[]): number {return values.reduce((a, b) => a + b, 0);}-import {- type CodeModeTurnHooks,- type ExecTurnStep,- type ResponsesItem,- relayNestedInput,-} from "../../../../code-mode/types.js";-import { log } from "../../../../logger.js";-import type { LegResponse } from "../../responses-leg-issuer.js";-import type { UsageCacheDetail } from "../../token-tracker.js";-import type { ClaudeSseSink } from "./claude-sse-sink.js";-import {- type LegOutcome,- type ResponsesLegContext,- type Usage,- parseResponsesLeg,-} from "./responses-leg.js";-import { type StallClock, type StallPolicy, systemStallClock } from "./stall-guard.js";-export interface ResponsesTurnOptionsextends Omit<ResponsesLegContext, "sink" | "codeMode" | "drainClock"> {/** Code mode for this turn (architecture §5.11). Absent ⇒ exec calls are ignored, as before. */@@ -212,7 +211,6 @@ class ResponsesTurn {private usageReported = false;/** The current leg's body; undefined ⇒ the primary request's (`issueLeg(undefined)`). */private currentBody: unknown = undefined;- private interstitialExecs = 0;/** Code mode: the Responses items of earlier legs of this message, interstitial execs included. */private readonly turnItems: ResponsesItem[] = [];@@ -498,12 +496,8 @@ class ResponsesTurn {await this.finishCompleted("tool_use");return undefined;}- this.interstitialExecs++;this.turnItems.push(...outcome.precedingItems, ...appendItems);- if (- this.interstitialExecs > MAX_INTERSTITIAL_EXECS ||- this.legUsages.length >= MAX_LEGS_PER_TURN- ) {+ if (this.legUsages.length >= MAX_LEGS_PER_TURN) {await this.stopAttempts();return undefined;}@@ -540,7 +534,6 @@ class ResponsesTurn {return undefined;}- /** Issue the next leg; undefined when the turn has ended instead. *//*** This leg's stall guard settings: the final attempt (no retry left) gets the* longer threshold, so no attempt is unbounded and the last one still has