Skip to content

feat(serving): notices carry the switcher - #1307

Merged
allisonmahmood merged 2 commits into
mainfrom
feat/switcher-notices
Nov 8, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
feat/switcher-notices

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

What changed

When Patchy stops a patch, it shows a notice: a revoked version, a document another tab replaced, a patch that needs a rebuild. A person stopped there had no way out but the address bar. Notices ran no script but the switcher relay, so Mod+Shift+K was claimed and nothing opened. Now a signed-in person opens Go to… on any notice and leaves. A signed-out person sees the notice as before.

How:

  • Optional admission (Door.noticeViewer): /~shell/notice/:code reads the session but never answers for the page. An active member or guest gets the notice with their switcher tag, then the session's scripts, so Clerk keeps the cookie fresh, plus any cookies Clerk set on the way. A handshake Clerk verified on the way back is admitted the same way, with the cookies that complete it, and without Clerk's cleanup hop; Session now returns a verified return's claims. Everyone else gets the notice with no viewer: signed out, a stale session Clerk would want to start a handshake for, signed in without a membership, deactivated, or the sign-in service down. The notice never redirects. The cookies of a handshake Clerk wants to start belong to its redirect, so they're dropped.
  • Needs-rebuild at a patch address already has its viewer, because a company address admits before it serves. It now passes that viewer to the notice. The notice's switcher tag also names the patch (data-patch), which the menu treats as the one on screen, as over a company shell: never a row, the flip goes to the patch before it, and This patch is offered by the same rule. A public patch's notice stays viewer-free, and so does a framed notice (needs-rebuild at a content URL), which keeps the relay alone.
  • The notice CSP (noticeContentSecurityPolicy) is the notice's own policy plus 'self' script and connect, Clerk's Frontend API host for both, and worker-src blob:. Only a viewer's notice gets it; everyone else's keeps the relay-only policy.
  • Caching: every notice is still private, no-store, so one viewer's notice never reaches anyone else.
  • The menu is feat(core): Mod+Shift+K opens Patchy's switcher #1304's. Its entry script now reads the patch from the tag when there's no frame. A stopping notice names no patch, so it shows no This patch and lists every place.

Closes #1271

Look at

A notice as a signed-in person, on brightline as Allison. She was in Spend Requests, then a notice says another connection replaced New Business's document. On #1304's head (ab55b42), ⌘⇧K is claimed and nothing opens. Now Go to… opens over the notice with Spend Requests lit and every place listed. There's no This patch, since no patch is on screen, and ↵ goes back.

Go to… open over the "This document was replaced" notice

Before: the same notice after ⌘⇧K

The notice with nothing open

The flow on both sides, before on the left. Before stops where the menu should open:

side-by-side.mp4

How it was verified

  • Pages.test.ts, two new cases. "As anyone" means byte-for-byte the notice rendered with no viewer, under the relay-only CSP.
    • /~shell/notice/:code:
      • A fresh session gets the switcher.
      • An expired session that Clerk refreshes on the way (refresh cookie, stubbed backend) gets the switcher and keeps Clerk's new cookies.
      • Expired with nothing to refresh it, as a browser navigation: Clerk wants a handshake. The notice is as anyone sees it, with no Location and no cookies. A mutant that passes the handshake's cookies through fails this.
      • Signed out, signed in without a membership, and deactivated: as anyone.
      • A handshake Clerk verified, returning to the notice, gets the switcher and exactly the handshake's cookies, with no redirect. Treating the completion like an initiation fails this.
      • A changed account: the notice names only the account signed in now.
      • principal_changed keeps its Sign in link for a viewer.
    • Needs-rebuild at a patch address:
      • A member, and a Clerk-refreshed session, get the switcher, naming the patch. A guest's switcher keys their own company.
      • The frame's notice at the content URL is relay-only, under the content policy.
      • Signed out gets the door (401), and a deactivated colleague the deactivated page (403), as before.
      • A public patch's notice is as anyone, with no cookies, for a member, a stale session and the signed out.
  • shell-headers.test.ts: the viewer's notice CSP admits 'self', Clerk and the relay. Apart from script, connect and worker, it is exactly the notice policy. render.test.ts: the switcher tag comes before the session's scripts, with no new inline script.
  • test/browser-tier1/switcher.spec.ts, two new cases, and all 11 pass:
    • On a stopping notice, a signed-in person's switcher keeps the list, ⌘⇧K opens the menu with Spend Requests lit and every place, Enter leaves, and the page logs no CSP violation. Signed out, the same notice claims the key and loads neither switcher.js nor /switcher.json.
    • The person visits Crew rota, then Sales HQ, and Sales HQ's wire retires. On its needs-rebuild notice, Crew rota is lit, Sales HQ isn't a row, This patch offers Overview, Versions, Log and Settings, and Enter lands on Crew rota. Without the patch in the tag, it fails: "Sales HQ is lit, not Crew rota".
  • Rebased onto main after feat(core): Mod+Shift+K opens Patchy's switcher #1304 merged (only the docs wording in docs/product.md and the Portal glossary needed merging by hand; CI is the check on the rebased head). Earlier, on the head rebased onto feat(core): Mod+Shift+K opens Patchy's switcher #1304's e72f3d40:
    • The switcher and switcher-relay browser specs pass under the shared lock, 28 of 28, both notice cases included.
    • The affected unit suites (auth Session and RequireSession, serving, core html and switcher, portal) pass, 353 of 353.
    • pnpm verify under the shared lock, with mise's Node 24 first on PATH: format, lint, typecheck, synth, postgres-concurrency, cli-smoke, install, tier2-smoke and browser pass. Browser is the whole tier 1 suite, 113 of 113.
    • test and test (bun) fail only in this machine's known places:
      • CLI stub servers, and LocalTaskProvider's, heard a stray GET / from a local port probe.
      • Supervisor's "does not reap active calls" times out at 20 s. That case answers the last request its local listener heard, so a stray request leaves the real call waiting. Alternating three runs alone on feat(core): Mod+Shift+K opens Patchy's switcher #1304's tip and on this head, it failed the same on both, 3 of 3, at a load average near 1.
  • Not checked: real browsers on a Mac. The browser suite is Chromium only, and blocks Clerk's real script, so the Clerk worker allowance is checked by policy, not by Clerk running on a notice.

Hit every surface:

  • Served pages: the ui-consistency spec says which notices load the switcher and the session's scripts, and what their CSP admits.
  • Vocabulary and product shape: Portal's Switcher and docs/product.md include notices. ADR-0006 says a notice reads the session but never redirects: it never starts a handshake, and takes a verified return without the cleanup hop.
  • Not touched: the wire contract, the CLI, the dev loop, migrations, company resources and the repo layout. Reverse states: no new way in.

Release impact

  • Breaking — requires action from anyone already running this
  • Not breaking — no action required

Notices gain scripts and a wider CSP for a signed-in viewer only. No API, CLI, schema or configuration change.

  • What does a revert leave behind? Nothing stored. A tab already showing a notice keeps its switcher until it reloads.
  • Does the release before it still work with that? Yes. Its notices render as they did. A patchy.switcher entry a notice wrote to sessionStorage is the one feat(core): Mod+Shift+K opens Patchy's switcher #1304's pages already write.

Built by Claude Opus 5.5 (xhigh) in Claude Code, orchestrated from T3 Code.

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area area:ui Portal and first-party browser pages, shared rendering and styles size:l 501-1,000 changed lines labels Nov 7, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Sol review (round 1)

CHANGES REQUESTED

  1. [P2] Needs-rebuild still takes the automatic handshake path. packages/serving/src/Pages.ts:324 — The new notice renderer runs after mandatory admission has already returned its response. Navigating to a company patch whose wire is retired with an expired session and no refresh cookie returns 307 to Clerk, with no notice. I reproduced this against the real local server. The new stale-session test covers this state only on /~shell/notice/:code; the company-address case skips it. This misses the requested non-redirecting notice behavior. Give needs-rebuild notice-aware admission, preserving the ordinary sign-in door when access cannot be established, and add the stale-without-refresh address case. Do not expose a private patch's notice to an unverified visitor.

  2. [P2] The default flip can return straight to the same needs-rebuild notice. packages/serving/src/Pages.ts:324 — No patch context reaches the notice's switcher, so its client treats the page like a portal page and selects the cached current patch. Reproduction: visit a working patch, visit another patch, retire the latter's wire, then reload it. The menu selects that same unusable patch; Mod+Shift+K then Enter navigates to the identical address and gets another 409 needs_rebuild. This breaks the parent's flip-back behavior and its rule that the current patch is never a row. Pass the known patch context into the notice's menu so it excludes that destination from the flip and selects the previous usable patch. Add a browser case for this path; the new browser case exercises only a stopping-notice URL.

  3. [P2] Dropping every handshake result also drops verified completion cookies. packages/serving/src/Door.ts:90 — Session.authenticate uses status: "handshake", completed: true for a successfully verified development handshake that only needs its cleanup hop. Returning to a notice through that flow now discards the new session cookies and omits the switcher. I reproduced a verified return carrying session cookies becoming a 200 notice with no Set-Cookie and no switcher. Dropping cookies for an unstarted handshake is reasonable; these cookies establish the session that already completed. Distinguish initiation from verified completion, preserve completion cookies, and resolve the viewer without redirecting or replaying the handshake. Cover both outcomes in the admission tests.

Validation: all 60 focused serving tests and the new Chromium notice case passed under the shared lock. The scenarios above were checked separately on a throwaway offline instance. No repository code was changed.

Reviewed by GPT 6.1 Sol (xhigh) in Codex, orchestrated from T3 Code.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Re: Sol review (round 1)

1. Needs-rebuild takes the handshake path: declined. That 307 comes from the patch address's own admission, which this PR doesn't change. A company address has to know who's asking before it says anything about the patch, a notice included, and on a top-level load that has always meant Clerk's handshake. Clerk returns to the same address, and the needs-rebuild notice then renders with the fresh session and the switcher. The notice adds no redirect of its own, and a visitor who can't be verified still gets the ordinary door.

2. The flip returned to the same notice: fixed in f2decd4. A needs-rebuild notice's switcher tag now names its patch (data-patch), and the switcher treats that patch as the one on screen, as it does a company shell's frame. It is never a row, the tab's pointer rule makes the patch before it the flip, and This patch is offered by the same membership rule as over the shell. A new browser case visits Crew rota, then Sales HQ, retires Sales HQ's wire and reloads it. On the old code it fails with "Sales HQ is lit, not Crew rota". Now Crew rota is lit, Sales HQ isn't a row, This patch offers Overview, Versions, Log and Settings, Enter lands on Crew rota, and the page logs no CSP violation.

3. Verified handshake cookies were dropped: fixed in f2decd4. Session.authenticate now returns a completed return's verified claims alongside its cookies. A stopping notice admits those claims at once and sets the cookies, so the viewer gets the switcher on that same load, with no cleanup hop and no redirect. A handshake Clerk wants to start is still no one, and its cookies are still dropped. Pages.test.ts covers both outcomes. A dev handshake return to a notice gets the switcher, with exactly the handshake's directives as Set-Cookie, and that case fails if a completion is treated like an initiation. The stale case still answers with no Location and no cookies.

@github-actions github-actions Bot added the area:core Touches the core area label Nov 7, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Sol review (round 2)

APPROVE

No findings in this PR's own diff against feat/switcher-menu. Findings 2 and 3 are closed; the declined finding 1 is not reopened.

  • Completed-handshake claims come from Clerk's verified session token, pass the existing authorized-party check and schema decoding, and reach only notice admission. Pages, withViewer, withSession, streams and /switcher.json retain their existing handshake behavior. Initiations still supply no claims and set no notice cookies.
  • data-patch comes from the server's admitted patch record, is escaped, and cannot be supplied through query parameters or frame messages. “This patch” additionally requires a matching patch in the viewer's own list. Guests and inaccessible patches get none. The rebuild notice excludes itself and flips back correctly.

Validation: 409 focused tests, 25 Chromium tests and 20 additional offline adversarial checks passed. No code changed.

Reviewed by GPT 6.1 Sol (xhigh) in Codex, orchestrated from T3 Code.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked a042c5cc (base e72f3d40, #1304's tip) on brightline, by Claude Opus 5.5 (xhigh) in Claude Code, orchestrated from T3 Code.

I drove both notice kinds as each kind of person with Playwright, in Chromium and Firefox, on fresh brightline instances: one at the head, then one at the base with the same script. Stopping notices were /~shell/notice/<code>?return=/brightline/kudos. For needs-rebuild, each person visited Kudos live, then its version's wire was set to 999 and they reloaded /brightline/kudos. Marcus was deactivated at Company by Allison while signed in, and a stranger signed in with no company.

Done means

  • A signed-in person on any Patchy notice opens the switcher with Mod+Shift+K and leaves: passed, identical in Chromium and Firefox. On the base, the same presses open nothing on any of these rows.

    Person Notice Lit This patch Enter lands on
    Allison (admin) stream_replaced New Business none /brightline/new-business
    Jordan (member) revoked Spend Requests none /brightline/spend
    Jordan (member) principal_changed Spend Requests (Sign in link kept) none not pressed
    Taylor (guest, Cedar Works) stream_replaced Kudos none /brightline/kudos
    Allison (admin) needs-rebuild, 409 New Business, Kudos not a row Overview, Versions, Log, Settings /brightline/new-business
    Jordan (member) needs-rebuild, 409 Spend Requests, Kudos not a row Overview, Versions /brightline/spend
    Taylor (guest) needs-rebuild, 409 Home, Kudos not a row none /
  • A signed-out person sees the notice as today: passed. The stream_replaced, revoked, principal_changed and session_expired notices, the 401 door at /brightline/kudos and the unknown-code 404 are byte-identical to the base, body and headers (cmp, origin normalized). In the browser, a signed-out person, the deactivated Marcus, the stranger and a forged session cookie all get the same body hash as the base. The key is claimed (window.patchySwitcher === true), there is no #patchy-switcher, and nothing is requested after the document: no switcher.js, no /switcher.json. No data-viewer, no names and no email appear in the body.

The rest of the brief

  • No redirect or loop: passed. All 20 notice responses per browser have no Location and no redirect chain. A needs-rebuild company address keeps the base's answers for people it doesn't admit: signed out and forged cookie get the 401 sign-in door, Marcus gets 403, and the stranger gets 303 to /join. The base gives the same.
  • Framed notice: passed. As Jordan and as Taylor, /~content/<kudos>/<version> answers 409 with the notice under the content policy (sandbox allow-scripts allow-modals; …; connect-src 'none'). It has one script, the relay, and no switcher tag. It's the same as the base.
  • Public patch: passed. harbor-pine-kickoff, shared public through the environment's CLI, then its wire retired, answers 409. For Jordan, signed out and a forged cookie, the body is identical, there's no viewer, no Set-Cookie, and the CSP is relay-only. It's the same as the base.
  • CSP: passed. A viewer's notice gets script-src 'self' <relay hash>; connect-src 'self'. Everyone else's keeps the relay-only policy, byte-identical to the base.
  • private, no-store: passed on every notice. That covers stopping, needs-rebuild for a member, a guest and a public patch, and framed. The signed-out and viewer responses were also read with curl. Firefox's Playwright reports bare no-store for every navigation document, the signed-out notice included. Chromium, curl and Firefox's own request context read private, no-store for the same routes.
  • Console: passed. No securitypolicyviolation event, no CSP message and no page error on any notice, in either browser. Chromium's only lines are its "Failed to load resource" for the 409, 401 and 403 documents themselves, as on the base.
  • Back: after the wire was restored, Kudos answers 200 with its frame.
  • Unit suites at the head: Pages, shell-headers, render, Session, core html and the switcher suites passed, 237 of 237. They include the Clerk refresh, initiation and completed-handshake cases.
  • CI on a042c5cc: all checks pass, including browser (with the two new switcher cases), clerk-live, tier2-smoke and rollback-rehearsal.
Screenshots: ⌘⇧K on Kudos's needs-rebuild notice, as Jordan (member) and as Taylor (guest)

Go to… over Kudos's needs-rebuild notice as Jordan: Spend Requests lit, This patch offers Overview and Versions, Kudos not listed

Go to… over Kudos's needs-rebuild notice as Taylor, a guest: no This patch, Kudos not listed, Home lit

Golden journeys

  • Sign in: passed, on brightline as Priya with dev personas. Signed out, /brightline/kudos answers 401 with the door. Signing in with return=/brightline/kudos answers 303 there, then 200. POST /logout, and the door's 401 returns.
  • Publish a page: passed. The environment's CLI, as Allison, published an HTML file. Jordan opens it at its address (200) and sees it on Home.
  • Share and unshare: passed. After share --patch … public, harbor-pine-kickoff answers 200 signed out. After share … company, it answers 401.
  • Find and open a tool: passed. Jordan opens Kudos in its frame. Home search wasn't driven by hand; CI's browser suite covers it.
  • Use a tool live and Use a tier 2 tool: not driven by hand. CI's browser subscription specs and tier2-smoke pass on the head.
  • Log a machine in and Invite and join: not touched by the diff.

Rollback answers: they match the diff. Nothing is stored. There's no migration, and no change to packages/api, the CLI or apps/infra. The new optional claims on a completed handshake exists only in memory, and only Door.noticeViewer reads it. RequireSession and every other caller ignore it. The base, which a revert serves, gave identical notices to everyone but a signed-in viewer on the same scenario, and script-free ones to signed-in viewers. No one-way label is needed, and none is set.

Not run

  • Real Clerk: a stale session Clerk refreshes on the way, a handshake Clerk wants to start (dropped), and a completed handshake admitted without the cleanup hop. Also the Clerk host and worker-src blob: in a viewer's notice CSP, and a stale session at a needs-rebuild company address taking the base's 307 to Clerk. These need a --clerk instance and a person to sign in. The PR's Pages.test.ts, Session.test.ts and shell-headers.test.ts cover them with a stubbed backend, and they passed here.
  • Real browsers on a Mac: left for Allison's hand test after deploy.

Notes

  • A forged or invalid session cookie is now cleared on the stopping notice itself (Set-Cookie: patchy_dev_person=; Max-Age=0). On the base, nothing was set there, and the next company page cleared it. The body is unchanged and the directive carries no viewer data. This is the only difference on a non-viewer's notice from the base.
  • In Firefox, the deactivated case signed in after deactivation, so it read as signed out. Chromium covers a session that was live when its person was deactivated.
  • On a dev-personas instance there's no Clerk, so a viewer's notice CSP has no Clerk host and no worker-src. That variant is checked by shell-headers.test.ts alone.

@allisonmahmood
allisonmahmood force-pushed the feat/switcher-menu branch 2 times, most recently from b785ac4 to 2a2935d Compare November 8, 2026 00:28
Base automatically changed from feat/switcher-menu to main November 8, 2026 00:44
allisonmahmood and others added 2 commits November 8, 2026 01:44
A person stopped on a Patchy notice, such as a revoked version or a
replaced document, had no way out but the address bar: notices ran no
script but the relay, so Mod+Shift+K was claimed and nothing opened.

Top-level notices now read the session without ever answering for the
page. An active signed-in viewer gets their switcher and the session's
scripts, under a notice CSP extended by exactly those sources. Signed
out, a handshake Clerk wants, no membership or a deactivated account
all get the notice as before; it never redirects. The needs-rebuild
notice at a company address uses the viewer admission already found.
Public pages and framed notices keep the relay alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t can't open

Two gaps Sol's review found in notices carrying the switcher.

A handshake Clerk verified, returning to a notice, became a plain notice
that dropped the cookies completing it. Session now returns a verified
return's claims, and a notice admits them at once with those cookies,
still without Clerk's cleanup hop. A handshake Clerk wants to start is
still no one, and its cookies are still dropped.

On a patch's needs-rebuild notice, the menu lit that same patch, so
Enter went straight back to the notice. The notice's switcher tag now
names the patch, which the menu treats as the one on screen, as a
company shell's frame does: never a row, the flip goes to the patch
before it, and This patch is offered by the same rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit 08e1fd9 into main Nov 8, 2026
25 checks passed
@allisonmahmood
allisonmahmood deleted the feat/switcher-notices branch November 8, 2026 01:00
allisonmahmood added a commit that referenced this pull request Nov 8, 2026
## What changed

This adds release 40's What's new entry, written from `08e1fd9`. It
covers everything merged since release 39's `through` (`17b1ad8`), and
sets the `patchy` release to `0.40.0` in `packages/patchy/package.json`
and `CURRENT_RELEASE`.

| Change | PRs |
| --- | --- |
| New: Jump anywhere with ⌘⇧K | #1294, #1298, #1304, #1307 |
| Improved: Your usual stays yours | #1295 |
| Patch changes: Mod+Shift+K no longer reaches patch code; Patchy serves
one script first in every patch document | #1298 |

#1293 is release 39's own entry. The range is exactly the switcher stack
(#1091), which ships as one release. #1295 had to ship no later than the
menu, and it does.

## Look at

- **The entry**, at the top of `releases` in
`packages/core/src/whatsNew.ts`.
- **Rollback safety, from the live commit `64ce907` (release 39) to this
PR's merge:**
- **No PR in the range is `one-way`.** There are no migrations, no API
or CLI contract changes, and no infrastructure changes.
- **#1295** changes only how new opens add to a person's score. Scores
written under the new rule stay valid for release 39, which keeps
counting every open.
- **#1298** inserts the relay into served patch bytes at serve time.
Stored files and digests are unchanged, so release 39 serves them as
before.
- **#1304 and #1307** add a `sessionStorage` entry that release 39 never
reads. #1307's new `claims` field on a completed Clerk handshake exists
only in memory.

**Rollback line:** If this release misbehaves, roll back to
`64ce90784350341fc2f60fe4f4161a78444f243e` (release 39).

## How it was verified

- **Tests:** the `packages/core` What's new test passes (5), the
`packages/api` suites pass (64), and the three files are formatted.
- **The range:** each of #1294, #1298, #1295, #1304 and #1307 was:
- reviewed by GPT 6.1 Sol at xhigh, with every finding fixed or declined
in writing on the PR;
  - accepted on its final head by an agent that didn't write it;
  - merged green on a branch up to date with main.

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

The changelog entry and the release version only.

- **What does a revert leave behind?** Nothing. CLIs installed from this
release report `0.40.0` and are told to match the server, as at every
release.
- **Does the release before it still work with that?** Yes.

Written by Claude Opus 5.5 in Claude Code, orchestrated from T3 Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:core Touches the core area area:docs Touches the docs area area:server Touches the server area area:ui Portal and first-party browser pages, shared rendering and styles size:l 501-1,000 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(serving): notices carry the switcher

1 participant