From a8f205609be8ef26976b75e41432a668f09fd2c4 Mon Sep 17 00:00:00 2001 From: Markov Date: Mon, 23 Feb 2026 22:28:57 +0100 Subject: [PATCH] fix: single session per agent instance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One agent = one session. Chat, tasks, tools — all share the same context. Session ID: 'agent-{slug}' (stable across restarts). --- src/router.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/router.ts b/src/router.ts index 93e6bd3..67eaab4 100644 --- a/src/router.ts +++ b/src/router.ts @@ -16,17 +16,20 @@ export class EventRouter { private log = logger.child({ component: 'event-router' }); private activeTasks = 0; private trackerTools: ToolDefinition[]; + /** Single session ID for the entire agent lifetime. */ + private readonly sessionId: string; constructor( private config: AgentConfig, private client: TrackerClient, private taskTracker: TaskTracker, ) { + this.sessionId = `agent-${config.slug}`; this.trackerTools = createTrackerTools({ trackerClient: client, agentSlug: config.slug, }); - this.log.info({ toolCount: this.trackerTools.length }, 'Tracker tools registered'); + this.log.info({ toolCount: this.trackerTools.length, sessionId: this.sessionId }, 'Tracker tools registered'); } async handleEvent(event: TrackerEvent): Promise { @@ -87,7 +90,7 @@ export class EventRouter { let collectedText = ''; for await (const msg of runAgent(prompt, { workDir: this.config.workDir, - sessionId: `task-${task.id}`, + sessionId: this.sessionId, model: this.config.model, provider: this.config.provider, systemPrompt: this.config.prompt || undefined, @@ -156,13 +159,10 @@ export class EventRouter { this.log.info('│ MESSAGE from @%s: "%s"', authorSlug, content.slice(0, 200)); this.log.info('│ Context: %s | Mentioned: %s', taskId ? `task=${taskId}` : chatId ? `chat=${chatId}` : 'none', isMentioned); - // Stable session ID per chat/task context — preserves conversation history - const sessionId = chatId ? `chat-${chatId}` : taskId ? `task-${taskId}` : `msg-${Date.now()}`; - let collectedText = ''; for await (const msg of runAgent(content, { workDir: this.config.workDir, - sessionId, + sessionId: this.sessionId, model: this.config.model, provider: this.config.provider, systemPrompt: this.config.prompt || undefined,