Skip to content

The agent that grows with you

fix(desktop): integrate the unread read-state layers — focused-session clear acks persistence, mark-all/mark-read ack watermarks, new-turn baseline reset

Tekniumb44b99e62ab7
diff --git a/apps/desktop/src/app/chat/sidebar/index.tsx b/apps/desktop/src/app/chat/sidebar/index.tsx
index 4e9b257e154..3f3ae0be472 100644
--- a/apps/desktop/src/app/chat/sidebar/index.tsx
+++ b/apps/desktop/src/app/chat/sidebar/index.tsx
@@ -123,6 +123,7 @@ import {
} from '@/store/session'
import { $sessionDotStateById, sessionStatusBucket } from '@/store/session-dot-state'
import { $focusedStoredSessionId, $workingSessionIds, type SplitDir } from '@/store/session-states'
+import { ackAllSessionsRead } from '@/store/session-unread'
import { markSessionUnread } from '@/store/session-unread-remote'
import { notifyError } from '@/store/notifications'
import { $archivedSessions, loadArchivedSessions } from '@/store/sidebar-archive'
@@ -1671,6 +1672,9 @@ export function ChatSidebar({
onClick={event => {
event.stopPropagation()
markAllSessionsRead()
+ // Ack the persisted layer too, or the next list
+ // refresh repaints every dot just dismissed.
+ ackAllSessionsRead()
}}
size="icon-xs"
variant="ghost"
diff --git a/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsx b/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsx
index 031d1825742..60de5f5ca5f 100644
--- a/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsx
+++ b/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsx
@@ -16,7 +16,11 @@ vi.mock('@/components/pane-shell/tree/store', () => ({
closeTreeTabsToRight: vi.fn(),
treeTabCloseTargets: vi.fn(() => null)
}))
-vi.mock('@/hermes', () => ({ renameSession: vi.fn() }))
+vi.mock('@/hermes', () => ({
+ renameSession: vi.fn(),
+ setApiRequestProfile: vi.fn(),
+ setSessionUnreadRemote: vi.fn(() => Promise.resolve({ ok: true }))
+}))
vi.mock('@/i18n', () => ({
useI18n: () => ({
t: {
@@ -80,6 +84,8 @@ vi.mock('@/store/projects', () => ({
vi.mock('@/store/session', () => ({
$activeSessionId: atom<null | string>(null),
$connection: atom<null | { mode: string }>(null),
+ $cronSessions: atom<unknown[]>([]),
+ $messagingSessions: atom<unknown[]>([]),
$selectedStoredSessionId: atom<null | string>(null),
$sessions: atom<unknown[]>([]),
$unreadFinishedSessionIds: atom<string[]>([]),
@@ -99,6 +105,7 @@ vi.mock('@/store/session-states', () => ({
vi.mock('@/store/windows', () => ({
canOpenSessionInTerminal: () => false,
canOpenSessionWindow: () => false,
+ isSecondaryWindow: () => false,
openSessionInNewWindow: vi.fn(),
openSessionInTerminal: vi.fn()
}))
diff --git a/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsx b/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsx
index 1619113df24..b2f1392a8dc 100644
--- a/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsx
+++ b/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsx
@@ -50,6 +50,7 @@ import {
sessionPinId,
setSessions
} from '@/store/session'
+import { ackStoredSessionId } from '@/store/session-unread'
import { $sessionColorOverrides, setSessionColorOverride } from '@/store/session-color'
import { $sessionTiles } from '@/store/session-states'
import { canOpenSessionInTerminal, canOpenSessionWindow, openSessionInTerminal } from '@/store/windows'
@@ -323,8 +324,10 @@ function useSessionActions({
triggerHaptic('selection')
if (unread || isUnread) {
- // Clear the transient family dot immediately…
+ // Clear the transient family dot immediately (and ack the persisted
+ // watermark/marker so a list refresh doesn't repaint it)…
markSessionRead(sessionId)
+ ackStoredSessionId(sessionId)
// …and retire the persisted watermark when the row carries one.
if (unread) {
diff --git a/apps/desktop/src/app/chat/sidebar/virtual-session-list.test.tsx b/apps/desktop/src/app/chat/sidebar/virtual-session-list.test.tsx
index a8379884924..821d98b24a4 100644
--- a/apps/desktop/src/app/chat/sidebar/virtual-session-list.test.tsx
+++ b/apps/desktop/src/app/chat/sidebar/virtual-session-list.test.tsx
@@ -63,6 +63,7 @@ describe('VirtualSessionList', () => {
onDeleteSession={noop}
onResumeSession={noop}
onTogglePin={noop}
+ onToggleUnread={noop}
pinned={false}
rows={rows}
sortable={false}
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index d72bd101417..f39465b8fde 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -2044,7 +2044,6 @@ export const en: Translations = {
openInSplit: 'Open in split',
copyIdFailed: 'Could not copy session ID',
sessionActions: 'Session actions',
- markRead: 'Mark as read',
sessionRunning: 'Session running',
needsInput: 'Needs your input',
waitingForAnswer: 'Waiting for your answer',
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index d2f4d207bcd..12d7525962e 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -1726,7 +1726,6 @@ export interface Translations {
openInSplit: string
copyIdFailed: string
sessionActions: string
- markRead: string
sessionRunning: string
needsInput: string
waitingForAnswer: string
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index c790def088a..4a5ea169832 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -2231,7 +2231,6 @@ export const zh: Translations = {
copyIdFailed: '无法复制会话 ID',
sessionActions: '会话操作',
- markRead: '标记为已读',
sessionRunning: '会话运行中',
needsInput: '需要你输入',
waitingForAnswer: '正在等待你的回答',
diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.ts
index 15063c92ebe..de350e747b4 100644
--- a/apps/desktop/src/store/session-states.ts
+++ b/apps/desktop/src/store/session-states.ts
@@ -39,13 +39,14 @@ import {
$selectedStoredSessionId,
$sessions,
$unreadFinishedSessionIds,
+ clearReadBaseline,
lineageAliases,
markSessionRead,
sessionMatchesStoredId,
setActiveSessionStoredIdRotation,
setSessions
} from './session'
-import { markSessionUnreadFinished } from './session-unread'
+import { ackStoredSessionId, markSessionUnreadFinished } from './session-unread'
import { isSecondaryWindow } from './windows'
// ---------------------------------------------------------------------------
@@ -182,6 +183,11 @@ function handleTransition(previous: ClientSessionState | null, next: ClientSessi
if (next.busy && !wasWorking) {
clearSettled(storedId)
+ // A NEW turn is starting: the read baseline guarded the PREVIOUS
+ // completion's re-asserts. Dropping it here means this turn's finish
+ // re-lights even if it lands within the same millisecond as the last
+ // read (same-tick submit → finish in tests and fast local models).
+ clearReadBaseline(storedId)
} else if (!next.busy && wasWorking) {
markSettled(storedId)
@@ -679,8 +685,10 @@ export function openSessionTile(
// Opening a session in a tab/tile is "reading" it — clear its unread dot
// exactly like main-thread resume does. Previously only
// setSelectedStoredSessionId cleared unread, so tile-opened sessions kept
- // their green dot even while the user was reading them.
+ // their green dot even while the user was reading them. Acks the persisted
+ // watermark/marker too so a later list refresh doesn't repaint it.
markSessionRead(storedSessionId)
+ ackStoredSessionId(storedSessionId)
if (storedSessionId === $selectedStoredSessionId.get()) {
return
@@ -933,11 +941,13 @@ export const selectionHomesToWorkspace = (selected: null | string, tiles: readon
// FOCUSED session, not the selected one: a tile is never $selectedStoredSessionId,
// and a tile tab click goes through activateTreePane rather than focusOpenSession,
// so this is the one hook that catches every way a tile reaches the front.
+// Clears the whole conversation family (markSessionRead) AND acks the
+// persisted watermark/marker (ackStoredSessionId) so the next list refresh
+// doesn't repaint the dot the user just cleared by looking at it.
$focusedStoredSessionId.listen(focused => {
- const cur = $unreadFinishedSessionIds.get()
-
- if (focused && cur.includes(focused)) {
- $unreadFinishedSessionIds.set(cur.filter(id => id !== focused))
+ if (focused) {
+ markSessionRead(focused)
+ ackStoredSessionId(focused)
}
})
diff --git a/apps/desktop/src/store/session-unread.ts b/apps/desktop/src/store/session-unread.ts
index 226e2b3c640..76e29c6490b 100644
--- a/apps/desktop/src/store/session-unread.ts
+++ b/apps/desktop/src/store/session-unread.ts
@@ -282,6 +282,16 @@ export function ackStoredSessionId(storedSessionId: null | string): void {
}
}
+/** Sidebar "Mark all as read" — ack every LOADED row (watermark := its current
+ * count, markers retired) so the persisted layer doesn't repaint the dots the
+ * user just dismissed on the next list refresh. Rows not loaded keep their
+ * state: an unseen session in a collapsed profile stays honestly unread. */
+export function ackAllSessionsRead(): void {
+ for (const row of rowsFor([$sessions.get(), $cronSessions.get(), $messagingSessions.get()])) {
+ ackSessionRow(row)
+ }
+}
+
/** DELETE/ARCHIVE CLEANUP — the session is gone from the user's world, so its
* watermark and marker are dead weight. Drops every candidate id (stored id,
* live id, lineage root) from both persisted records in `profile`'s bucket
diff --git a/apps/desktop/src/store/session.ts b/apps/desktop/src/store/session.ts
index b9a43a376e9..5b06249951b 100644
--- a/apps/desktop/src/store/session.ts
+++ b/apps/desktop/src/store/session.ts
@@ -703,6 +703,18 @@ export function markAllSessionsRead() {
// already-viewed completion keeps re-lighting the row.
export const $lastReadAtBySessionId = atom<Record<string, number>>({})
+/** A new turn started for this session: the read baseline only guarded the
+ * PREVIOUS completion's re-asserts, so drop it — the new turn's finish must
+ * re-light even when it lands in the same millisecond as the last read. */
+export const clearReadBaseline = (storedSessionId: string) => {
+ const map = $lastReadAtBySessionId.get()
+
+ if (storedSessionId in map) {
+ const { [storedSessionId]: _dropped, ...rest } = map
+ $lastReadAtBySessionId.set(rest)
+ }
+}
+
export const setSelectedStoredSessionId = (next: Updater<string | null>) => {
updateAtom($selectedStoredSessionId, next)
// Opening a session clears its unread state — the user is now looking at it.