The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep responsePreviewed settle gated on the boundary flag
spfcraze9cc428cff814
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/index.ts b/apps/desktop/src/app/session/hooks/use-message-stream/index.tsindex 90a6fcad9a8..01cf8df499a 100644--- a/apps/desktop/src/app/session/hooks/use-message-stream/index.ts+++ b/apps/desktop/src/app/session/hooks/use-message-stream/index.ts@@ -632,25 +632,29 @@ export function useMessageStream({nextMessages = prev.map((message, messageIndex) =>messageIndex === index ? completeMessage(message) : message)- } else if (existing.interim && (responsePreviewed || finalContinuesInterim)) {+ } else if ((interimBoundaryPending && responsePreviewed) || finalContinuesInterim) {// Settle the interim in place instead of creating a duplicate —- // the DB has one row, so the live UI must agree. Previously this- // was gated on `responsePreviewed` alone, so a NON-previewed- // tool-call turn whose final matched its sealed interim appended a- // second bubble (the "renders twice: partial first copy + clean- // final" bug, #63679). `finalContinuesInterim` closes that gap- // for ordinary tool-call turns while `responsePreviewed` still- // covers the verify-on-stop continuation-budget case even when the- // final text was rewritten and no longer shares a prefix.+ // the DB has one row, so the live UI must agree. Two distinct+ // settle paths with different boundary requirements://- // We key on the message's OWN durable `interim` state, not the- // session's volatile `interimBoundaryPending` flag: the flag is- // reset to false by a subsequent `message.start` (a chained turn,- // follow-up, or mid-turn compaction). When that reset lands- // between this turn's `message.interim` and `message.complete`, the- // flag-based gate wrongly fell through to appending a duplicate- // bubble (#74560). The message row still says `interim`, so the- // continuation merges correctly regardless of the flag.+ // • responsePreviewed covers the verify-on-stop continuation-+ // budget case, where the final may be a rewrite sharing no+ // prefix with the interim. Because there is no continuity+ // guarantee, it must stay gated on the session's+ // `interimBoundaryPending` flag: after a new `message.start`+ // resets the flag, a previewed final is a DISTINCT reply and+ // must append its own bubble, never overwrite the interim+ // (otherwise interim('old') → message.start →+ // complete({response_previewed: true, text: 'new'}) would+ // silently destroy 'old').+ //+ // • finalContinuesInterim (prefix-either-way continuity, same+ // text or one a prefix of the other) is safe to settle+ // flag-free: continuity can only hold for the SAME message,+ // so a `message.start` reset landing between this turn's+ // `message.interim` and `message.complete` must not force an+ // append of a duplicate bubble (#74560). This also closes the+ // non-previewed tool-call gap from #63679.nextMessages = prev.map((message, messageIndex) =>messageIndex === index ? completeMessage(message) : message)diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/interim-sealing.test.tsx b/apps/desktop/src/app/session/hooks/use-message-stream/interim-sealing.test.tsxindex 90ac198a98c..0aa549ec50f 100644--- a/apps/desktop/src/app/session/hooks/use-message-stream/interim-sealing.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-message-stream/interim-sealing.test.tsx@@ -234,6 +234,26 @@ describe('useMessageStream interim text sealing', () => {expect(texts[0]).toBe('partial answer continued')})+ it('appends a distinct previewed final after a message.start reset instead of overwriting the interim', async () => {+ await mountStream()+ await start()+ await interim('old interim text')+ // A genuinely new turn begins — message.start resets interimBoundaryPending.+ // Production ordering: mid-turn compaction-resume events do NOT include+ // message.start (COMPACTION_RESUME_EVENT_TYPES in gateway-event.ts), and+ // the TUI gateway emits message.complete BEFORE goal-followup starts+ // (tui_gateway/server.py), so a previewed final arriving after the reset+ // is a DISTINCT reply, not a rewrite of the interim. It must append its+ // own bubble — never overwrite the old one (sweeper review on #76583).+ await start()+ await completePreviewed('totally new answer')++ const texts = assistantMessages()+ expect(texts).toContain('old interim text')+ expect(texts).toContain('totally new answer')+ expect(texts).toHaveLength(2)+ })+it('appends a genuinely different final as its own bubble (two real assistant segments)', async () => {await mountStream()await start()