Skip to content

Commit 638947e

Browse files
only21milclaude
andauthored
fix(claude): Claude text generation stops saving throwaway transcripts (#28367)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent dcbe9a6 commit 638947e

4 files changed

Lines changed: 84 additions & 15 deletions

File tree

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function makeFakeClaudeBinary(dir: string, lifecyclePort?: number) {
5757
function withFakeClaudeEnv<A, E, R>(
5858
input: {
5959
output: string;
60+
rejectsNoSessionPersistence?: boolean;
6061
lifecyclePort?: number;
6162
exitCode?: number;
6263
stderr?: string;
@@ -75,6 +76,8 @@ function withFakeClaudeEnv<A, E, R>(
7576
const binDir = yield* makeFakeClaudeBinary(tempDir, input.lifecyclePort);
7677
const pathDelimiter = (yield* HostProcess.isWindows) ? ";" : ":";
7778
const previousPath = process.env.PATH;
79+
const previousRejectsNoSessionPersistence =
80+
process.env.T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE;
7881
const previousOutput = process.env.T3_FAKE_CLAUDE_OUTPUT;
7982
const previousExitCode = process.env.T3_FAKE_CLAUDE_EXIT_CODE;
8083
const previousStderr = process.env.T3_FAKE_CLAUDE_STDERR;
@@ -89,6 +92,12 @@ function withFakeClaudeEnv<A, E, R>(
8992
process.env.PATH = `${binDir}${pathDelimiter}${previousPath ?? ""}`;
9093
process.env.T3_FAKE_CLAUDE_OUTPUT = input.output;
9194

95+
if (input.rejectsNoSessionPersistence) {
96+
process.env.T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE = "1";
97+
} else {
98+
delete process.env.T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE;
99+
}
100+
92101
if (input.exitCode !== undefined) {
93102
process.env.T3_FAKE_CLAUDE_EXIT_CODE = String(input.exitCode);
94103
} else {
@@ -135,6 +144,13 @@ function withFakeClaudeEnv<A, E, R>(
135144
Effect.sync(() => {
136145
process.env.PATH = previousPath;
137146

147+
if (previousRejectsNoSessionPersistence === undefined) {
148+
delete process.env.T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE;
149+
} else {
150+
process.env.T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE =
151+
previousRejectsNoSessionPersistence;
152+
}
153+
138154
if (previousOutput === undefined) {
139155
delete process.env.T3_FAKE_CLAUDE_OUTPUT;
140156
} else {
@@ -320,6 +336,28 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
320336
}),
321337
);
322338

339+
it.effect("retries without --no-session-persistence when the Claude CLI rejects it", () =>
340+
withFakeClaudeEnv(
341+
{
342+
output: JSON.stringify({ structured_output: { title: "Reconnect failures" } }),
343+
rejectsNoSessionPersistence: true,
344+
},
345+
(textGeneration) =>
346+
Effect.gen(function* () {
347+
const generated = yield* textGeneration.generateThreadTitle({
348+
cwd: process.cwd(),
349+
message: "Investigate reconnect failures",
350+
modelSelection: {
351+
instanceId: ProviderInstanceId.make("claudeAgent"),
352+
model: SYNTHETIC_CLAUDE_STANDARD_MODEL,
353+
},
354+
});
355+
356+
expect(generated.title).toBe("Reconnect failures");
357+
}),
358+
),
359+
);
360+
323361
it.effect.each([
324362
{ verbose: false, label: "normal" },
325363
{ verbose: true, label: "verbose" },
@@ -430,6 +468,14 @@ it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
430468
apiError,
431469
],
432470
["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+
],
433479
] as const)("reports %s when the Claude CLI fails", ([, output, expected]) =>
434480
withFakeClaudeEnv({ output, stderr: wrapperNotice, exitCode: 1 }, (textGeneration) =>
435481
Effect.gen(function* () {

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

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ const CLAUDE_INVESTIGATION_ALLOWED = [
4949
// Denies override allows; block git --output/-o because allowed trailing args can otherwise write anywhere.
5050
const CLAUDE_INVESTIGATION_DENIED = ["Bash(git * --output*)", "Bash(git * -o *)"].join(",");
5151

52+
const NO_SESSION_PERSISTENCE = "--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}'`;
55+
5256
const ClaudeOutputEnvelope = Schema.Struct({
5357
structured_output: Schema.Unknown,
5458
});
@@ -181,7 +185,9 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
181185
"Failed to encode Claude CLI settings.",
182186
);
183187

184-
const runClaudeCommand = Effect.fn("runClaudeJson.runClaudeCommand")(function* () {
188+
const runClaudeCommand = Effect.fn("runClaudeJson.runClaudeCommand")(function* (
189+
noSessionPersistence: boolean,
190+
) {
185191
const workingDirectory =
186192
operation === "generateThreadTitle"
187193
? yield* fileSystem
@@ -217,6 +223,7 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
217223
]
218224
: ["--tools", ""]),
219225
"--disable-slash-commands",
226+
...(noSessionPersistence ? [NO_SESSION_PERSISTENCE] : []),
220227
// managed-mcp.json already isolates servers and makes Claude reject this flag.
221228
...(managedMcpConfig ? [] : ["--strict-mcp-config"]),
222229
"--permission-mode",
@@ -255,25 +262,32 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
255262
{ concurrency: "unbounded" },
256263
);
257264

258-
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);
259276
const stderrDetail = stderr.trim();
260277
const stdoutDetail = stdout.trim();
261278
const detail =
262279
claudeErrorResult(stdoutDetail) ??
263280
(stderrDetail.length > 0 ? stderrDetail : stdoutDetail);
264-
return yield* new TextGenerationError({
265-
operation,
266-
detail:
267-
detail.length > 0
268-
? `Claude CLI command failed: ${detail}`
269-
: `Claude CLI command failed with code ${exitCode}.`,
270-
});
271-
}
272-
273-
return stdout;
274-
});
275-
276-
const rawStdout = yield* runClaudeCommand().pipe(
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+
}),
277291
Effect.scoped,
278292
Effect.timeoutOption(investigate?.timeoutMs ?? CLAUDE_TIMEOUT_MS),
279293
Effect.flatMap(

‎apps/server/src/textGeneration/testing/ClaudeTextGeneration.fixture.mjs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ if (!argv.includes("--disable-slash-commands")) {
2525
if (!argv.includes("--strict-mcp-config")) {
2626
fail("text generation must not load configured MCP servers", 9);
2727
}
28+
if (process.env.T3_FAKE_CLAUDE_REJECTS_NO_SESSION_PERSISTENCE === "1") {
29+
if (argv.includes("--no-session-persistence")) {
30+
fail("error: unknown option '--no-session-persistence'", 1);
31+
}
32+
} else if (!argv.includes("--no-session-persistence")) {
33+
fail("text generation must not save a resumable session", 16);
34+
}
2835
const settingsIndex = argv.indexOf("--settings");
2936
if (settingsIndex === -1 || JSON.parse(argv[settingsIndex + 1]).disableAllHooks !== true) {
3037
fail("text generation must disable hooks", 10);

‎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)