#5421 · Visibility-only read tracking acknowledges unattended attention
Verdict: REPRODUCED · Root-cause confidence: high
1. TL;DR
A thread can lose its unread attention even though nobody has interacted with the app. The shared read-tracking hook treats document visibility as sufficient evidence that the user saw new attention. In an independently authored reproduction, the real app mutation sends a read request both when the visible document lacks focus and when it has focus but receives no input. The hidden-document control correctly avoids the request. Existing push-sender tests and its flush logic establish that a read timestamp covering the event prevents notification delivery; native desktop/mobile behavior and actual device delivery were not exercised.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| New attention is acknowledged while a visible app lacks focus. | Verified | Fresh initially-read thread; attention advances from 100 to 200; hasFocus returns false. The real app mutation calls the SDK once. Repeated in clean checkout B. |
| Focus without any user input also acknowledges attention. | Verified | The second parameterized scenario receives no key, pointer, wheel, touch, focus, or visibility event. One SDK read request is still sent in both runs. No idle timeout exists in the production path. |
| The read can suppress a pending push. | Verified at sender boundary | The sender refetches read state at flush, comparing lastReadAt with both latestAttentionAt and eventAt. Its existing test updates a queued event's thread to read before coalescing; mobile requests and client signals remain empty. Seven sender tests pass in each checkout. |
| Maximized split panes can leave hidden read trackers mounted. | Static support; UI execution unverified | SplitTree hides the mounted pane and disables only its timeline. ThreadDetailView's read-tracking invocation is unconditional. No live pane reproduction was run. |
| Specific macOS/Electron covering behavior, phone focus semantics, historical 50–300 ms timings, or counts from personal threads. | Unverified | Only Linux/jsdom and repository-owned sender tests were available; no reporter runtime or private thread data was accessed. |
| A fixed approximately ten-second presence window is the correct solution. | Product choice, not evidence | The reproduction establishes missing presence gates, not an appropriate timeout, pane policy, or native/mobile fallback. |
3. Environment
- Trusted source: public get-bb/bb, freshly fetched origin/main at
e9dafb6c0245a37c6972dffa71134d546f3d497e. Re-fetch before publication found no newer main commit. - Linux 4.19.0-gvisor; Node v22.19.0; pnpm 9.15.0; Vitest v4.1.1; app's existing isolated jsdom project.
- Two separate checkouts at the same commit, each with its own frozen dependency installation. A full Turbo build passed in A: 65/65 tasks. The app/upstream build passed in B: 4/4 tasks.
- No running app, real provider, enrolled machine, database, device, network push relay, ports, or runtime data directory was used. Only the SDK transport is mocked; the hook, read mutation, query client, and app transaction path are real.
- This is a behavioral side-effect bug, not a visual reproduction; no screenshots are claimed.
4. Minimal reproduction
- Prepare the trusted base:
git clone https://github.com/get-bb/bb.git bb-5421 cd bb-5421 git fetch origin main git checkout --detach e9dafb6c0245a37c6972dffa71134d546f3d497e pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build
- Create
apps/app/src/hooks/useThreadReadTracking.attention-repro.test.tsxwith the complete independently authored test below. It starts with an already-read thread, so neither visible case fails because an old unread thread was opened. Advancing attention, not an interaction, is the only subsequent stimulus.// @vitest-environment jsdom import { act, cleanup, renderHook } from "@testing-library/react"; import { afterEach, expect, it, vi } from "vitest"; import { makeThreadWithRuntime } from "@bb/test-helpers/domain-fixtures"; import { sdk } from "@/lib/sdk"; import { makeThreadResponse } from "@/test/fixtures/thread-responses"; import { createQueryClientTestHarness } from "@/test/queryClientTestHarness"; import { useMarkThreadRead } from "./mutations/thread-state-mutations"; import { threadQueryKey } from "./queries/query-keys"; import { useThreadReadTracking } from "./useThreadReadTracking"; vi.mock("@/lib/sdk", () => ({ sdk: { threads: { markRead: vi.fn() } }, })); const originalVisibility = Object.getOwnPropertyDescriptor( document, "visibilityState", ); afterEach(() => { cleanup(); vi.restoreAllMocks(); vi.resetAllMocks(); if (originalVisibility) { Object.defineProperty(document, "visibilityState", originalVisibility); } else { Reflect.deleteProperty(document, "visibilityState"); } }); it.each([ { scenario: "visible without window focus", visible: true, focused: false }, { scenario: "visible and focused without input", visible: true, focused: true, }, { scenario: "hidden without focus (control)", visible: false, focused: false, }, ])( "preserves new unread attention when $scenario", async ({ visible, focused }) => { Object.defineProperty(document, "visibilityState", { configurable: true, value: visible ? "visible" : "hidden", }); vi.spyOn(document, "hasFocus").mockReturnValue(focused); const threadId = "thr_attention_reproduction"; const harness = createQueryClientTestHarness(); harness.queryClient.setQueryData( threadQueryKey(threadId), makeThreadWithRuntime({ id: threadId, lastReadAt: 100, latestAttentionAt: 100, }), ); vi.mocked(sdk.threads.markRead).mockResolvedValue( makeThreadResponse({ id: threadId, lastReadAt: 200, latestAttentionAt: 200, }), ); const { rerender } = renderHook( ({ attentionAt }) => { useThreadReadTracking({ markThreadRead: useMarkThreadRead(), thread: { id: threadId, lastReadAt: 100, latestAttentionAt: attentionAt, }, }); }, { initialProps: { attentionAt: 100 }, wrapper: harness.wrapper }, ); expect(sdk.threads.markRead).not.toHaveBeenCalled(); await act(async () => { rerender({ attentionAt: 200 }); }); expect(sdk.threads.markRead).not.toHaveBeenCalled(); }, ); - Run the reproduction through the normal app test task:
pnpm exec turbo run test --filter=@bb/app -- src/hooks/useThreadReadTracking.attention-repro.test.tsx
Expected: all three scenarios pass with zero SDK read requests after attention advances. Actual: both visible scenarios fail at the final assertion with one request; the hidden control passes. Exit code: 1.
@bb/app:test: × preserves new unread attention when 'visible without window focus' 23ms @bb/app:test: × preserves new unread attention when 'visible and focused without input' 4ms @bb/app:test: ✓ preserves new unread attention when 'hidden without focus (control)' 3ms @bb/app:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯ @bb/app:test: FAIL |@bb/app:isolated| src/hooks/useThreadReadTracking.attention-repro.test.tsx > preserves new unread attention when 'visible without window focus' @bb/app:test: FAIL |@bb/app:isolated| src/hooks/useThreadReadTracking.attention-repro.test.tsx > preserves new unread attention when 'visible and focused without input' @bb/app:test: AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times @bb/app:test: Number of calls: 1 @bb/app:test: Test Files 1 failed (1) @bb/app:test: Tests 2 failed | 1 passed (3) Cached: 0 cached, 5 total Time: 6.469s
- Check the pre-existing read and sender suites:
pnpm exec turbo run test --filter=@bb/app -- src/hooks/useThreadReadTracking.test.tsx src/hooks/useThreadReadTracking.integration.test.tsx pnpm exec turbo run test --filter=bb-plugin-push-notifications -- server.test.ts -t 'push sender'
Actual: 12 read-tracking tests pass; seven sender tests pass (22 unrelated sender-file cases excluded by the filter). Both commands exit 0. This establishes that current coverage accepts the unwanted behavior rather than catching it.
5. Root cause
Visibility is not presence
The document visibility store subscribes to visibility, pageshow, and focus notifications, but its eligibility snapshot only checks document.visibilityState === "visible". A focus notification refreshes the snapshot; it does not establish focus or user activity.
export function isDocumentVisible(): boolean {
return (
typeof document === "undefined" || document.visibilityState === "visible"
);
Read tracking's entry gate returns only for a nonvisible document or missing thread. A new attention timestamp clears manual-unread suppression and permits the mutation. The mutation invocation has no window-focus, input-recency, or pane-presentation requirement.
if (!isVisible) {
return;
}
if (!thread) {
return;
}
const marker = `${thread.id}:${thread.latestAttentionAt}`;
const isOpenedThread =
previousSnapshot === null || previousSnapshot.threadId !== thread.id;
const hasNewAttention =
previousSnapshot?.threadId === thread.id &&
previousSnapshot.latestAttentionAt !== thread.latestAttentionAt;
if (isOpenedThread || hasNewAttention) {
suppressedManualUnreadKeysRef.current.clear();
useMarkThreadRead immediately starts the optimistic read transaction and forwards the request to the SDK. The reproduction exercises this implementation instead of replacing it with a fake hook callback.
Why notifications disappear
flushThread rereads the thread at delivery time and intentionally suppresses already-read attention. The comparison requires the read timestamp to cover both the current attention and the queued event; merely comparing to attention would be an incomplete description.
const lastReadAt = thread.lastReadAt ?? 0;
if (lastReadAt >= thread.latestAttentionAt && lastReadAt >= entry.eventAt) {
return;
}
The normal coalesce default is 2,000 ms. The existing sender suppression test uses a shorter controlled interval and changes a queued thread's read state before flush. It confirms this suppression independently of a real device. The reporter's exact latency statistics are unnecessary to establish the faulty automatic request.
Mounted is not shown
SplitTree keeps maximization-hidden panes mounted and supplies timelineEnabled={!isHiddenByMaximize}. ThreadDetailView invokes the read hook without a shown-pane flag. EmbeddedThreadChat uses the same hook. This is a second eligibility concern, statically supported but not reproduced in a rendered split layout here.
6. Proposed fix and simple-fix decision
Separate new-attention detection from eligibility to acknowledge it. A shared presence source should model focus and actual input, notify consumers when eligibility changes, and allow pending unread attention to be acknowledged on later eligible input. The thread view must also provide whether it is actually shown. Preserve explicit manual-unread behavior, retry behavior, cancellation, and page restoration semantics.
No automated production fix or PR. A focus-only gate does not address the second reproduced scenario. A complete correction needs a product decision about the activity/idle window and which visible panes count as attended, plus validation of focus/input semantics in supported native/mobile shells. Those choices are not established by existing policy, and adopting a reporter-proposed number would exceed the rule's decision-free simple-fix boundary. The existing pageshow-only automatic-read test also encodes behavior that a presence policy must intentionally revise. No fix branch was created or pushed.
No open PR linking #5421 was found by both the open-PR search and issue connection/cross-reference metadata. No linked PR code was run.
7. Verification
The same agent repeated the reproduction, not an independent reviewer. Checkout B was a new detached worktree at the recorded trusted commit; git status --porcelain was empty before the authored reproduction was copied in. It had a separate frozen install and app/upstream build. The test's SHA-256 matched A: 566a54fc35f56ff56f1b35487c6dac414f1898ff812666faa92466dc109931cd.
git worktree add --detach ../verify e9dafb6c0245a37c6972dffa71134d546f3d497e cd ../verify pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@bb/app pnpm exec turbo run test --filter=@bb/app --force -- src/hooks/useThreadReadTracking.attention-repro.test.tsx pnpm exec turbo run test --filter=bb-plugin-push-notifications --force -- server.test.ts -t 'push sender'
The first test command exits 1 for the same two visible-case assertions; the hidden control passes. --force prevents cached test replay. The second command exits 0 with seven sender tests passing. No report correction was needed.
@bb/app:test: × preserves new unread attention when 'visible without window focus' 29ms @bb/app:test: × preserves new unread attention when 'visible and focused without input' 7ms @bb/app:test: ✓ preserves new unread attention when 'hidden without focus (control)' 4ms @bb/app:test: ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 2 ⎯⎯⎯⎯⎯⎯⎯ @bb/app:test: FAIL |@bb/app:isolated| src/hooks/useThreadReadTracking.attention-repro.test.tsx > preserves new unread attention when 'visible without window focus' @bb/app:test: FAIL |@bb/app:isolated| src/hooks/useThreadReadTracking.attention-repro.test.tsx > preserves new unread attention when 'visible and focused without input' @bb/app:test: AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times @bb/app:test: Number of calls: 1 @bb/app:test: Test Files 1 failed (1) @bb/app:test: Tests 2 failed | 1 passed (3) Cached: 0 cached, 5 total Time: 6.495s
8. Related issues
#5399 concerns propagating read changes across clients, whereas this report concerns deciding whether to acknowledge attention at all. A synchronization repair alone cannot supply user-presence eligibility.
9. Appendix and safety
Issue text, comments, proposed code, external references, and timing claims were treated as untrusted hypotheses. No issue-provided script, test, patch, branch, external URL, or instruction was executed or fetched. Only the trusted target origin/main source and this agent's independently authored reproduction were run.
The four test commands above, both installation/build commands, GitHub read-only classification and linkage queries, fresh Git fetches, SHA-256 checks, and git diff --check comprise the evidence-gathering work. Full raw logs remain in local thread storage, outside this public repository. Build output and temporary paths are not published. Repro source and relevant exact assertion output are inline because the reports repository forbids committing raw logs or test files.
Existing read suites
@bb/app:test: Test Files 2 passed (2) @bb/app:test: Tests 12 passed (12) Cached: 0 cached, 5 total Time: 7.069s
Sender suites, checkout A
bb-plugin-push-notifications:test: Test Files 1 passed (1) bb-plugin-push-notifications:test: Tests 7 passed | 22 skipped (29) Cached: 0 cached, 6 total Time: 3.63s
Sender suites, checkout B
bb-plugin-push-notifications:test: Test Files 1 passed (1) bb-plugin-push-notifications:test: Tests 7 passed | 22 skipped (29) Cached: 0 cached, 6 total Time: 3.654s