Registry Mirror
Skip to content

Conversation

@backnotprop

@backnotprop backnotprop commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Why

The owner rarely got Chrome notifications from the Inbox. His Inbox's settings showed notifications: { enabled: true, allowed_origin: "http://127.0.0.1:59812" }, while the Inbox advertises and opens http://localhost:59812/. Chrome grants notification permission per scheme+host+port, so the page at localhost:59812 had no permission (default), and the one-time "allow again" line only appeared when a question arrived while the page was open, then never again after a reload. Notifications were off, silently.

Owner's requirement: notifications must always work, deterministically, and never fail silently. This PR detects every way they fail silently, and fixes or plainly shows each. Which events notify is unchanged.

What changes

1. Origin drift (fixed / shown prominently)

  • One origin: a browser's top-level navigation of / at another loopback spelling of this port (127.x.y.z, [::1]) answers 307 to http://localhost:<port>/ with its query; the browser keeps the #thread= fragment (packages/server/inbox-canonical.ts). localhost is canonical because it is what the Inbox already opens and advertises, what every thread link agents get uses, and the spelling plan review / code review share their cookies on. Never redirected: APIs, the device door, MCP, connection routes, frames, clients without fetch metadata, the tailnet listener, another port's spelling, any non-literal name (the prototype's inbox.plannotator.localhost, PLANNOTATOR_ALLOWED_HOSTS names).
  • Port drift: when this address has no permission but another address of this computer had it (allowedOrigin), a prominent "Notifications are off at this address … Allow" line shows at once, on every load, until answered. The plain ask (never asked here) also stays on every load once the Inbox holds a thread; a blocked address gets a quiet line pointing at Settings. A grant made in Chrome's site settings while the page is open records allowedOrigin.
  • Fixed-address prototype (PROTOTYPE: one-click fixed address for the Inbox (portless) — do not merge #1945): its name removes port drift entirely (one origin whatever port the Inbox gets). This PR adds no seam for it; the prototype can make its name the one address when it lands.

2. No tab open (shown; a fallback is a decision, see the design note)

  • The server counts open Inbox windows (event streams with window=<id>) and whether each one's browser allows notifications (POST /api/inbox/window, live on change). notify_reach: { enabled, windows, allowed, allowed_origins } rides /api/inbox/health, /api/inbox/settings and an event: reach frame.
  • Each tab reports again on every event-stream hello (a reconnect's URL carries the permission it first had; after the 15 s grace or an Inbox restart that would be stale), without the page's serverSession so it reaches a restarted Inbox. event: reach goes only to streams with a window= id, never the phone's door (contract 7.9).
  • Settings → General: "Notifications reach you: Yes, through this tab / through another Inbox tab (localhost:61000) / No: no open Inbox tab may notify / No: no Inbox tab is open".

3. Background tabs

  • Chrome's intensive throttling only aligns chained timers; the page's work after an event is one unchained timer, so a hidden tab's notice is delayed by at most ~1 s. Proved: the e2e freezes the tab with CDP (Page.setWebLifecycleState: frozen), sends a question, resumes, and the notice is raised once.
  • Bug fixed: on an EventSource reconnect the server used the cursor the URL was opened with instead of Last-Event-ID, replaying everything since page load. A usable header (a non-negative whole number) now wins; an empty or malformed one falls back to the cursor. So a tab whose connection dropped catches up from where it was and raises what it missed.
  • A tab Chrome discarded (Memory Saver; document.wasDiscarded) or froze for a minute or more says so once, with how to keep localhost always active.

4. Several tabs / stale tabs

  • A tab that may not notify (no permission, blocked, another origin) never claims an item, so it cannot swallow a notice another tab would show; claims are per origin anyway. Proved in the hook test.

5. Live status and a test

  • Permission is read live (Permissions API change event + a fresh read on focus/visibility).
  • Settings: On for this address, Off, Not allowed in Chrome for this address with Allow, Blocked in Chrome for this address with Chrome's own steps for this address; Send a test notification (own tag, never replaces a real notice) with "Didn't see it? Check System Settings → Notifications → Google Chrome, and Focus." No new keyboard shortcuts.

Design note: notifying with no Inbox tab open (for the owner to decide)

(The note was meant for .product/drafts/inbox-notify-deterministic/NOTE.md in the main checkout; this agent could not write outside its worktree, so it is here in full.)

The server now knows the exact moment no tab can notify (notify_reach.allowed === 0 when a question arrives), so any fallback below can fire only then, with no duplicates.

  1. Service worker + Notification (no push). A service worker only runs when an event wakes it; with no tab open nothing does (Periodic Background Sync needs an installed PWA and fires at the browser's discretion, hours apart). Not viable alone.
  2. Web Push. The Inbox sends an encrypted push (VAPID) through the browser's push service (Chrome: FCM, Safari 16+: Apple), which wakes the service worker with no tab open while the browser runs (macOS Chrome keeps running with no windows; Windows/Linux need "continue running background apps"). http://localhost is a secure context. Needs the internet and a third-party push service (payload end-to-end encrypted), and a fixed origin (subscription is per origin: PROTOTYPE: one-click fixed address for the Inbox (portless) — do not merge #1945 or a fixed port).
  3. Native macOS helper (the existing spike): UNUserNotificationCenter, its own permission and icon, offline, no browser/tab/origin involved, click opens the thread. Needs Developer ID signing + notarization. Linux notify-send and a Windows toast have the same shape.
  4. osascript display notification. Zero install; but attributed to Script Editor (its permission and icon), click opens Script Editor not the thread, no replace-by-tag, no actions. A stop-gap only.
  5. Install as an app (PWA / Chrome app mode). Own window, Dock icon, badge, stable origin per install; closing the window still ends the page, so alone it notifies no more than a tab (an app window is less likely to be closed or discarded, to verify). With option 2 it gives push with no window open.

Recommendation: merge this; land the fixed address (#1945) to end port drift (any browser-side option needs a stable origin anyway); for "no tab open", a server-side fallback fired only when allowed === 0: the native macOS helper (3), with osascript (4) as a labelled interim if acceptable, and notify-send / Windows toast on those systems. Web Push (2) + PWA (5) only if a browser-only answer is preferred and the internet dependency is acceptable. Open question: is the osascript interim acceptable until the helper is signed?

Tests

  • packages/server/inbox-notify-origin.test.ts: the redirect (127.x, [::1], query kept) and everything not redirected (no fetch metadata, frames, HEAD, APIs, the door, MCP, other names, other ports, the tailnet); window counting, a reconnect past the grace with a stale URL put right by the report, reach frames only for windows, unusable Last-Event-ID falling back to the cursor, live reports, grace, the switch off; validation and the stale-tab / cross-site guards; Last-Event-ID resumes.
  • packages/inbox/notify.test.ts (askKind, the owner's case), notifyStatus.test.ts (status words, blocked steps, the test hint, reach), notifyHook.test.tsx (no claim without permission, live re-read, the ask staying, the test notice, frozen/discarded, the window report), notificationStates.test.tsx (DOM: each line, Settings status, Allow, steps, test, reach).
  • tests/e2e/notifications.spec.ts on the compiled binary: the ask stays across a reload, 127.0.0.1 lands on localhost with its #thread, Settings status / test / reach, "moved" at once after a port change with Allow, an Inbox restart under an open tab (the tab reconnects and reports granted again), a frozen tab raises what arrived as it wakes, once.
  • inbox-devices.test.ts: health's key list gains the additive notify_reach (contract 7.4 updated).

backnotprop and others added 4 commits October 16, 2026 17:39
…stays, live status, test, reach

- One origin: a browser navigation at 127.x/[::1]:<port> redirects to
  http://localhost:<port>/ (permission is per origin); APIs, the door, MCP,
  the tailnet and other names are never redirected. A canonicalUrl seam for
  the fixed-address prototype (#1945).
- The line above the list stays until resolved: 'moved' (allowed at another
  address, none here) at once with Allow; 'ask' once there is a thread;
  'blocked' quiet, pointing at Settings.
- Live permission (change event + focus/visibility), Settings status, Allow,
  blocked steps, Send a test notification with the macOS hint.
- The server counts open windows and which may notify (notify_reach on health,
  settings and an SSE 'reach' frame; POST /api/inbox/window).
- Last-Event-ID wins over the URL cursor on reconnect; a discarded or long-
  frozen tab says so; a tab without permission claims nothing.

Co-Authored-By: Claude <noreply@anthropic.com>
- A reconnecting tab reports its permission again on every hello (the
  stream URL's permission= can be stale past the grace or after a restart),
  without the page's serverSession so it reaches a restarted Inbox.
- reach frames only on streams with a window= id (never the phone's door).
- Last-Event-ID counts only when it is a non-negative whole number; else the
  URL's cursor.
- Drop the unused canonicalUrl seam (the fixed-address prototype can add it).

Co-Authored-By: Claude <noreply@anthropic.com>
…ns; the moved line says to reload or close the old tab; 7.9 says Last-Event-ID wins over ?cursor=
@backnotprop
backnotprop merged commit 660d019 into main Oct 17, 2026
32 checks passed
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