Skip to content

Commit fbc544a

Browse files
lopes-felipeclaude
andcommitted
Retry automatic thread title generation
A title request that times out or hits a busy CLI now retries twice with exponential backoff before falling back to the truncated message. An unsupported Codex ChatGPT model is not retried, since it has its own fallback model path. Each attempt re-invokes the provider. Ports pingdotgg/t3code#8087. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f75b925 commit fbc544a

2 files changed

Lines changed: 58 additions & 16 deletions

File tree

‎apps/server/src/threadTitle.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,35 @@ describe("resolveBestEffortGeneratedTitle", () => {
211211
);
212212
});
213213

214+
it("retries a transient title failure before falling back", async () => {
215+
const generateThreadTitle = vi
216+
.fn()
217+
.mockImplementationOnce(() => Effect.fail(new Error("Claude CLI request timed out.")))
218+
.mockImplementationOnce(() => Effect.fail(new Error("Claude CLI request timed out.")))
219+
.mockImplementationOnce(() => Effect.succeed({ title: "Generated after retry" }));
220+
221+
const title = await Effect.runPromise(
222+
resolveBestEffortGeneratedTitle({
223+
cwd: "/tmp/project",
224+
titleSourceText: "Plan the workflow",
225+
attachments: [],
226+
defaultTitle: "New thread",
227+
retryDelay: "1 millis",
228+
textGeneration: {
229+
generateCommitMessage: () => Effect.die("unsupported"),
230+
generatePrContent: () => Effect.die("unsupported"),
231+
generateBranchName: () => Effect.die("unsupported"),
232+
generateThreadTitle,
233+
generateStructuredJson: () => Effect.die("unsupported"),
234+
},
235+
logPrefix: "threadTitle test",
236+
}),
237+
);
238+
239+
expect(title).toBe("Generated after retry");
240+
expect(generateThreadTitle).toHaveBeenCalledTimes(3);
241+
});
242+
214243
it.each(["gpt-5.3-codex", DEFAULT_THREAD_TITLE_MODEL_BY_PROVIDER.codex])(
215244
"retries unsupported ChatGPT Codex title model %s with the standard Codex model",
216245
async (model) => {

‎apps/server/src/threadTitle.ts‎

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from "@t3tools/contracts";
1010
import { isUnsupportedCodexModelError } from "./provider/codexErrors.ts";
1111
import { Cause, Effect } from "effect";
12+
import * as Schedule from "effect/Schedule";
1213

1314
import type { TextGenerationShape } from "./git/Services/TextGeneration.ts";
1415

@@ -157,6 +158,8 @@ export const resolveBestEffortGeneratedTitleResult = (input: {
157158
readonly textGeneration: TextGenerationShape;
158159
readonly logPrefix: string;
159160
readonly logContext?: Record<string, unknown>;
161+
/** First backoff before retrying a failed generation; tests shorten it. */
162+
readonly retryDelay?: `${number} millis` | `${number} seconds`;
160163
}) =>
161164
Effect.gen(function* () {
162165
const fallbackTitle = buildFallbackTitle({
@@ -180,22 +183,32 @@ export const resolveBestEffortGeneratedTitleResult = (input: {
180183
input.titleGenerationModel ??
181184
DEFAULT_THREAD_TITLE_MODEL_BY_PROVIDER.codex;
182185
const generateTitle = (model: string) =>
183-
input.textGeneration.generateThreadTitle({
184-
cwd,
185-
message: input.titleSourceText,
186-
...(input.previousTitle !== undefined ? { previousTitle: input.previousTitle } : {}),
187-
...(input.linkedContext !== undefined ? { linkedContext: input.linkedContext } : {}),
188-
...(input.attachments.length > 0 ? { attachments: input.attachments } : {}),
189-
model,
190-
...(requestedModelSelection
191-
? {
192-
modelSelection:
193-
requestedModelSelection.model === model
194-
? requestedModelSelection
195-
: { ...requestedModelSelection, model },
196-
}
197-
: {}),
198-
});
186+
Effect.suspend(() =>
187+
input.textGeneration.generateThreadTitle({
188+
cwd,
189+
message: input.titleSourceText,
190+
...(input.previousTitle !== undefined ? { previousTitle: input.previousTitle } : {}),
191+
...(input.linkedContext !== undefined ? { linkedContext: input.linkedContext } : {}),
192+
...(input.attachments.length > 0 ? { attachments: input.attachments } : {}),
193+
model,
194+
...(requestedModelSelection
195+
? {
196+
modelSelection:
197+
requestedModelSelection.model === model
198+
? requestedModelSelection
199+
: { ...requestedModelSelection, model },
200+
}
201+
: {}),
202+
}),
203+
).pipe(
204+
// A timeout or a busy CLI is usually gone a few seconds later. An unsupported model is
205+
// not, and has its own fallback below.
206+
Effect.retry({
207+
times: 2,
208+
schedule: Schedule.exponential(input.retryDelay ?? "2 seconds"),
209+
while: (error) => !isUnsupportedCodexChatGptModelError(String(error)),
210+
}),
211+
);
199212

200213
let generatedResult = yield* Effect.exit(generateTitle(requestedModel));
201214

0 commit comments

Comments
 (0)