The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): let Quick Entry submit after its own stale residue
JoaoMarcos44345483b8c006
diff --git a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.ts b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.tsindex e3afc51bcd7..e037ff8a551 100644--- a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.ts+++ b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.test.ts@@ -763,6 +763,52 @@ describe('useSessionTileDelegate stale multi-window guard (#65047)', () => {expect($notifications.get().some(note => note.kind === 'warning')).toBe(true)})+ it('grafts same-window residue and still submits the Quick Entry prompt', async () => {+ setSessions([row({ id: storedId, profile: 'work-vps' })])+ vi.mocked(getLatestSessionMessages).mockResolvedValue({+ session_id: storedId,+ messages: [+ { content: 'a', id: 1, role: 'user', timestamp: 1 },+ { content: 'server-side turn residue', id: 2, role: 'assistant', timestamp: 2 }+ ]+ })++ const stale = createClientSessionState(storedId, [+ { id: 'u1', role: 'user', rowId: 1, parts: [textPart('a')] }+ ])++ const sessionStateByRuntimeIdRef = { current: new Map([[runtimeId, stale]]) }+ const runtimeIdByStoredSessionIdRef = { current: new Map([[storedId, runtimeId]]) }+ const seeds: unknown[] = []+ const requestGateway = vi.fn(async () => ({}) as never)++ renderTile(requestGateway, {+ runtimeIdByStoredSessionIdRef,+ sessionStateByRuntimeIdRef,+ updateSessionState: vi.fn((id, updater, stored) => {+ const prev = sessionStateByRuntimeIdRef.current.get(id) ?? createClientSessionState(stored)+ const next = updater(prev)+ sessionStateByRuntimeIdRef.current.set(id, next)+ seeds.push(next)++ return next+ })+ })++ await sessionTileDelegate()!.submitToSession(runtimeId, 'follow up')++ expect(requestGatewayForProfile).toHaveBeenCalledWith(+ 'work-vps',+ 'prompt.submit',+ { session_id: runtimeId, text: 'follow up' },+ 1_800_000,+ undefined+ )+ expect(seeds.at(-1)).toEqual(expect.objectContaining({ messages: expect.any(Array) }))+ expect((seeds.at(-1) as { messages: unknown[] }).messages).toHaveLength(2)+ expect($notifications.get().some(note => note.kind === 'warning')).toBe(false)+ })+it('allows submitToSession when the authoritative transcript is not ahead', async () => {setSessions([row({ id: storedId, profile: 'work-vps' })])vi.mocked(getLatestSessionMessages).mockResolvedValue({diff --git a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.tsindex 063f065ec42..335ff3095ec 100644--- a/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts+++ b/apps/desktop/src/app/contrib/hooks/use-session-tile-delegate.ts@@ -14,7 +14,7 @@ import {import { translateNow } from '@/i18n/runtime'import { type ChatMessage, chatMessageText, toChatMessages } from '@/lib/chat-messages'import { markReasoningEffortPending } from '@/lib/chat-runtime'-import { profileScopeForSessionOwner, refreshIfTranscriptStale } from '@/lib/stale-transcript-guard'+import { profileScopeForSessionOwner, transcriptRefreshIfBehind } from '@/lib/stale-transcript-guard'import { noteMessageSent } from '@/store/desktop-metrics'import { notify } from '@/store/notifications'import {@@ -508,18 +508,20 @@ export function useSessionTileDelegate({const cached = sessionStateByRuntimeIdRef.current.get(runtimeId)const owner = await ownerForStoredSession(storedSessionId)- const refreshed = await refreshIfTranscriptStale(storedSessionId, cached?.messages ?? [], {+ const refresh = await transcriptRefreshIfBehind(storedSessionId, cached?.messages ?? [], {profile: profileScopeForSessionOwner(owner)})- if (refreshed) {+ // Only a competing view's surplus refuses the send; this window's own+ // server-side turn residue is grafted and the prompt proceeds (#130031).+ if (refresh?.competingView) {updateSessionState(runtimeId,state => ({...state,awaitingResponse: false,busy: false,- messages: refreshed,+ messages: refresh.messages,pendingBranchGroup: null}),storedSessionId@@ -537,6 +539,10 @@ export function useSessionTileDelegate({// so callers never report delivery for this refusal.return { runtimeSessionId: runtimeId, storedSessionId: null }}++ if (refresh) {+ updateSessionState(runtimeId, state => ({ ...state, messages: refresh.messages }), storedSessionId)+ }}const routedRequest = storedSessionId