Repository navigation
feat(push-relay): complete the FCM route and run relay tests in Fast checks - #1816
Conversation
…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.
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.
|
Warning Review limit reachedYou'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. View limit details
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. Comment |
|
Merge pass: review-work report. This PR deletes a workflow (
Manual QA
Code-review findings and resolution
Gate review
All required checks are green and no review thread is open. |
## 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>
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:BadDeviceTokenalready is. Before, FCM'sINVALID_ARGUMENTfor a token that is not one answered502and kept the endpoint. The PC kept pushing to it until the 60-day expiry, while the same case on APNs answered410(unsubscribe). Now it deletes the token's FCM endpoints and answers410. The rule is below.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 withFCM_SERVICE_ACCOUNTand its message reach FCM. A made-up token checks the sign-in without a phone: the relay answers410only once Google took its sign-in and FCM called the token invalid.scripts/ci-tests.tsnow includespush-relay, and.github/workflows/push-relay.ymlis 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.docs/native-app.mdsaid 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.mdgains 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
projects/<id>/messages:sendwith an OAuth access token from the service account) is the send API Google documents. The legacy server-key APIs are deprecated.notificationpart. Android hands a data message to the app'sFirebaseMessagingService(ovis-push), which decrypts it and shows the PC's title and body. Anotificationpart would be shown by the system with text the relay wrote, and the relay cannot read the alert.data.ovisholds the ciphertext in standard base64, the same field and encoding as the APNs payload'sovis, so both apps decode alike.ovisis not a reserved key: FCM reservesfrom,message_type, andgoogle/gcmprefixes.ovisplus the ciphertext always fits.Urgency: highbecomesandroid.priority: HIGH(anything else,NORMAL).TTLbecomesandroid.ttlas"<n>s", capped at 28 days, which is FCM's 4-week maximum;0smeans now or never.Topicbecomesandroid.collapse_key.aes128gcmbody untouched and holds no key that could read it.The invalid-token rule
FCM's error codes say
INVALID_ARGUMENTcomes with "an extension of typegoogle.rpc.BadRequest... to specify which field was invalid". Example 2 on the send page (an invalid registration token) carries only theFcmErrordetail. 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_ARGUMENTnaming no field, or onlymessage.token: the token's FCM endpoints are deleted, and the answer is410.INVALID_ARGUMENTnaming any other field, or a bareBadRequest: the relay's message was at fault. The answer is502and the endpoint stays.service = 'fcm', so a leaked APNs token registered as an FCM one cannot wipe the phone's iOS endpoints (tested).UNREGISTEREDandSENDER_ID_MISMATCHare unchanged.Changes to existing tests (still 27 of them, plus 1 new = 28):
INVALID_ARGUMENTcase that expected502is what this PR now treats as gone. It moved to the gone test, and threeINVALID_ARGUMENTanswers that name a field of the message take its place, still502and kept.UNAUTHENTICATEDanswer instead ofTHIRD_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
app/,server/orshared/.429from FCM or APNs is passed on withoutRetry-After, as before.CI and open PRs
No open PR touches
scripts/ci-tests.ts,.github/workflows/push-relay.ymlorci.yml. #1652 changesdocs/development.mdin another hunk (line 145; this one is at line 756). #1542, which #1695 waited for before folding the workflow in, is merged. #1813 touchesserver/only.Verification
bun test ./push-relay: 28 pass, 0 fail.INVALID_ARGUMENTas 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.tsthrough its CLI, against the realworker.tsserved on loopback with in-memory SQLite and a fake Google/FCM that gives Firebase's documented invalid-token answer:fcmwithout a token, or an unknown APNs environment, it prints the usage and exits 2.201throughapi.sandbox.push.apple.com.201after one Google sign-in.410with 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 includingpush-relay/worker.test.ts), exit 0.test-push.tssmoke 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 (
502to410) and removes a workflow, so it waits for a real review.