Skip to content

feat(push-relay): complete the FCM route and run relay tests in Fast checks - #1816

Merged
devswha merged 5 commits into
mainfrom
feat/push-relay-fcm
Oct 24, 2026
Merged

devswha merged 5 commits into
mainfrom
feat/push-relay-fcm

Conversation

@devswha

@devswha devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner

What

The FCM route this was meant to add is already on main: it landed with the relay in #1695 (commit 1089a2b41, "send to Android phones through Firebase Cloud Messaging"). It has { "service": "fcm", "token", "vapid_key" } registration, FCM HTTP v1 data messages, VAPID pinning, the same rate limits, and gone handling scoped per service. #1744's Android module already registers that way. This PR audits the route against the APNs contract and closes what the audit found:

  1. An FCM token that FCM calls invalid is gone, as an APNs BadDeviceToken already is. Before, FCM's INVALID_ARGUMENT for a token that is not one answered 502 and kept the endpoint. The PC kept pushing to it until the 60-day expiry, while the same case on APNs answered 410 (unsubscribe). Now it deletes the token's FCM endpoints and answers 410. The rule is below.
  2. FCM endpoints are tested under the same limits. A new test pins the per-endpoint limit (60) and the per-phone limit across a token's endpoints (120), applied before FCM is called. Moving the FCM branch above the limits fails it (mutation-checked).
  3. push-relay/test-push.ts fcm <token> sends one real push through FCM after a deploy, as it already did for APNs. The tests use a fake Google, so only a real call shows that the relay's sign-in with FCM_SERVICE_ACCOUNT and its message reach FCM. A made-up token checks the sign-in without a phone: the relay answers 410 only once Google took its sign-in and FCM called the token invalid.
  4. The relay's tests run in Fast checks. The unit glob in scripts/ci-tests.ts now includes push-relay, and .github/workflows/push-relay.yml is removed. Fast checks runs on every PR with no path filter, so a relay-only PR still runs them, and they now sit behind a required check.
  5. Docs: docs/native-app.md said Android (FCM) would get its route "later". It now says what is built and what Android push still waits for: step 4's native subscribe, the Firebase project and the deploy. push-relay/README.md gains the invalid-token rule, the Firebase prerequisite, the FCM real-push check and the CI move. The changelog fragment is under Maintenance.

Why FCM HTTP v1, as a data-only message

  • HTTP v1 (projects/<id>/messages:send with an OAuth access token from the service account) is the send API Google documents. The legacy server-key APIs are deprecated.
  • Data only, no notification part. Android hands a data message to the app's FirebaseMessagingService (ovis-push), which decrypts it and shows the PC's title and body. A notification part would be shown by the system with text the relay wrote, and the relay cannot read the alert.
  • data.ovis holds the ciphertext in standard base64, the same field and encoding as the APNs payload's ovis, so both apps decode alike. ovis is not a reserved key: FCM reserves from, message_type, and google/gcm prefixes.
  • Size: FCM's 4096-byte limit counts data keys and values. The relay already refuses a push whose APNs wrapper passes 4096 bytes, so ovis plus the ciphertext always fits.
  • Headers: Urgency: high becomes android.priority: HIGH (anything else, NORMAL). TTL becomes android.ttl as "<n>s", capped at 28 days, which is FCM's 4-week maximum; 0s means now or never. Topic becomes android.collapse_key.
  • Still end-to-end encrypted: the relay forwards the RFC 8291 aes128gcm body untouched and holds no key that could read it.

The invalid-token rule

FCM's error codes say INVALID_ARGUMENT comes with "an extension of type google.rpc.BadRequest ... to specify which field was invalid". Example 2 on the send page (an invalid registration token) carries only the FcmError detail. The token management guide says: "If you are certain that the message payload is valid and you receive either of these responses [UNREGISTERED, INVALID_ARGUMENT] ... it is safe to delete your record of this registration".

The relay's message has a fixed shape, and every parameter a PC controls (TTL, Topic, Urgency, body size) is validated before sending. So:

  • INVALID_ARGUMENT naming no field, or only message.token: the token's FCM endpoints are deleted, and the answer is 410.
  • INVALID_ARGUMENT naming any other field, or a bare BadRequest: the relay's message was at fault. The answer is 502 and the endpoint stays.
  • The delete stays service = 'fcm', so a leaked APNs token registered as an FCM one cannot wipe the phone's iOS endpoints (tested). UNREGISTERED and SENDER_ID_MISMATCH are unchanged.

Changes to existing tests (still 27 of them, plus 1 new = 28):

  • In "a refused access token is fetched again once; other FCM or sign-in failures keep the endpoint", the bare INVALID_ARGUMENT case that expected 502 is what this PR now treats as gone. It moved to the gone test, and three INVALID_ARGUMENT answers that name a field of the message take its place, still 502 and kept.
  • The expired-access-token fixture now uses FCM's UNAUTHENTICATED answer instead of THIRD_PARTY_AUTH_ERROR, which is about APNs and web push credentials. Behaviour for any 401 is unchanged: fetch a new access token once.

Left as it is, on purpose

  • No deploy, no Cloudflare resources, no secrets.
  • Nothing in app/, server/ or shared/.
  • The 32-endpoint cap and the per-phone limit still count per token string across services. A token string belongs to one service in practice, and a per-service cap would not stop a leaked-token eviction (one can register 32 of the same service).
  • A 429 from FCM or APNs is passed on without Retry-After, as before.

CI and open PRs

No open PR touches scripts/ci-tests.ts, .github/workflows/push-relay.yml or ci.yml. #1652 changes docs/development.md in another hunk (line 145; this one is at line 756). #1542, which #1695 waited for before folding the workflow in, is merged. #1813 touches server/ only.

Verification

  • bun test ./push-relay: 28 pass, 0 fail.
  • Mutation checks, each restored afterwards. Treating INVALID_ARGUMENT as never gone fails the gone test. Ignoring the named fields fails the keep test. Sending to FCM before the rate limits fails the new limits test.
  • test-push.ts through its CLI, against the real worker.ts served on loopback with in-memory SQLite and a fake Google/FCM that gives Firebase's documented invalid-token answer:
    • With no arguments, fcm without a token, or an unknown APNs environment, it prints the usage and exits 2.
    • An APNs sandbox token gets 201 through api.sandbox.push.apple.com.
    • An FCM token gets 201 after one Google sign-in.
    • A made-up FCM token gets 410 with the sign-in note, its endpoint is deleted, and the cached access token is reused.
  • bun run check fast: all steps ok on the final tree (typecheck, build, unit tests 6365 pass / 0 fail in 452 files, now including push-relay/worker.test.ts), exit 0.
  • Gate review by a code-review agent: APPROVE, no blocking issues. It reran the relay and changelog suites (40 pass), reproduced the test-push.ts smoke run against the real Worker, and ran 13 error-path probes of its own on the FCM handling.

Review

This changes the relay's HTTP answer for one FCM error (502 to 410) and removes a workflow, so it waits for a real review.

…iceToken

FCM's INVALID_ARGUMENT for a token that is not one answered 502 and kept the endpoint, so the PC
pushed to it until the 60-day expiry, where APNs' BadDeviceToken answers 410. FCM names a refused
request field in a google.rpc.BadRequest detail and an invalid token comes with none (Firebase's
own example), so INVALID_ARGUMENT naming no field but message.token now deletes the token's FCM
endpoints and answers 410; one naming any other field is the relay's message at fault and keeps
the endpoint. The delete stays scoped to service = 'fcm'.

The expired access token fixture now uses FCM's UNAUTHENTICATED answer; any 401 still fetches a
new access token once.
…ones

The per-endpoint and per-phone limits were tested on APNs endpoints only; an FCM endpoint now
shows both, and that a limited push never reaches FCM or counts.
`bun push-relay/test-push.ts fcm <token>` registers an FCM token and sends one push, as the APNs
form does: the tests use a fake Google, so only a real call shows that the relay's sign-in with
FCM_SERVICE_ACCOUNT and its message reach FCM. A made-up token checks the sign-in without a
phone: the relay answers 410 only once Google took it and FCM called the token invalid.
scripts/ci-tests.ts collects push-relay/ with the unit tests, so the relay's tests run in Fast
checks (no path filter, a required check) and the dedicated Push relay workflow goes, the
follow-up #1695 planned once #1542 merged.
The plan still said Android would get its relay route later; it is built (not deployed), and
Android push now waits for the client's native subscribe, the Firebase project and the deploy.
@coderabbitai

coderabbitai Bot commented Oct 24, 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 1 minute.

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
Commits

Reviewing files that changed from the base of the PR and between a3267e6 and a33682c.

Files selected for processing: 9
  • .github/workflows/push-relay.yml
  • changelog.d/push-relay-fcm.md
  • docs/development.md
  • docs/native-app.md
  • push-relay/README.md
  • push-relay/test-push.ts
  • push-relay/worker.test.ts
  • push-relay/worker.ts
  • scripts/ci-tests.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

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass: review-work report. This PR deletes a workflow (.github/workflows/push-relay.yml), and CodeRabbit's check passed only because it was rate-limited, so no CodeRabbit review ran. Per AGENTS.md, this comment records the code-review agent's findings and how each was resolved. Overall: PASSED.

Lane Verdict Confidence
Manual QA (7 rows, artifacts kept) PASS -
Code review (omo-native-code-reviewer, programming and remove-ai-slops) PASS: 0 blocker, 0 major -
Gate review (fresh reviewer, another model) APPROVE HIGH

Manual QA

  • 28 relay tests pass, and the typecheck passes.
  • The new 410 case fails on main's worker.ts.
  • The new unit glob selects push-relay/worker.test.ts.
  • This PR's Fast checks job ran push-relay/worker.test.ts (exit 0), with unit: 6364 pass, 0 fail. The deleted workflow only ran bun test ./push-relay, and Fast checks now covers that on every PR and every push to main.
  • Merging deploys nothing: no workflow deploys the relay.
  • Outside PR feat(chat): read native Copilot CLI transcripts #1652 gets no new conflict.

Code-review findings and resolution

  • Invalid-token rule. It is correct against FCM's documented error shapes. Malformed JSON, missing details and non-array details all mean "not gone", so the endpoint is kept and the relay answers 502. If there are several violations, all must be message.token. Mutants are all killed: main's worker, "every INVALID_ARGUMENT is gone", and a delete without service='fcm'. Resolved: no change needed.
  • Deletion scope. Only that token's FCM endpoints are removed, and a test proves APNs endpoints survive. No change needed.
  • Secrets. test-push.ts never reads the service account and prints only HTTP statuses. The gate ran the real CLI against a local Worker: exit 0, one FCM send, no token printed. No change needed.
  • MINOR (worker.ts:395-396). A BadRequest with an empty fieldViolations list counts as gone, and the rule relies on the relay's own message staying valid. Accepted as is: a violation that names no field is, by the PR's stated rule, the documented invalid-token case, and every PC-controlled parameter is validated before sending. Any future change to the message must keep that invariant. Worth a follow-up comment in the code.
  • NITs (accepted, follow-ups). The response body is typed with a cast rather than a schema. fcm <token> sandbox takes sandbox as the relay address. One README line is wider than the rest.

Gate review

  • All five changes were verified.
  • 11 error-response cases were exercised: empty and mixed fieldViolations, malformed details, and 404 UNREGISTERED. FCM invalidation keeps APNs endpoints, and errors in other fields keep FCM endpoints.

All required checks are green and no review thread is open.

@devswha
devswha merged commit aabe566 into main Oct 24, 2026
9 checks passed
@devswha
devswha deleted the feat/push-relay-fcm branch October 24, 2026 08:03
devswha added a commit that referenced this pull request Oct 25, 2026
## What

Mute one noisy agent's alerts from its row menu in the Agents list (the
⋯, a right-click or the context-menu key): **Mute alerts** / **Unmute
alerts**. A muted pane raises no alert on any channel, on any browser or
device of the server, while its status is still drawn and tracked:

- **Push, browser and phone app.** `server/push.ts` reads the shared
list when an alert is scheduled, again right before a delayed one goes
out (also after its title lookup), and when a pane ends. A mute change
calls off waiting alerts for good, so an unmute does not bring back an
old finish. The phone app (#1744, #1816, #1817) subscribes through its
`OvisPush` plugin and posts its relay endpoint to the same `POST
/api/push/subscribe`, so it is one more subscription on the same list
and is muted the same way: the push service treats every endpoint alike,
and a test pins a relay-shaped subscription held back next to a browser
one.
- **In the page:** the in-app droplet, the chime and the tab
notification (`src/lib/useAlerts.ts`). A chime that waits its turn among
open tabs checks the mute again right before it plays, and a chime
already scheduled behind another one (`src/lib/alertSound.ts`) is
silenced when the pane is muted before its notes start, unless another
pane it also tells is still unmuted; a caller is confirmed only when the
chime sounded and its pane is still unmuted.
- **Shared like the pins:** a new optional `muted_panes` in
`/api/preferences` (keys are `paneStorageId`, so a pane id reused on
another PC is not muted; validated, deduplicated, at most 500). A
missing list in a change leaves it, an empty one clears it. An older
server that keeps no list gets none sent and offers no mute. Two
browsers muting different panes at once both keep their mute (merged
pane by pane), and a refused change gives way to a newer list as the
pins do.
- A muted row shows a crossed bell. A watching device sees the item
disabled.

Refs #1052. This revives a local branch from before the i18n, `App.tsx`
and shared-type splits; it is rebased onto current main with the strings
in `src/lib/i18n/sidebar.*` and the page checks in `useAlerts.ts`.

Design: follows the per-conversation mute of chat apps (Slack's "Mute
channel", Discord's "Mute channel"): one switch in the item's own menu,
a quiet icon on the row, state shared across devices. Coding-agent apps
(Codex, Claude) have no per-session mute, so there is nothing closer to
follow. DESIGN.md has the entry.

## Why

One agent that finishes or asks often (a watcher, a looping job) drowns
out the others. The only way to quiet it was to turn alerts off for
every pane or on one device at a time.

## Storage

The list is kept in a document of its own, `muted-panes.json` (`{
"muted_panes": [...] }`) in the state directory, written by
`PreferenceStore` (`server/preferences.ts`). `preferences.json` keeps
exactly the shape every release reads and writes. A release from before
this one rewrites `preferences.json` whole on its next save; keeping the
list there would let a rollback or downgrade erase every mute. In its
own document it is an addition an older writer cannot erase, so under
the stored-format rules of #1824 it is not a structural change:

- an older release never opens `muted-panes.json`, and its saves leave
it alone; after it, this release reads the older save and the mutes
together, with no write of its own (tested);
- a missing `muted-panes.json` reads as nothing muted; a damaged one
mutes nothing, is never read as an empty list to write over, and is kept
as `muted-panes.json.bad` by the next mute (tested);
- a save writes `preferences.json` first, then `muted-panes.json`. If
the second write fails, the previous `preferences.json` is put back
before the 500, so both files are byte-for-byte as they were (tested);
- **accepted window:** two files cannot be swapped as one. If putting
`preferences.json` back fails too, or the process ends between the two
renames, `preferences.json` keeps the refused change and a restart reads
it, although memory and the client were told the save failed. Nothing is
lost; at worst a refused settings or pins change comes back after a
restart. Closing this would take a journal or one combined document,
which is more machinery than a settings store warrants;
- the HTTP/WS contract still carries the list as `muted_panes` in the
`/api/preferences` document and the `preferences` event.

## Contract change — needs a real review

This adds a field to the `/api/preferences` HTTP contract and the
`preferences` event on the machines event stream, and changes when
web/native push is sent. Per AGENTS.md it should wait for a real review,
not only CodeRabbit.

## How it was verified

- `bun run check fast`: typecheck, build and unit tests pass.
- Unit tests: `server/push.test.ts` (mute cancels a delayed push;
mute+unmute during the title lookup sends nothing; list re-read before
send; all four paths suppress only the keyed pane; the phone app's relay
subscription is muted next to a browser's), `server/preferences.test.ts`
(malformed and oversized lists, older documents, an older release's
whole rewrite of `preferences.json` after a mute, a damaged
`muted-panes.json`), `src/lib/alertSound.test.ts` (a question queued
behind a finish, muted before its notes start, never sounds and gives
its place back; a question chime two panes share keeps sounding for the
unmuted one and is confirmed only to it),
`src/lib/preferencesSync(.hook).test.ts` (older server, refused change,
concurrent mutes from two browsers), `src/lib/notifications.test.ts`.
- `server/api.contract.test.ts`: the HTTP and event-stream round trip,
two tabs' revisions, and a watching device's PUT answered 403.
- `scripts/pane-mute-demo-regression.ts` (enrolled in `ci-browser.sh`):
the unmodified app over the demo transport with the real
`PreferenceStore`, two tabs as two browsers, at 390 and 1440 wide, light
and dark, Korean at 390: the menu item, its pressed and focus states,
the crossed bell, the alerts held back, an older server and a watching
device.
- Reviewed by a code-review agent and by Codex (no HIGH findings).
Fixed: concurrent mutes from two browsers now merge pane by pane (with a
test that fails without it), and a chime waiting its turn among tabs
re-checks the mute. Known and left as is: two saves of the mute list
landing at the same instant end with the last one, as the pins do; the
menu item says Mute/Unmute and carries a checked state, as designed in
DESIGN.md.

---------

Co-authored-by: mp <mp@local>
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