diff --git a/src/auto-reply/reply/agent-runner.ts b/src/auto-reply/reply/agent-runner.ts index 73a380e70..6b3b021ee 100644 --- a/src/auto-reply/reply/agent-runner.ts +++ b/src/auto-reply/reply/agent-runner.ts @@ -157,22 +157,26 @@ export async function runReplyAgent(params: { buffer: createAudioAsVoiceBuffer({ isAudioPayload }), }) : null; + const touchActiveSessionEntry = async () => { + if (!activeSessionEntry || !activeSessionStore || !sessionKey) { + return; + } + const updatedAt = Date.now(); + activeSessionEntry.updatedAt = updatedAt; + activeSessionStore[sessionKey] = activeSessionEntry; + if (storePath) { + await updateSessionStoreEntry({ + storePath, + sessionKey, + update: async () => ({ updatedAt }), + }); + } + }; if (shouldSteer && isStreaming) { const steered = queueEmbeddedPiMessage(followupRun.run.sessionId, followupRun.prompt); if (steered && !shouldFollowup) { - if (activeSessionEntry && activeSessionStore && sessionKey) { - const updatedAt = Date.now(); - activeSessionEntry.updatedAt = updatedAt; - activeSessionStore[sessionKey] = activeSessionEntry; - if (storePath) { - await updateSessionStoreEntry({ - storePath, - sessionKey, - update: async () => ({ updatedAt }), - }); - } - } + await touchActiveSessionEntry(); typing.cleanup(); return undefined; } @@ -180,18 +184,7 @@ export async function runReplyAgent(params: { if (isActive && (shouldFollowup || resolvedQueue.mode === "steer")) { enqueueFollowupRun(queueKey, followupRun, resolvedQueue); - if (activeSessionEntry && activeSessionStore && sessionKey) { - const updatedAt = Date.now(); - activeSessionEntry.updatedAt = updatedAt; - activeSessionStore[sessionKey] = activeSessionEntry; - if (storePath) { - await updateSessionStoreEntry({ - storePath, - sessionKey, - update: async () => ({ updatedAt }), - }); - } - } + await touchActiveSessionEntry(); typing.cleanup(); return undefined; }