Skip to content

Commit 4908d8c

Browse files
Gigioxxjuliusmarmingeclaude
authored
fix(server): keep Claude renames when importing sessions (pingdotgg#12292)
Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent 5f89a05 commit 4908d8c

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎apps/server/src/project/AgentSessionScanner.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2808,6 +2808,40 @@ describe("parseAgentSessionTranscript", () => {
28082808
});
28092809
});
28102810

2811+
it.each([
2812+
{ customTitles: ["Refactor auth module"], expected: "Refactor auth module" },
2813+
// Claude writes an empty customTitle when the user clears a rename.
2814+
{ customTitles: ["Refactor auth module", ""], expected: "Generated title" },
2815+
])("uses Claude custom titles $customTitles over the AI title", ({ customTitles, expected }) => {
2816+
const aiTitle = JSON.stringify({
2817+
type: "ai-title",
2818+
aiTitle: "Generated title",
2819+
sessionId: "claude-session",
2820+
});
2821+
const thread = AgentSessionScanner.parseAgentSessionTranscript({
2822+
contents: [
2823+
JSON.stringify({
2824+
type: "user",
2825+
sessionId: "claude-session",
2826+
timestamp: "2026-08-24T10:00:00.000Z",
2827+
message: { role: "user", content: "<command-name>/effort</command-name>" },
2828+
}),
2829+
// Claude rewrites both records on every metadata flush with ai-title
2830+
// last, so a later ai-title must not override the user's rename.
2831+
...customTitles.flatMap((customTitle) => [
2832+
JSON.stringify({ type: "custom-title", customTitle, sessionId: "claude-session" }),
2833+
aiTitle,
2834+
]),
2835+
].join("\n"),
2836+
source: "claudeAgent",
2837+
providerInstanceId: ProviderInstanceId.make("claudeAgent"),
2838+
fallbackSessionId: "fallback",
2839+
lastActiveAtMs: Date.parse("2026-08-24T12:00:00.000Z"),
2840+
});
2841+
2842+
expect(thread?.title).toBe(expected);
2843+
});
2844+
28112845
it("drops injected Codex instructions while keeping the visible user event", () => {
28122846
const thread = AgentSessionScanner.parseAgentSessionTranscript({
28132847
contents: [

‎apps/server/src/project/AgentSessionScanner.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const TranscriptRecord = Schema.Struct({
8888
cwd: Schema.optional(Schema.String),
8989
sessionId: Schema.optional(Schema.String),
9090
aiTitle: Schema.optional(Schema.String),
91+
customTitle: Schema.optional(Schema.String),
9192
isSidechain: Schema.optional(Schema.Boolean),
9293
isMeta: Schema.optional(Schema.Boolean),
9394
isCompactSummary: Schema.optional(Schema.Boolean),
@@ -277,6 +278,7 @@ function parseAgentSessionRecords(
277278
// timestamp text, so only transcript metadata can provide a resumable ID.
278279
let providerSessionId = input.source === "codex" ? "" : input.fallbackSessionId;
279280
let title: string | null = null;
281+
let customTitle: string | null = null;
280282
let derivedTitle: string | undefined;
281283
let model: string | null = null;
282284
let hasCodexSessionId = false;
@@ -379,6 +381,10 @@ function parseAgentSessionRecords(
379381
}
380382
if (record.sessionId?.trim()) providerSessionId = record.sessionId.trim();
381383
if (record.aiTitle?.trim()) title = record.aiTitle.trim();
384+
// Claude rewrites both title records on every flush, so the user's
385+
// rename is tracked separately instead of racing the later ai-title.
386+
// An empty customTitle is how Claude clears a rename.
387+
if (record.customTitle !== undefined) customTitle = record.customTitle.trim() || null;
382388
const messageModel = record.message?.model?.trim();
383389
// Claude uses this sentinel for local error responses. It is not a
384390
// model ID that can be selected when the imported session resumes.
@@ -471,7 +477,7 @@ function parseAgentSessionRecords(
471477
source: input.source,
472478
providerInstanceId: input.providerInstanceId,
473479
providerSessionId,
474-
title: title ?? derivedTitle ?? "Imported thread",
480+
title: customTitle ?? title ?? derivedTitle ?? "Imported thread",
475481
model,
476482
createdAt: retainedMessages[0]?.createdAt ?? fallbackTimestamp,
477483
updatedAt: fallbackTimestamp,
@@ -495,6 +501,7 @@ function shouldRetainDecodedRecord(
495501
record.type === "assistant" ||
496502
record.sessionId !== undefined ||
497503
record.aiTitle !== undefined ||
504+
record.customTitle !== undefined ||
498505
record.message?.model !== undefined
499506
);
500507
}

0 commit comments

Comments
 (0)