Skip to content

The agent that grows with you

refactor(desktop): the messaging-completion check lives with the unread store

yoniebans34dae5d0c534
diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.ts
index 979f9149331..016ae32c712 100644
--- a/apps/desktop/src/store/session-states.ts
+++ b/apps/desktop/src/store/session-states.ts
@@ -34,7 +34,6 @@ import {
import { resolveRememberedActivePane, workspaceScopeKey } from '@/components/pane-shell/workspace-scope'
import type { WorkspaceMode } from '@/contrib/types'
import { finalizeInterruptedMessages, sealOpenToolParts } from '@/lib/chat-messages'
-import { isMessagingSource } from '@/lib/session-source'
import { tileFocusStampOnFocusChange } from '@/lib/session-timer-since'
import { stableArray } from '@/lib/stable-array'
import { readJson, writeJson } from '@/lib/storage'
@@ -94,7 +93,7 @@ import {
type SessionOwnerScope,
type SessionProfileRoute
} from './session-request-router'
-import { ackStoredSessionId, markSessionUnreadFinished } from './session-unread'
+import { ackStoredSessionId, isMessagingCompletion, markSessionUnreadFinished } from './session-unread'
import { migrateTranscriptTailsForProfile } from './transcript-tail-cache'
import { isBrowserWindow, isSecondaryWindow } from './windows'
@@ -764,19 +763,9 @@ function handleTransition(previous: ClientSessionState | null, next: ClientSessi
/** Mark a completed turn unread unless the user is already looking at it. */
function lightUnreadCompletion(storedId: string, runtimeId?: string) {
- const messagingRow = [...$sessions.get(), ...$cronSessions.get(), ...$messagingSessions.get()].find(session =>
- sessionMatchesStoredId(session, storedId)
- )
-
- // Messaging conversations deliver their own completion to their originating
- // platform. A Desktop observer is not an unread recipient of that delivery.
- if (isMessagingSource(messagingRow?.source)) {
- return
- }
-
// FOCUSED, not selected: a session finishing in the tile the user is
// watching is already seen, and a tile is never the primary selection.
- if (storedId === $focusedStoredSessionId.get()) {
+ if (storedId === $focusedStoredSessionId.get() || isMessagingCompletion(storedId)) {
return
}
diff --git a/apps/desktop/src/store/session-unread.ts b/apps/desktop/src/store/session-unread.ts
index de0f7ed6049..e5bd95125e7 100644
--- a/apps/desktop/src/store/session-unread.ts
+++ b/apps/desktop/src/store/session-unread.ts
@@ -1,4 +1,5 @@
import { Codecs, persistentAtom } from '@/lib/persisted'
+import { isMessagingSource } from '@/lib/session-source'
import { stableArray } from '@/lib/stable-array'
import { readKey } from '@/lib/storage'
import { $activeGatewayProfile, normalizeProfileKey } from '@/store/profile'
@@ -205,6 +206,12 @@ function setMarkerBucket(profile: string, ids: readonly string[]): void {
$unreadFinishedMarkers.set(next)
}
+/** A messaging conversation delivers its completion to its own platform; a
+ * Desktop observer is not an unread recipient of it. */
+export function isMessagingCompletion(storedSessionId: string): boolean {
+ return isMessagingSource(resolveLoadedRow(storedSessionId)?.source)
+}
+
/** UNREAD WRITER — the live busy→idle edge (session-states.ts) and any surface
* that learns out-of-band that a session produced something the user hasn't
* seen. Flags the transient atom (immediate paint) AND persists the marker so