Skip to content

Commit 7e0bde5

Browse files
only21milclaude
andcommitted
fix(claude): retry text generation without --no-session-persistence when the CLI rejects it
The version gate read the provider probe's snapshot, which is null until the first probe finishes and comes from the state directory, while generation runs in a temp or project directory where a cwd-sensitive wrapper can launch a different Claude Code. Always pass the flag and, only when the CLI rejects it as an unknown option (Claude Code before 2.0.63), run once more without it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 53f4b61 commit 7e0bde5

3 files changed

Lines changed: 12 additions & 24 deletions

File tree

‎apps/server/src/provider/Drivers/ClaudeDriver.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ export const ClaudeDriver: ProviderDriver<ClaudeSettings, ClaudeDriverEnv, Path.
193193
);
194194
const textGeneration = yield* makeClaudeTextGeneration(
195195
effectiveConfig,
196-
Effect.suspend(() => snapshot.getSnapshot).pipe(Effect.map((current) => current.version)),
197196
processEnv,
198197
modelCatalog,
199198
);

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ function makeFakeClaudeBinary(dir: string, lifecyclePort?: number) {
5757
function withFakeClaudeEnv<A, E, R>(
5858
input: {
5959
output: string;
60-
cliVersion?: string | null;
6160
rejectsNoSessionPersistence?: boolean;
6261
lifecyclePort?: number;
6362
exitCode?: number;
@@ -205,7 +204,6 @@ function withFakeClaudeEnv<A, E, R>(
205204
const config = decodeClaudeSettings(input.claudeConfig ?? {});
206205
const textGeneration = yield* makeClaudeTextGeneration(
207206
config,
208-
Effect.succeed(input.cliVersion === undefined ? "2.1.316" : input.cliVersion),
209207
undefined,
210208
Effect.succeed(SYNTHETIC_CLAUDE_MODEL_CATALOG),
211209
);
@@ -338,20 +336,11 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
338336
}),
339337
);
340338

341-
it.effect.each([
342-
{ cliVersion: "2.0.63", rejectsNoSessionPersistence: false, label: "passes it to 2.0.63" },
343-
{ cliVersion: "2.0.62", rejectsNoSessionPersistence: true, label: "omits it for 2.0.62" },
344-
{
345-
cliVersion: null,
346-
rejectsNoSessionPersistence: true,
347-
label: "omits it for an unknown version",
348-
},
349-
])("--no-session-persistence $label", ({ cliVersion, rejectsNoSessionPersistence }) =>
339+
it.effect("retries without --no-session-persistence when the Claude CLI rejects it", () =>
350340
withFakeClaudeEnv(
351341
{
352342
output: JSON.stringify({ structured_output: { title: "Reconnect failures" } }),
353-
cliVersion,
354-
rejectsNoSessionPersistence,
343+
rejectsNoSessionPersistence: true,
355344
},
356345
(textGeneration) =>
357346
Effect.gen(function* () {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
getModelSelectionStringOptionValue,
1919
getProviderOptionDescriptors,
2020
} from "@t3tools/shared/model";
21-
import { compareSemverVersions } from "@t3tools/shared/semver";
2221
import {
2322
BUNDLED_CLAUDE_MODEL_CATALOG,
2423
type ClaudeModelCatalog,
@@ -50,8 +49,10 @@ const CLAUDE_INVESTIGATION_ALLOWED = [
5049
// Denies override allows; block git --output/-o because allowed trailing args can otherwise write anywhere.
5150
const CLAUDE_INVESTIGATION_DENIED = ["Bash(git * --output*)", "Bash(git * -o *)"].join(",");
5251

53-
// Claude Code before 2.0.63 rejects --no-session-persistence as an unknown option.
54-
const NO_SESSION_PERSISTENCE_MIN_VERSION = "2.0.63";
52+
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}'`);
5556

5657
const ClaudeOutputEnvelope = Schema.Struct({
5758
structured_output: Schema.Unknown,
@@ -83,7 +84,6 @@ function claudeErrorResult(stdout: string): string | undefined {
8384

8485
export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(function* (
8586
claudeSettings: ClaudeSettings,
86-
cliVersion: Effect.Effect<string | null>,
8787
environment?: NodeJS.ProcessEnv,
8888
modelCatalog: Effect.Effect<ClaudeModelCatalog> = Effect.succeed(BUNDLED_CLAUDE_MODEL_CATALOG),
8989
) {
@@ -186,7 +186,9 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
186186
"Failed to encode Claude CLI settings.",
187187
);
188188

189-
const runClaudeCommand = Effect.fn("runClaudeJson.runClaudeCommand")(function* () {
189+
const runClaudeCommand = Effect.fn("runClaudeJson.runClaudeCommand")(function* (
190+
noSessionPersistence: boolean,
191+
) {
190192
const workingDirectory =
191193
operation === "generateThreadTitle"
192194
? yield* fileSystem
@@ -198,9 +200,6 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
198200
)
199201
: cwd;
200202
const managedMcpConfig = yield* hasClaudeManagedMcpConfig();
201-
const version = yield* cliVersion;
202-
const supportsNoSessionPersistence =
203-
version !== null && compareSemverVersions(version, NO_SESSION_PERSISTENCE_MIN_VERSION) >= 0;
204203
const spawnCommand = yield* resolveSpawnCommand(
205204
claudeSettings.binaryPath || "claude",
206205
[
@@ -225,7 +224,7 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
225224
]
226225
: ["--tools", ""]),
227226
"--disable-slash-commands",
228-
...(supportsNoSessionPersistence ? ["--no-session-persistence"] : []),
227+
...(noSessionPersistence ? [NO_SESSION_PERSISTENCE] : []),
229228
// managed-mcp.json already isolates servers and makes Claude reject this flag.
230229
...(managedMcpConfig ? [] : ["--strict-mcp-config"]),
231230
"--permission-mode",
@@ -282,7 +281,8 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
282281
return stdout;
283282
});
284283

285-
const rawStdout = yield* runClaudeCommand().pipe(
284+
const rawStdout = yield* runClaudeCommand(true).pipe(
285+
Effect.catchIf(rejectsNoSessionPersistence, () => runClaudeCommand(false)),
286286
Effect.scoped,
287287
Effect.timeoutOption(investigate?.timeoutMs ?? CLAUDE_TIMEOUT_MS),
288288
Effect.flatMap(

0 commit comments

Comments
 (0)