Skip to content

Commit 940b8a5

Browse files
only21milclaude
andcommitted
fix(claude): retry without --no-session-persistence only on the CLI's stderr rejection
The retry matched the combined error detail, which prefers a stdout error result, so an API or model error mentioning the option could trigger it. Decide from the exit code and stderr instead, and build the reported error after that decision. Note in the Usage guide that Claude Code and Codex text generation is not in the totals. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7e0bde5 commit 940b8a5

3 files changed

Lines changed: 33 additions & 18 deletions

File tree

‎apps/server/src/textGeneration/ClaudeTextGeneration.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,14 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
468468
apiError,
469469
],
470470
["stderr when stdout has no error", "not json", wrapperNotice],
471+
[
472+
"a stdout error naming --no-session-persistence without retrying",
473+
JSON.stringify({
474+
is_error: true,
475+
result: "error: unknown option '--no-session-persistence'",
476+
}),
477+
"error: unknown option '--no-session-persistence'",
478+
],
471479
] as const)("reports %s when the Claude CLI fails", ([, output, expected]) =>
472480
withFakeClaudeEnv({ output, stderr: wrapperNotice, exitCode: 1 }, (textGeneration) =>
473481
Effect.gen(function* () {

‎apps/server/src/textGeneration/ClaudeTextGeneration.ts‎

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ const CLAUDE_INVESTIGATION_ALLOWED = [
5050
const CLAUDE_INVESTIGATION_DENIED = ["Bash(git * --output*)", "Bash(git * -o *)"].join(",");
5151

5252
const NO_SESSION_PERSISTENCE = "--no-session-persistence";
53-
// Claude Code before 2.0.63 rejects the flag; those runs retry without it.
54-
const rejectsNoSessionPersistence = (error: TextGenerationError) =>
55-
error.detail.includes(`unknown option '${NO_SESSION_PERSISTENCE}'`);
53+
// Claude Code before 2.0.63 exits with this on stderr; those runs retry without the flag.
54+
const NO_SESSION_PERSISTENCE_REJECTED = `error: unknown option '${NO_SESSION_PERSISTENCE}'`;
5655

5756
const ClaudeOutputEnvelope = Schema.Struct({
5857
structured_output: Schema.Unknown,
@@ -263,26 +262,32 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
263262
{ concurrency: "unbounded" },
264263
);
265264

266-
if (exitCode !== 0) {
265+
return { stdout, stderr, exitCode };
266+
});
267+
268+
const rawStdout = yield* runClaudeCommand(true).pipe(
269+
Effect.filterOrElse(
270+
(result) =>
271+
result.exitCode === 0 || !result.stderr.includes(NO_SESSION_PERSISTENCE_REJECTED),
272+
() => runClaudeCommand(false),
273+
),
274+
Effect.flatMap(({ stdout, stderr, exitCode }) => {
275+
if (exitCode === 0) return Effect.succeed(stdout);
267276
const stderrDetail = stderr.trim();
268277
const stdoutDetail = stdout.trim();
269278
const detail =
270279
claudeErrorResult(stdoutDetail) ??
271280
(stderrDetail.length > 0 ? stderrDetail : stdoutDetail);
272-
return yield* new TextGenerationError({
273-
operation,
274-
detail:
275-
detail.length > 0
276-
? `Claude CLI command failed: ${detail}`
277-
: `Claude CLI command failed with code ${exitCode}.`,
278-
});
279-
}
280-
281-
return stdout;
282-
});
283-
284-
const rawStdout = yield* runClaudeCommand(true).pipe(
285-
Effect.catchIf(rejectsNoSessionPersistence, () => runClaudeCommand(false)),
281+
return Effect.fail(
282+
new TextGenerationError({
283+
operation,
284+
detail:
285+
detail.length > 0
286+
? `Claude CLI command failed: ${detail}`
287+
: `Claude CLI command failed with code ${exitCode}.`,
288+
}),
289+
);
290+
}),
286291
Effect.scoped,
287292
Effect.timeoutOption(investigate?.timeoutMs ?? CLAUDE_TIMEOUT_MS),
288293
Effect.flatMap(

‎docs/user/usage.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Select a model under **Breakdown** to see its trend, cache hit rate, and cost pe
1717

1818
Totals depend on the history available on each server. Grok turns without a saved completed-turn
1919
record are missing from the totals.
20+
Text generation (thread titles, commit messages, PR text, branch names and review guides) is not in
21+
the totals for Codex or Claude Code 2.0.63 and newer, because those runs save no session history.
2022

2123
OpenCode reads its SQLite database and older JSON history. Antigravity reads local conversation
2224
databases, including T3-managed profiles. Set `OPENCODE_DATA_DIR` or `ANTIGRAVITY_DATA_DIR` on the

0 commit comments

Comments
 (0)