Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(ui): stack unread sessions first in the Inbox hover popover (#2097)
Call Whitedf48df0cc084
diff --git a/ui/src/components/workbench/InboxHoverPopover.test.tsx b/ui/src/components/workbench/InboxHoverPopover.test.tsxnew file mode 100644index 000000000..2f19e1bb7--- /dev/null+++ b/ui/src/components/workbench/InboxHoverPopover.test.tsx@@ -0,0 +1,123 @@+/* @vitest-environment jsdom */++import { cleanup, fireEvent, render, screen } from '@testing-library/react';+import { afterEach, expect, it, vi } from 'vitest';+import { MemoryRouter, Route, Routes } from 'react-router-dom';+import { Popover } from '../ui/popover';+import type { InboxSession } from '../../context/ApiContext';+import { readInboxFilter } from '../../lib/inboxFilterMemory';+import { InboxHoverPopover } from './WorkbenchSidebar';++vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));+vi.mock('../ui/markdown', () => ({ Markdown: ({ content }: { content: string }) => <p>{content}</p> }));++// Newest first, the order the feed hands the popover.+const row = (id: number, minutesAgo: number): InboxSession => ({+ session_id: `session-${id}`, title: `Session ${id}`, scope_id: null,+ project_id: null, project_name: null,+ last_activity_at: new Date(Date.UTC(2026, 8, 21, 12, 0) - minutesAgo * 60_000).toISOString(),+ last_message_author: 'agent', replied: false, preview_text: `Preview ${id}`,+ preview_at: null, unread_count: 0, unread: false,+});++// `unreadSessions` counts the whole feed, so it is passed separately: the cases+// this popover has to get right are the ones where it exceeds what `sessions` holds.+function mount(+ sessions: InboxSession[],+ unreadBySession: Record<string, number>,+ unreadSessions = Object.keys(unreadBySession).length,+) {+ const peek = (+ <Popover open>+ <InboxHoverPopover+ sessions={sessions}+ unreadBySession={unreadBySession}+ unreadSessions={unreadSessions}+ totalUnread={Object.values(unreadBySession).reduce((sum, n) => sum + n, 0)}+ canMarkRead+ onItemClick={() => {}}+ onMarkAllRead={() => {}}+ onMouseEnter={() => {}}+ onMouseLeave={() => {}}+ />+ </Popover>+ );+ render(+ <MemoryRouter initialEntries={['/']}>+ <Routes>+ {/* Stands in for the full Inbox page, so a link out of the peek is+ observable as the navigation it is meant to be. */}+ <Route path="/inbox" element={<p>Full inbox</p>} />+ <Route path="*" element={peek} />+ </Routes>+ </MemoryRouter>,+ );+ return screen+ .getAllByRole('button')+ .map((node) => node.textContent ?? '')+ .filter((text) => text.includes('Session '))+ .map((text) => text.match(/Session \d+/)?.[0] ?? '');+}++afterEach(() => {+ cleanup();+ window.localStorage.clear();+});++it('stacks unread sessions above read ones', () => {+ const sessions = [0, 1, 2, 3].map((id) => row(id, id * 10));+ expect(mount(sessions, { 'session-2': 1, 'session-3': 4 })).toEqual([+ 'Session 2', 'Session 3', 'Session 0', 'Session 1',+ ]);+});++it('keeps the feed order inside each group', () => {+ const sessions = [0, 1, 2, 3].map((id) => row(id, id * 10));+ expect(mount(sessions, { 'session-0': 1, 'session-3': 1 })).toEqual([+ 'Session 0', 'Session 3', 'Session 1', 'Session 2',+ ]);+});++it('shows an unread session the chronological five would have buried', () => {+ // Five read sessions are newer than the only unread one, so a plain slice of+ // the feed's first five never reaches it — which is the case the popover exists+ // to serve.+ const sessions = [0, 1, 2, 3, 4, 5].map((id) => row(id, id * 10));+ const shown = mount(sessions, { 'session-5': 2 });+ expect(shown).toHaveLength(5);+ expect(shown[0]).toBe('Session 5');+});++it('leaves the order alone when nothing is unread', () => {+ const sessions = [0, 1, 2].map((id) => row(id, id * 10));+ expect(mount(sessions, {})).toEqual(['Session 0', 'Session 1', 'Session 2']);+});++it('says so when an unread session sits outside the loaded pages', () => {+ // Five read rows loaded and three unread sessions counted feed-wide: two of the+ // three are older than the loaded window, so no ordering of these rows reaches+ // them and a header reading "3 unread" would otherwise sit above five read rows.+ const sessions = [0, 1, 2, 3, 4].map((id) => row(id, id * 10));+ mount(sessions, { 'session-4': 1 }, 3);+ const notice = screen.getByRole('button', { name: 'workbench.inbox.moreUnreadInFull' });+ fireEvent.click(notice);+ expect(screen.getByText('Full inbox')).toBeTruthy();+ // The full inbox resolves its tab from this store on entry, so the click has to+ // land the user on Unread rather than whichever tab they last left behind.+ expect(readInboxFilter()).toEqual({ tab: 'unread', leftAt: 0 });+});++it('stays quiet when the loaded rows already hold every unread session', () => {+ const sessions = [0, 1, 2].map((id) => row(id, id * 10));+ mount(sessions, { 'session-1': 1, 'session-2': 5 });+ expect(screen.queryByText('workbench.inbox.moreUnreadInFull')).toBeNull();+});++it('stays quiet when the peek is already full of unread sessions', () => {+ // Nothing is being hidden by the row limit that the header count does not+ // already state, so the notice would be noise on the common triage case.+ const sessions = [0, 1, 2, 3, 4, 5, 6].map((id) => row(id, id * 10));+ const unread = Object.fromEntries(sessions.map((s) => [s.session_id, 1]));+ expect(mount(sessions, unread)).toHaveLength(5);+ expect(screen.queryByText('workbench.inbox.moreUnreadInFull')).toBeNull();+});diff --git a/ui/src/components/workbench/InboxPage.tsx b/ui/src/components/workbench/InboxPage.tsxindex b0e323e40..ffac824a7 100644--- a/ui/src/components/workbench/InboxPage.tsx+++ b/ui/src/components/workbench/InboxPage.tsx@@ -51,6 +51,21 @@ export const InboxPage: React.FC<{ onOpenSearch: () => void }> = ({ onOpenSearchwriteInboxFilter(next, readInboxFilter().leftAt);}, []);+ // Entering /inbox while this page is already mounted — the user is on the inbox+ // and something navigates to it again — keeps the same element, so the resolve+ // in the initializer above never runs a second time and the tab would simply+ // not move. Re-entry has to mean what entry means, so redo exactly what mount+ // does: resolve from the store, and align the store with what is now shown.+ // Keyed on location.key, which changes once per navigation and not on renders.+ const entryKeyRef = useRef(location.key);+ useEffect(() => {+ if (entryKeyRef.current === location.key) return;+ entryKeyRef.current = location.key;+ const resumed = resolveInboxFilter(readInboxFilter(), Date.now());+ setFilterState(resumed);+ writeInboxFilter(resumed, 0);+ }, [location.key]);+// Stamp when the user leaves the inbox (route change → unmount, app/tab// backgrounded, reload/close) so the next entry can measure the absence. If// they background the page itself for a long time, revert to Unread on return.diff --git a/ui/src/components/workbench/InboxPageFilterEntry.test.tsx b/ui/src/components/workbench/InboxPageFilterEntry.test.tsxnew file mode 100644index 000000000..3e5fb9fb2--- /dev/null+++ b/ui/src/components/workbench/InboxPageFilterEntry.test.tsx@@ -0,0 +1,77 @@+/* @vitest-environment jsdom */++import { cleanup, fireEvent, render, screen } from '@testing-library/react';+import { afterEach, expect, it, vi } from 'vitest';+import { MemoryRouter, Route, Routes, useNavigate } from 'react-router-dom';+import type { InboxSession } from '../../context/ApiContext';+import { writeInboxFilter } from '../../lib/inboxFilterMemory';+import { InboxPage } from './InboxPage';++const feed = vi.hoisted(() => ({+ inboxSessions: [] as InboxSession[],+ unreadBySession: {} as Record<string, number>,+ loading: false,+ nextCursor: null as string | null,+ refresh: vi.fn(),+ loadMore: vi.fn(),+ markRead: vi.fn(),+}));+vi.mock('../../context/WorkbenchInboxContext', () => ({+ useWorkbenchInbox: () => ({+ ...feed,+ totalUnread: Object.values(feed.unreadBySession).reduce((sum, n) => sum + n, 0),+ unreadSessions: Object.keys(feed.unreadBySession).length,+ loadingMore: false,+ }),+}));+vi.mock('../../context/InstanceAuthorizationContext', () => ({+ useInstanceAuthorization: () => ({ capabilities: { can_chat: true, can_read_instance: false } }),+}));+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));+vi.mock('../ui/markdown', () => ({ Markdown: ({ content }: { content: string }) => <p>{content}</p> }));++const row = (id: number): InboxSession => ({+ session_id: `session-${id}`, title: `Session ${id}`, scope_id: null,+ project_id: null, project_name: null, last_activity_at: '2026-09-21T12:00:00Z',+ last_message_author: 'agent', replied: false, preview_text: `Reply ${id}`,+ preview_at: null, unread_count: 0, unread: false,+});++// Stands in for any caller that records the tab it wants and then navigates to+// /inbox — the sidebar peek's "unread is outside this preview" link does exactly+// this. Rendered beside the page so the navigation lands on the route the page+// is already mounted on, which is the case a fresh mount never exercises.+function ReEnter() {+ const navigate = useNavigate();+ return <button onClick={() => { writeInboxFilter('unread', 0); navigate('/inbox'); }}>Re-enter</button>;+}++const visibleRows = () => document.querySelectorAll('[data-inbox-session-id]').length;++function mount() {+ render(+ <MemoryRouter initialEntries={['/inbox']}>+ <Routes>+ <Route path="/inbox" element={<><InboxPage onOpenSearch={() => {}} /><ReEnter /></>} />+ </Routes>+ </MemoryRouter>,+ );+}++afterEach(() => {+ cleanup();+ window.localStorage.clear();+});++it('honours a tab recorded just before navigating to the inbox it is already on', () => {+ feed.inboxSessions = [0, 1, 2].map(row);+ feed.unreadBySession = { 'session-1': 1 };+ writeInboxFilter('all', 0);+ mount();+ expect(visibleRows()).toBe(3);++ fireEvent.click(screen.getByText('Re-enter'));+ // Same route, so React Router keeps this page mounted and the mount-time+ // resolve never runs again. Re-entering still has to mean what entering means.+ expect(visibleRows()).toBe(1);+});diff --git a/ui/src/components/workbench/WorkbenchSidebar.tsx b/ui/src/components/workbench/WorkbenchSidebar.tsxindex 4d25cabd4..71ad43ab2 100644--- a/ui/src/components/workbench/WorkbenchSidebar.tsx+++ b/ui/src/components/workbench/WorkbenchSidebar.tsx@@ -27,6 +27,7 @@ import {import clsx from 'clsx';import type { LucideIcon } from 'lucide-react';+import { writeInboxFilter } from '../../lib/inboxFilterMemory';import { useRouteSurfaceActive } from '../../lib/routeSurfaceActivity';import { useLatestRef } from '../../lib/useLatestRef';@@ -105,6 +106,10 @@ const SidebarNavRow: React.FC<{</NavLink>);+// How many session rows the peek holds. Named because two things depend on it:+// which rows are picked, and whether the peek had room it could not fill.+const PEEK_ROWS = 5;+// 360px floating popover that opens when the user hovers the Inbox entry.// Mirrors design.pen KmQ1L — header + a few session cards + footer "open full// inbox" link. Pure presentational; data comes from <WorkbenchInboxProvider>.@@ -131,10 +136,43 @@ const InboxHoverPopover: React.FC<{}) => {const { t } = useTranslation();const navigate = useNavigate();- const shown = sessions.slice(0, 5);// The unread map is authoritative; a session absent from it has 0 unread// (don't fall back to the card's stale unread_count — see InboxPage).const unreadOf = (s: InboxSession) => unreadBySession[s.session_id] ?? 0;+ // Unread first, then the rest. `sort` is stable, so within each group the feed+ // keeps the backend's activity order untouched.+ //+ // This decides *which* five appear, not only how they are stacked — and that is+ // the point. The popover is a five-row peek at a feed that is usually longer, so+ // a strictly chronological slice hides the unread session the user opened it to+ // act on behind ones they have already read. The full Inbox page keeps the+ // chronological order on purpose: it has unread/all tabs and keyset pagination,+ // which a client-side reorder would fight.+ const shown = useMemo(+ () =>+ [...sessions]+ .sort(+ (a, b) =>+ Number((unreadBySession[b.session_id] ?? 0) > 0) -+ Number((unreadBySession[a.session_id] ?? 0) > 0),+ )+ .slice(0, PEEK_ROWS),+ [sessions, unreadBySession],+ );+ // `unreadSessions` counts the whole feed; `sessions` holds only the pages the+ // provider has loaded, so an unread session older than the loaded window is in+ // the count but not in the rows, and no ordering of those rows can surface it.+ // Say so rather than letting a header that reads "3 unread" sit above five read+ // rows. The condition is deliberately "the peek had room and could not fill it":+ // a peek already full of unread is hiding nothing the header does not state.+ const unreadShown = shown.filter((s) => unreadOf(s) > 0).length;+ const unreadBeyondPeek = unreadShown < PEEK_ROWS && unreadSessions > unreadShown;+ const openFullInbox = (filter?: 'unread') => {+ // The Inbox page resolves its tab from this store on entry, so writing it+ // first is how a caller asks for a tab without a new route or prop.+ if (filter) writeInboxFilter(filter, 0);+ navigate('/inbox');+ };return (// Portaled (PopoverContent) so it escapes the sidebar's stacking context and// floats above the chat panel — a plain `absolute z-50` div was painted under@@ -224,9 +262,19 @@ const InboxHoverPopover: React.FC<{</div>)}+ {unreadBeyondPeek && (+ <button+ type="button"+ onClick={() => openFullInbox('unread')}+ className="rounded-lg border border-dashed border-border px-3 py-2 text-left text-[11px] leading-relaxed text-muted transition hover:bg-foreground/[0.04] hover:text-foreground"+ >+ {t('workbench.inbox.moreUnreadInFull')}+ </button>+ )}+<buttontype="button"- onClick={() => navigate('/inbox')}+ onClick={() => openFullInbox()}className="flex items-center justify-center gap-1.5 rounded-md pt-1 text-[11px] font-medium text-cyan-ink hover:underline">{t('workbench.inbox.viewAll')}diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.jsonindex 28c2d408a..0a9c11d7e 100644--- a/ui/src/i18n/en.json+++ b/ui/src/i18n/en.json@@ -2654,6 +2654,7 @@"replied": "Replied","loadMore": "Load more","moreUnreadBeyond": "More unread sessions may be further down — load more to see them.",+ "moreUnreadInFull": "Some unread sessions aren't in this preview — open the full inbox.","notifications": {"checking": "Checking notifications","unsupported": "Notifications unavailable",diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.jsonindex b6f8f7a47..d6a20676b 100644--- a/ui/src/i18n/zh.json+++ b/ui/src/i18n/zh.json@@ -2654,6 +2654,7 @@"replied": "已回复","loadMore": "加载更多","moreUnreadBeyond": "还有未读会话在后面的分页里,点击「加载更多」查看。",+ "moreUnreadInFull": "有未读会话不在这个预览里,打开完整收件箱查看。","notifications": {"checking": "正在检查通知","unsupported": "当前不支持通知",