Skip to content

fix(notifications): land alert taps in an app window and off removed PCs - #958

Merged
devswha merged 6 commits into
mainfrom
fix/notification-tap-target
Oct 13, 2026
Merged

devswha merged 6 commits into
mainfrom
fix/notification-tap-target

Conversation

@devswha

@devswha devswha commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Problem

  • On Android Chrome or a desktop browser, tapping an agent alert could bring forward a Markdown reader tab (/?read=…) or a raw file tab opened earlier from the file viewer. The pane named in the alert never opened.
  • An alert (still in the notification center) or a remembered selection (reload, new window) that names a PC removed since left an empty pane area with no explanation. An alert for a pane that has closed switched to herdr's focused pane without saying anything.
  • Review follow-ups (second commit): the worker's second delivery of one tap could strand a closed pane's lookup; a tab resumed with an old roster dropped a tap for a PC set up since; a just-added PC could be reported missing by a roster rebuilt from a pane status; shipped files such as /social-preview.png still counted as app windows; and a closed pane's tap always said its workspace had closed.

Cause

  • public/sw.js notificationclick picked windows.find(focused) || windows[0] without checking client.url. matchAll lists the most recently focused window first, so the reader tab got the select-pane message. It renders FileReader, not App, so nothing consumed the message, and focus() succeeded, so openWindow never ran.
  • src/App.tsx handled "PC missing" and "pane closed" only for address links (pendingLink, resolveLink, setHeaderNote). Notification targets went straight to selectTarget, which also cleared pendingLink. That includes the worker's selectLatest repeat on a cold start, so a cold start's link could lose its machine-missing handling as well. A stored selection never set pendingLink.
  • Review follow-ups: the link resolver only re-ran on snapshot or selection changes, and dropped a lookup whose pendingLink object had been replaced, so the worker's second identical delivery stranded it. The tap handler decided "PC missing" from whatever roster the tab held, and the selection check ran on any machines change, including lists rebuilt from a pane status before load() brought a just-added PC. The alert carried no workspace, so resolveLink could only answer workspace-closed for a closed pane.

Fix

  • sw.js: new isAppWindow(url). Only the app shell's paths count: it rejects ?read= readers, /api/ responses (raw files and HTML pages), /ws, and any path whose last part has an extension other than index.html (icons, /social-preview.png, the manifest, /sw.js, notices). notificationclick only considers app windows, and opens the app when none is left. CACHE_NAME is unchanged because no icons changed.
  • Push payload: PushPayload.workspace_id (optional, additive). server/push.ts records each pane's workspace in seed() beside its title and sends it with status and ended alerts. sw.js keeps it in the notification data, posts it with select-pane, and puts it in the cold-start URL as ws=.
  • src/lib/notificationTarget.ts: machineMissing, machineGone(roster, rosterSeq, since, id) (a PC is gone only by a roster the server sent after it was named), notificationLanding(roster, target) (select, or a link carrying the alert's workspace, marked stale when the cached roster lacks the PC) and sameLink.
  • App.tsx, notification handler:
    • A pane the roster lists is selected as before.
    • Anything else is set as pendingLink, the same way popstate does, so it settles through resolveLink with its notes. With the alert's workspace, a closed pane opens its workspace's pane with the pane-closed note.
    • A second identical delivery keeps the pending link (and its lookup); a new link bumps linkTick, which the resolver effect watches, so it also settles when the pane is already selected.
    • A PC missing from the cached roster no longer settles at once: the link waits and load() asks for a fresh roster.
  • App.tsx, machine-missing effect: counts server rosters (rosterSeq, bumped in load() and the machines event, never for pane-status rebuilds) and decides only from one sent after the link or selection was made. A remembered selection (reload, new window) is checked against the first roster, and the selection keeps being checked against each newer one (a PC removed elsewhere while selected); "Open PC" before load() is checked against the roster load() brings. A rosterTick state re-runs the check when a roster comes in while a link waits, even if the list is unchanged (no re-render per poll otherwise).

Tests

  • src/pwa-notification.test.ts:
    • isAppWindow cases, now including /social-preview.png, /THIRD_PARTY_NOTICES.md, the manifest, /sw.js and /favicon.ico.
    • The push handler keeps workspace_id in the notification data; a tap posts it and a cold start opens /?machine=…&ws=…&pane=…&view=chat. Both fail on the previous sw.js.
    • A reader tab used last never gets focused or messaged, and the app window takes the pane.
    • With only reader or raw tabs open, the app opens on the pane.
    • Existing tests now give clients a URL. All 17 fail without the sw.js change.
  • src/lib/notificationTarget.test.ts: machineMissing, machineGone (a roster no newer than the naming never settles; one after it does), notificationLanding (a PC the cached roster lacks waits as a stale link, known pane, unknown roster/panes/pane, the alert's workspace with resolveLink giving pane-closed), sameLink, and workspace_id parsing in notificationTargets.
  • server/push.test.ts: status and ended alerts carry the seeded workspace_id.
  • scripts/notification-view-regression.ts: an ended pane's alert delivered twice while the session lookup is held (page.route on /api/session, released after the second tap) lands on its workspace's pane with "That agent has closed: its workspace is open". Run alone through bun run check run: passes with the fix, times out on the note with the dedupe and linkTick taken out.
  • First commit: bun run build then bun run check run bun scripts/ui-contexts-regression.ts: pass. After the review follow-ups: bun run build then bun run check run bun scripts/ui-contexts-regression.ts (includes checkNotificationStartup, which pins the select-pane message shape, and checkNotificationView): pass.
  • bun run check fast (workflow syntax, generated types, typecheck, build, unit tests: 3080 pass, 0 fail): pass.

Notes

Merge-session review

Fixed (2be0fd0, 3b87dfc):

  • Ended pane still in the cached roster (medium): a tap on a pane the resumed tab still listed selected it and dropped the alert's workspace_id; when the next roster removed the pane, the app fell back to herdr's focused pane with no note. The tap now keeps the alert's workspace as a hint with the selection (cleared by any other pick); once the selected pane is confirmed gone against fetchSession, the hint resolves through resolveLink: the workspace's pane opens with "That agent has closed: its workspace is open". Regression in scripts/notification-view-regression.ts: the pane is listed at the tap, closed through herdr afterwards, with herdr's focus in another workspace; it times out without the fix.
  • Tab alerts without workspace_id (medium): with push off and alerts on in this tab, showPaneStatusNotification / showPaneEndedNotification now put the pane's workspace_id in the notification data, and the worker-less fallback click goes through the same landing as a worker's tap. Unit test in src/lib/notifications.test.ts (fails without the fix).
  • Remove PC on the selected PC (low): the server tells the roster before it answers the DELETE, so the selection check showed "That link's PC is not set up here" for the user's own removal. MachineSidebar now selects this PC before the request and restores the selection if the request fails. scripts/machine-conflict-regression.ts gains an event stream and a DELETE that tells the roster first; it fails without the fix.
  • Unbounded wait in the browser check (low): the /api/session lookup wait races a 4 s timeout, and release() / unroute run in a finally.

Deferred:

  • An old server's push (or a pane that alerts before the server's first seed()) with no workspace_id, whose pane alone is gone still shows "That link's workspace is closed"; settling such a tap silently is a wording/policy choice, left as in the Notes above.

Checks: bun run check fast (3081 pass, 0 fail); CI=1 bun run check run --build bun scripts/ui-contexts-regression.ts: pass; CI=1 bun run check run --build bun scripts/machine-conflict-regression.ts: pass.

🤖 Generated with Claude Code

The service worker focused whichever same-origin window was used last, which
could be a Markdown reader (?read=) or a raw file tab that never handles the
pane selection. It now keeps app windows only and opens the app otherwise.

A tapped alert or a remembered selection naming a PC removed since left an
empty pane area. Alerts now go through the link path (resolveLink, notes),
which also stops the worker's repeated select-pane from clearing a cold
start's pending link, and a remembered selection of a removed PC falls back
to this PC with the machine-missing note once the roster is in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 41 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c087c2cb-8618-4de5-aeaf-dcafa3c2a5e4
📥 Commits

Reviewing files that changed from the base of the PR and between 1322830 and cdfe636.

📒 Files selected for processing (15)
  • changelog.d/notification-tap-target.md
  • public/sw.js
  • scripts/machine-conflict-regression.ts
  • scripts/notification-view-regression.ts
  • server/AGENTS.md
  • server/push.test.ts
  • server/push.ts
  • shared/protocol.ts
  • src/App.tsx
  • src/components/MachineSidebar.tsx
  • src/lib/notificationTarget.test.ts
  • src/lib/notificationTarget.ts
  • src/lib/notifications.test.ts
  • src/lib/notifications.ts
  • src/pwa-notification.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

devswha and others added 5 commits October 13, 2026 22:02
… the pane's workspace

Review follow-ups for the notification tap target fix:
- A second delivery of one tap (the worker posts before and after focus) no longer strands the
  first's session lookup: an identical pending link is kept, and a tap's link bumps a counter the
  link resolver watches, so a pane that is already selected is settled too.
- A PC missing from the tab's cached roster no longer discards the tap: it waits as a link and a
  fresh roster is asked for. A PC is called gone only by a roster the server sent after it was
  named, so a list rebuilt from a pane status (Open PC before load()) no longer drops a new PC.
- The worker treats only the app shell's paths as app windows: any shipped file is excluded.
- Push alerts name the workspace the pane was last seen in (PushPayload.workspace_id), so an
  ended pane's tap opens that workspace with the pane-closed note instead of workspace-closed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… roster

The selection's missing-PC check stays on for every roster the server sends after the selection
was made, so a PC removed elsewhere while selected still lands on this PC with the note. Rosters
rebuilt from a pane status remain no newer than the selection, and only a pending link bumps the
re-check tick, so no render is added per poll.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ab alerts

A phone resumed from the background can still list the pane an ended
alert names, so the tap selected it at once and dropped the alert's
workspace. When the next roster removed the pane, the app fell back to
herdr's focused pane, possibly in another workspace, with no note. The
tap now keeps the alert's workspace as a hint with the selection; when
the selected pane is confirmed gone, the hint resolves as a link does:
that workspace's pane opens with "That agent has closed: its workspace
is open". Any other pick clears the hint.

The tab's own alerts (push off, alerts on in this tab) carried no
workspace_id, so a tap after the pane ended said "That link's workspace
is closed" although the workspace was open. They now name the pane's
workspace as the server's push does, and the worker-less fallback click
goes through the same landing as a worker's tap.

The browser check covers the listed-then-closed pane with herdr focus in
another workspace, and bounds its /api/session wait so a future change
fails fast instead of holding the lane.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The server tells every tab the roster without a removed PC before it
answers the DELETE, so the tab's new selection check usually saw the
selected PC missing first and said "That link's PC is not set up here"
for the user's own Remove PC. Remove PC now selects this PC before the
request and puts the selection back if the request fails.

machine-conflict-regression.ts gains an event stream and a DELETE that
tells the roster before it answers, and checks that no note appears.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@devswha
devswha merged commit 426e493 into main Oct 13, 2026
17 checks passed
@devswha
devswha deleted the fix/notification-tap-target branch October 13, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant