Skip to content

The agent that grows with you

fix(desktop): address transcript refresh review feedback

Guilherme Aguiar01e542b76444
diff --git a/apps/desktop/src/app/contrib/hooks/use-background-sync.test.ts b/apps/desktop/src/app/contrib/hooks/use-background-sync.test.ts
index b4d5b6e6c25..4cb9f0bbc7a 100644
--- a/apps/desktop/src/app/contrib/hooks/use-background-sync.test.ts
+++ b/apps/desktop/src/app/contrib/hooks/use-background-sync.test.ts
@@ -205,7 +205,7 @@ describe('active transcript refresh', () => {
await waitFor(() => expect(refresh).toHaveBeenCalledTimes(1))
})
- it('coalesces a burst of global ticks, including writes for another session', async () => {
+ it('coalesces a burst of global session-change ticks', async () => {
vi.useFakeTimers()
$changeEventsAvailable.set(true)
const refresh = vi.fn(async () => undefined)
@@ -220,7 +220,7 @@ describe('active transcript refresh', () => {
expect(refresh).toHaveBeenCalledTimes(1)
await act(async () => {
- vi.advanceTimersByTime(10_000)
+ vi.advanceTimersByTime(9_999)
await Promise.resolve()
})
diff --git a/apps/desktop/src/app/contrib/hooks/use-background-sync.ts b/apps/desktop/src/app/contrib/hooks/use-background-sync.ts
index 793d5da2b8f..2105bb050c9 100644
--- a/apps/desktop/src/app/contrib/hooks/use-background-sync.ts
+++ b/apps/desktop/src/app/contrib/hooks/use-background-sync.ts
@@ -363,18 +363,24 @@ export function useBackgroundSync({
activeTranscriptRefreshPendingRef.current = null
}
+ let sawBusyDuringRead = false
+
+ const unsubscribeBusy = $busy.listen(busy => {
+ sawBusyDuringRead ||= busy
+ })
+
void Promise.resolve(refreshActiveTranscript()).finally(() => {
+ unsubscribeBusy()
+
// If streaming began while the read was in flight, reconciliation was
// discarded and the external event still needs one idle retry.
if (
preservePending &&
- $busy.get() &&
+ (sawBusyDuringRead || $busy.get()) &&
$activeSessionId.get() === runtimeSessionId &&
$selectedStoredSessionId.get() === storedSessionId
) {
activeTranscriptRefreshPendingRef.current = sessionKey
-
- return
}
})
},