fix(session): preserve title on first-turn branches

This commit is contained in:
can1357
2026-08-03 14:43:39 +02:00
parent 14a03d4579
commit b1d75bb55b
3 changed files with 29 additions and 0 deletions
@@ -7506,7 +7506,10 @@ export class AgentSession {
await this.#advisors.drainAndDetachRecorders();
try {
if (!selectedEntry.parentId) {
const title = this.sessionManager.getSessionName();
const titleSource = this.sessionManager.titleSource;
await this.sessionManager.newSession({ parentSession: previousSessionFile });
if (title) await this.sessionManager.setSessionName(title, titleSource);
} else {
this.sessionManager.createBranchedSession(selectedEntry.parentId);
}
@@ -181,6 +181,29 @@ function historicalImagePrompt(text: string): UserMessage {
};
}
describe("AgentSession branch title metadata", () => {
it("preserves an explicit title when branching before the first prompt", async () => {
const ctx = await createTestSession({ inMemory: true });
try {
const entryId = ctx.sessionManager.appendMessage({
role: "user",
content: "hello",
timestamp: Date.now(),
});
await ctx.sessionManager.setSessionName("new-ds", "user");
await ctx.session.branch(entryId);
expect(ctx.sessionManager.getSessionName()).toBe("new-ds");
expect(ctx.sessionManager.titleSource).toBe("user");
expect(await ctx.sessionManager.setSessionName("automatic", "auto")).toBe(false);
expect(ctx.sessionManager.getSessionName()).toBe("new-ds");
} finally {
await ctx.cleanup();
}
});
});
describe("AgentSession historical image prompts", () => {
it("returns the selected images when branching from a user prompt", async () => {
const ctx = await createTestSession({ inMemory: true });
@@ -461,6 +461,9 @@ describe("createBranchedSession", () => {
session.createBranchedSession(leafId);
expect(session.getSessionName()).toBe("new-ds");
expect(session.titleSource).toBe("user");
expect(await session.setSessionName("automatic", "auto")).toBe(false);
expect(session.getSessionName()).toBe("new-ds");
});
it("extracts correct path from branched tree", () => {