From e8ede14f5d51bae1ef1290cbd051351760936c65 Mon Sep 17 00:00:00 2001 From: haoqixu Date: Tue, 23 Jun 2026 19:32:55 +0800 Subject: [PATCH] fix(agent): normalize session names --- packages/agent/src/harness/session/session.ts | 3 ++- packages/agent/test/harness/session.test.ts | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/agent/src/harness/session/session.ts b/packages/agent/src/harness/session/session.ts index 6f136208..ce369dff 100644 --- a/packages/agent/src/harness/session/session.ts +++ b/packages/agent/src/harness/session/session.ts @@ -234,12 +234,13 @@ export class Session { } async appendSessionName(name: string): Promise { + const sanitizedName = name.replace(/[\r\n]+/g, " ").trim(); return this.appendTypedEntry({ type: "session_info", id: await this.storage.createEntryId(), parentId: await this.storage.getLeafId(), timestamp: new Date().toISOString(), - name: name.trim(), + name: sanitizedName, } satisfies SessionInfoEntry); } diff --git a/packages/agent/test/harness/session.test.ts b/packages/agent/test/harness/session.test.ts index c9598da8..39e285b5 100644 --- a/packages/agent/test/harness/session.test.ts +++ b/packages/agent/test/harness/session.test.ts @@ -86,6 +86,12 @@ async function runSessionSuite( expect(context.messages[1]?.role).toBe("custom"); }); + it("normalizes session names", async () => { + const session = new Session(await createStorage()); + await session.appendSessionName(" hello\nworld\r\nagain "); + expect(await session.getSessionName()).toBe("hello world again"); + }); + it("supports labels and session info entries without affecting context", async () => { const session = new Session(await createStorage()); const user1 = await session.appendMessage(createUserMessage("one"));