The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): voice turn bound honours hidden user rows; adopt moves the null-session anchor
kshitijk4poor2516ed13d8c7
diff --git a/apps/desktop/src/lib/chat-messages.test.ts b/apps/desktop/src/lib/chat-messages.test.tsindex 306b03dd38f..6d2282211a5 100644--- a/apps/desktop/src/lib/chat-messages.test.ts+++ b/apps/desktop/src/lib/chat-messages.test.ts@@ -1355,6 +1355,17 @@ describe('collectUnspokenTurnSpeech', () => {expect(collectUnspokenTurnSpeech(messages, 'vanished-stream-id')?.text).toBe('Live reply only.')expect(collectUnspokenTurnSpeech(messages, 'a1')?.text).toBe('Live reply only.')})++ it('bounds to a hidden user turn too (widget intents render no bubble)', () => {+ const messages = [+ user('u1', 'old question'),+ assistant('a1', 'Previous output from last turn.'),+ { ...user('u2', 'widget intent'), hidden: true },+ assistant('a2', 'Live reply only.')+ ]++ expect(collectUnspokenTurnSpeech(messages, null)?.text).toBe('Live reply only.')+ })})describe('stripPendingClarifyProjectionForCache', () => {diff --git a/apps/desktop/src/lib/chat-messages/parts.ts b/apps/desktop/src/lib/chat-messages/parts.tsindex 64ba0e013b5..a4d6dd88033 100644--- a/apps/desktop/src/lib/chat-messages/parts.ts+++ b/apps/desktop/src/lib/chat-messages/parts.ts@@ -72,8 +72,10 @@ export interface UnspokenTurnSpeech {* If `lastSpokenId` is missing or stale (session id assigned mid-turn,* live-tail rewrite missed), do **not** fall back to index -1 — that replays* every earlier assistant turn as one speech string. Bound to the current- * turn (assistant bubbles after the last user message) instead. A slice with- * no user row (mid-turn interims only) still collects those assistants.+ * turn (assistant bubbles after the last user message) instead. Hidden user+ * rows count: a widget intent or Bot Chat kickoff is a real turn for the+ * agent even though no bubble renders. A slice with no user row (mid-turn+ * interims only) still collects those assistants.*/export function collectUnspokenTurnSpeech(messages: ChatMessage[],@@ -82,7 +84,7 @@ export function collectUnspokenTurnSpeech(let spokenIndex = lastSpokenId ? messages.findLastIndex(m => m.id === lastSpokenId) : -1if (spokenIndex < 0) {- const lastUser = messages.findLastIndex(m => m.role === 'user' && !m.hidden)+ const lastUser = messages.findLastIndex(m => m.role === 'user')if (lastUser >= 0) {spokenIndex = lastUserdiff --git a/apps/desktop/src/lib/spoken-reply.test.ts b/apps/desktop/src/lib/spoken-reply.test.tsindex bc8f1bead5b..d48a1e879b4 100644--- a/apps/desktop/src/lib/spoken-reply.test.ts+++ b/apps/desktop/src/lib/spoken-reply.test.ts@@ -98,6 +98,16 @@ describe('adoptSpokenReplySession', () => {adoptSpokenReplySession(null, 'session-created')expect(spokenReplyOf('session-created')?.id).toBe('a1')+ // Moved, not copied: the next new chat (null session again) starts clean.+ expect(spokenReplyOf(null)).toBeNull()+ })++ it('does not overwrite an anchor the created session already has', () => {+ markAssistantIdSpoken(null, [assistant('a1')], 'a1')+ markAssistantIdSpoken('session-created', [assistant('a1'), assistant('a2')], 'a2')+ adoptSpokenReplySession(null, 'session-created')++ expect(spokenReplyOf('session-created')?.id).toBe('a2')})it('does not leak a spoken anchor from one real session into another', () => {diff --git a/apps/desktop/src/lib/spoken-reply.ts b/apps/desktop/src/lib/spoken-reply.tsindex 57ca91108e6..8bf8f81e2a0 100644--- a/apps/desktop/src/lib/spoken-reply.ts+++ b/apps/desktop/src/lib/spoken-reply.ts@@ -114,7 +114,9 @@ export function markAssistantIdSpoken(/*** Carry the spoken anchor when a chat gets a real session id (null → created)* mid voice-conversation. Do not copy across two real sessions — that would- * leak "already spoken" into a different transcript.+ * leak "already spoken" into a different transcript. The null-session entry is+ * moved, not copied: left behind, it would mark the NEXT new chat's first reply+ * as already spoken.*/export function adoptSpokenReplySession(fromSessionId: string | null | undefined,@@ -129,11 +131,15 @@ export function adoptSpokenReplySession(const from = lastSpokenBySession.get(fromKey)- if (!from || lastSpokenBySession.has(toKey)) {+ if (!from) {return}- lastSpokenBySession.set(toKey, from)+ lastSpokenBySession.delete(fromKey)++ if (!lastSpokenBySession.has(toKey)) {+ lastSpokenBySession.set(toKey, from)+ }}/** Current spoken anchor, migrated in place when the live row was rewritten. */