fix(activity): keep live agents visible when showing unread only

A running agent's thread is read unless it carries an older unread event, so the
unread-only filter hid agents that were working again. Exempt live threads
(currentAgentState non-null) alongside the selected-row exemption.
This commit is contained in:
Jinjing
2026-11-08 15:04:10 -08:00
parent cc7d19e932
commit 4e4c2c1956
2 changed files with 13 additions and 3 deletions
@@ -68,16 +68,25 @@ function options(query: string): Parameters<typeof useAgentPaneThreads>[0] {
}
describe('Activity search query in the real hook', () => {
it('excludes acknowledged rows from an unread search', () => {
it('keeps live rows but excludes acknowledged finished rows from an unread search', () => {
const panes = installThreads(12)
const entries = useAppStore.getState().agentStatusByPaneKey
useAppStore.setState({
agentStatusByPaneKey: Object.fromEntries(
panes.map((paneKey, index) => [
paneKey,
index === 0 ? entries[paneKey] : { ...entries[paneKey], state: 'done' as const }
])
),
acknowledgedAgentsByPaneKey: Object.fromEntries(panes.map((paneKey) => [paneKey, 100_000]))
})
const activity = renderHook(() =>
useAgentPaneThreads({ ...options(' PROJECT ☃ '), readFilter: 'unread' })
)
expect(activity.result.current.allThreads).toHaveLength(12)
expect(activity.result.current.visibleThreads).toEqual([])
expect(activity.result.current.visibleThreads.map((thread) => thread.paneKey)).toEqual([
panes[0]
])
})
it('keeps selection, child classification and scoped row order', () => {
@@ -221,10 +221,11 @@ export function useAgentPaneThreads(args: {
const matchesSearchQuery =
normalizedQuery === null ? null : createActivityThreadSearchMatcher(normalizedQuery)
return scopeVisibleThreads.filter((thread) => {
// Why: keep the just-selected thread visible after auto-mark-read flips it to read, else unread-only mode makes the clicked row vanish from the list.
// Why: unread-only must not hide live agents (a read agent can be running again) or the just-selected row that auto-mark-read flipped to read.
if (
readFilter === 'unread' &&
!thread.unread &&
thread.currentAgentState === null &&
thread.paneKey !== effectiveSelectedPaneKey
) {
return false