From 0fa3173e73bdc960f05122c136bbb3ea9a846a9a Mon Sep 17 00:00:00 2001 From: Jason Carreira Date: Fri, 6 Mar 2026 13:54:56 -0500 Subject: [PATCH] fix: create new conversation for per-channel mode instead of resuming default (#503) Co-authored-by: Letta Code Co-authored-by: Claude Sonnet 4.6 --- src/core/sdk-session-contract.test.ts | 4 ++-- src/core/session-manager.ts | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/core/sdk-session-contract.test.ts b/src/core/sdk-session-contract.test.ts index 6487be5..4e18f92 100644 --- a/src/core/sdk-session-contract.test.ts +++ b/src/core/sdk-session-contract.test.ts @@ -499,7 +499,7 @@ describe('SDK session contract', () => { let createdSessions = 0; let startedSends = 0; - vi.mocked(resumeSession).mockImplementation((_id, opts) => { + vi.mocked(createSession).mockImplementation((_id, opts) => { const sessionName = createdSessions++ === 0 ? 'chat-a' : 'chat-b'; return { initialize: vi.fn(async () => undefined), @@ -655,7 +655,7 @@ describe('SDK session contract', () => { agentId: 'agent-contract-test', conversationId: 'conv-new', }; - vi.mocked(resumeSession).mockReturnValue(createdSession as never); + vi.mocked(createSession).mockReturnValue(createdSession as never); const activeSession = { close: vi.fn(() => undefined), diff --git a/src/core/session-manager.ts b/src/core/session-manager.ts index 2c04d1f..57177ba 100644 --- a/src/core/session-manager.ts +++ b/src/core/session-manager.ts @@ -255,12 +255,16 @@ export class SessionManager { } session = resumeSession(convId, opts); } else if (this.store.agentId) { - // Agent exists but no conversation stored -- resume the default conversation + // Agent exists but no conversation stored for this key. + // 'shared' is the single shared conversation — resume it like the default. + // Channel-specific keys (per-channel/per-chat mode) need a fresh conversation. process.env.LETTA_AGENT_ID = this.store.agentId; installSkillsToAgent(this.store.agentId, this.config.skills); sessionAgentId = this.store.agentId; - prependSkillDirsToPath(sessionAgentId); // must be before resumeSession spawns subprocess - session = resumeSession(this.store.agentId, opts); + prependSkillDirsToPath(sessionAgentId); // must be before resumeSession/createSession spawns subprocess + session = key === 'shared' + ? resumeSession(this.store.agentId, opts) + : createSession(this.store.agentId, opts); } else { // Create new agent -- persist immediately so we don't orphan it on later failures log.info('Creating new agent');