Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
Push notifications in the browser (Web Push)
Status: in-progress Author: Claude Date: 2026-10-08
TLDR
Carbon shows a notification only in the ERP bell, by email or by Slack. If no Carbon tab is open, the user sees nothing until they open the app or read their mail. This spec adds a fourth channel: push.
Push uses the Web Push standard to show an operating-system notification, even when every Carbon tab is closed. Browser notifications are a setting of the browser, not of a user. Once someone enables them in a browser, whoever is signed in there gets their own notifications, from every company they belong to. Signing out stops them at once. Like the in-app bell, push has no per-topic switch: every notification pushes.
The notify job sends one push for each notification it creates. The job uses the web-push package and one VAPID key pair for each deployment. The pair is derived from SESSION_SECRET, so push needs no setup.
Overview diagram
sequenceDiagram
participant U as Browser
participant SW as push-worker.js
participant ERP as ERP routes
participant DB as pushSubscription
participant N as notify job
participant S as send-push job
participant P as Push service
U->>SW: Enable: register + subscribe
U->>ERP: PUT subscription, gets carbon-push cookie
ERP->>DB: upsert the row of this endpoint
N->>DB: read rows of push recipients
N->>S: carbon/send-push per row
S->>P: signed, encrypted request
P->>SW: push event, worker shows it
U->>ERP: sign out, cookie names the endpoint
ERP->>DB: delete rows of the endpoint
U->>ERP: next sign-in, the bell re-saves the row
Problem Statement
- The
notifyjob (packages/jobs/src/inngest/functions/notifications/notify.ts) had 3 channels: in-app, email and Slack. - The in-app channel reaches the user only while an ERP tab is open.
useNotificationslistens on the realtime topicuser:<userId>:notification. - Email is a paid feature (
EMAIL_NOTIFICATIONS, Business and Partner plans). On other plans, a user with no ERP tab open gets no signal at all. - A planner who closes the browser at the end of a shift misses an approval request or a job assignment until the next login.
Before this change, no code in apps/ or packages/ called the Notification API, the Push API or navigator.serviceWorker. The file apps/erp/public/serviceWorker.js existed, but no code registered it. It is deleted (2026-10-09).
Proposed Solution
How Web Push works in Carbon
- Each deployment has one VAPID key pair.
getVapidDetails()(@carbon/env/push.server) derives it fromSESSION_SECRET. There are no push env vars. - The user clicks Enable on the bell's "Enable browser notifications" row or on the Browser notifications card at Account → Notifications.
- The browser asks for permission to show notifications.
- The page registers the service worker
/push-worker.jsand callspushManager.subscribe()with the VAPID public key. - The browser returns a subscription: an endpoint URL and 2 keys (
p256dh,auth). - The page sends the subscription with
PUT /api/push-subscription. - The route saves one
pushSubscriptionrow for this endpoint, owned by the signed-in user. - The route sets the signed
carbon-pushcookie, which holds the endpoint. - The page sets
browserNotificationsEnabledin localStorage: browser notifications are now on for this browser. - Later, the
notifyjob finds the push recipients and theirpushSubscriptionrows, and sends onecarbon/send-pushevent per row. - The
send-pushjob signs and encrypts the payload withweb-pushand posts it to the endpoint. - The push service sends the payload to the browser, where
push-worker.jsshows the notification. - When the user clicks the notification, the worker focuses an open Carbon tab or opens a new one at the notification's link.
Sign-out and the next sign-in
- Every sign-out path calls
clearAuthCookies(@carbon/auth): the explicit sign-out, a forced sign-out and an expired session on the login page. clearAuthCookiesreads thecarbon-pushcookie, deletes every row of that endpoint and clears the cookie. Pushes for the user who left stop at once.- The browser keeps its permission, its subscription and the
browserNotificationsEnabledflag. - When the next user signs in,
useRestoreBrowserNotificationsruns from the always-mounted bell, once per tab and user. - If permission is granted and the flag is set, it saves the browser's subscription for the user signed in now, with no prompt.
- The new user only ever gets their own notifications:
notifysends a push to the owner of the row and nobody else.
Which notifications push
Push mirrors in-app. If the deployment has push keys (isPushConfigured(), true wherever SESSION_SECRET is set), every recipient of the in-app row gets a push in each browser where notifications are on. There is no topic filter and no event filter. So IntegrationSync, which fires again on each sync sweep while failures last, also pushes each time.
notify reads subscriptions by userId only. The step resolve-recipients already limits the recipients to members of the notification's company. So a user gets the push of every company they belong to, and a company switch does not silence the browser.
A digest from notify (more than one item) sends one push with the digest's description. The cron job notification-digest sends no push, because it only rolls up rows that notify already delivered.
Payload
| Field | Value |
|---|---|
title |
getNotificationEmailHeading(event), for example "Job assigned to you". A workflow notification uses its author's subject (the description). |
body |
the notification description, for example "Job J00105 assigned to you". A workflow notification uses its author's message, with each [label](url) reduced to its label. |
url |
buildNotificationLink(event, documentId, companyId, documentType); /api/link switches the company first |
tag |
`${event}:${primaryDocumentId}`; the worker closes an older notification with the same tag before it shows the new one |
web-push encrypts the payload end to end (aes128gcm). The push service cannot read it.
Design Decisions
| Decision | Choice | Rationale |
|---|---|---|
| Plan gating | None. Push is free on all plans. | Agreed with the user. Push is another view of the in-app notification, and the bell is free. |
| Library | web-push in @carbon/jobs |
Agreed with the user. It does VAPID signing and payload encryption, which are easy to get wrong by hand. |
| Apps | ERP only | Agreed with the user. MES has no notification UI. |
| Channel name | "push" in code; "browser notifications" in the UI | "Browser notifications" is the word a user understands. |
| Per-topic switch | None. Push is not a NotificationDestination or a NotificationPreferenceChannel. |
Agreed with the user: push mirrors in-app, which has no switch either. |
| Setting scope | A setting of the browser, not of a user | Agreed with the user. A shared computer gives each signed-in person their own notifications without a new opt-in. Browser permission is per site and browser too. |
| Subscription rows | One row per endpoint (UNIQUE ("endpoint")), owned by the signed-in user. companyId is the company the user enabled it from. |
One browser has one endpoint, so one owner at a time. companyId keeps tenant attribution and the RLS member check. |
| Companies | The user gets the push of every company they belong to | Agreed with the user. resolve-recipients already drops non-members. |
| Table shape | id from xid(), single-column PK, no audit columns |
Same shape as notificationPreference and userModulePreference: a user-owned preference row. |
| RLS | Owner and company member, the same rule as notificationPreference |
The user reads and writes only their own rows. The jobs and the sign-out cleanup use the service role. |
| Same browser, new user | On save, the route deletes the rows of OTHER users with the same endpoint (service role) | Only the user signed in now may own the browser's row. |
| Sign out | clearAuthCookies deletes the rows of the endpoint in the signed carbon-push cookie |
Agreed with the user: signing out stops pushes on every path, not only the Sign Out button. |
| Next sign-in | useRestoreBrowserNotifications saves the browser for the new user with no prompt, while browserNotificationsEnabled is set |
Agreed with the user. The setting belongs to the browser. |
| Status check | GET /api/push-subscription?endpoint= is read-only |
Opening a page never claims the browser. Only Enable and the sign-in restore save a row. |
| The soft ask | The bell's inbox shows "Enable browser notifications" while nobody has enabled them in this browser | The native prompt opens only from a click, so a user who is not interested says no to Carbon, not to the browser. A browser "Block" is close to permanent. |
| Prompt snooze | Not now hides the row for 30 days in this browser; a second Not now or a Disable hides it for good | The row must not nag. Account → Notifications always keeps the setting. |
| Disable | Off for this browser, for everyone who uses it | The setting belongs to the browser. |
| Which events push | Every notification, like in-app | Agreed with the user. In-app-only events push too, including the repeated IntegrationSync alert. |
| Digests | One push per notify call; no push from the digest cron |
Agreed with the user. The cron only regroups delivered rows. |
| Where the VAPID keys come from | Derived from SESSION_SECRET with HKDF-SHA256. The subject is the app URL when it is https, else mailto: + SUPPORT_EMAIL. |
Agreed with the user: env vars were too much to manage. A pair generated at build time was rejected: images are published per commit, so it would rotate on each build and ship the private key. Without SESSION_SECRET (a SKIP_ENV_VALIDATION script) there is no push channel. |
| Dead subscription | send-push deletes the row on HTTP 404 or 410. On 401 or 403 it logs a warning and keeps the row. |
Agreed with the user. 404 and 410 mean that the subscription is gone for good. 401 and 403 usually mean another VAPID key, but Apple also sends 403 when it refuses our token, so a delete could remove every Safari row. |
| Retries | Retry on 429 and 5xx; no retry on other 4xx | A 4xx other than 404, 410 and 429 is a bad request, and a retry fails again. |
| Delivery options | TTL = 86 400 s (1 day), urgency = normal |
A notification older than 1 day is old news. The bell still has it. |
| Fan-out shape | notify sends one carbon/send-push event per subscription row |
Same pattern as carbon/send-email and carbon/send-slack. Each browser retries on its own. |
| Service worker | New file apps/erp/public/push-worker.js, scope /; the old serviceWorker.js is deleted |
The old file cached logos and avatars, and that behavior was never live. A browser allows one worker per scope, so registering it at / later would have replaced push-worker.js and stopped every push. |
| Worker updates | skipWaiting() on install and clients.claim() on activate |
The worker caches nothing, so a new version can take over at once. |
| Repeated pushes | The worker never passes tag to showNotification. It closes older notifications with the same data.tag, then shows the new one under a fresh identifier. |
The browser gives the tag to macOS as the identifier, and macOS replaces a notification with the same identifier silently. renotify does not help. |
| Rotated subscription | The worker handles pushsubscriptionchange. It subscribes again and sends the new subscription with the old endpoint. |
A browser can rotate the subscription at any time. Without this step, push stops with no signal. |
| Focused tab | The worker always shows the notification | Chrome requires a visible notification for each push (userVisibleOnly: true). |
| VAPID public key in the browser | The settings loader and the app shell loader (pushPublicKey) return it. It is not in window.env. |
The server derives the pair, and returns null when it has none. |
| MCP exposure | The new service functions have no @mcp tag |
A browser subscription is meaningless to an API caller (conventions-services.md). |
| Env group | New group push in FEATURES, with all 3 vars needed |
validateEnv then warns when push is half-configured. |
Data Model Changes
- A new table,
pushSubscription, one row per endpoint (migration20261008002726).notificationPreferencedoes not change: push is not a preference channel. - A new rule in
packages/database/src/authz/manifest.ts, and the generated authz migration20261008002814. No migration holds aCREATE POLICY.
erDiagram
user ||--o{ pushSubscription : "owns"
company ||--o{ pushSubscription : "enabled from"
pushSubscription {
text id PK
text userId FK
text companyId FK
text endpoint UK
text p256dh
text auth
text userAgent
timestamptz createdAt
timestamptz updatedAt
}
The table:
CREATE TABLE "pushSubscription" (
"id" TEXT NOT NULL DEFAULT xid(),
"userId" TEXT NOT NULL,
"companyId" TEXT NOT NULL,
"endpoint" TEXT NOT NULL,
"p256dh" TEXT NOT NULL,
"auth" TEXT NOT NULL,
"userAgent" TEXT,
"createdAt" TIMESTAMPTZ NOT NULL DEFAULT now(),
"updatedAt" TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT "pushSubscription_pkey" PRIMARY KEY ("id"),
CONSTRAINT "pushSubscription_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "pushSubscription_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "pushSubscription_endpoint_key" UNIQUE ("endpoint")
);
ALTER TABLE "pushSubscription" ENABLE ROW LEVEL SECURITY;
CREATE INDEX "pushSubscription_userId_companyId_idx"
ON "pushSubscription" ("userId", "companyId");
CREATE INDEX "pushSubscription_companyId_idx"
ON "pushSubscription" ("companyId");
Manifest rule (same as notificationPreference):
pushSubscription: policies({
select: and(owner("userId"), member("companyId")),
insert: and(owner("userId"), member("companyId")),
update: { using: owner("userId"), check: and(owner("userId"), member("companyId")) },
delete: and(owner("userId"), member("companyId"))
}),
The table holds no business data, so the demo datasets need no change. wipe.ts finds tables by their companyId column. pushSubscription is in SECRET_TABLES (packages/jobs/src/backups/schema.ts): a backup never carries a browser's endpoint and keys, and an in-place restore leaves the current browsers alone. pnpm db:check:backups passes.
API / Service Changes
@carbon/notifications
No change to the destinations or the preference channels. Push is neither a NotificationDestination nor a NotificationPreferenceChannel: it mirrors in-app.
@carbon/env
- Add
packages/env/src/push.server.ts(export@carbon/env/push.server, server-only because it importsnode:crypto).deriveVapidDetails(secret, appUrl)is the pure derivation;getVapidDetails()memoizes it forSESSION_SECRET. isPushConfigured()returns true whengetVapidDetails()is not null.
@carbon/lib
- Add the event
"carbon/send-push"toEventswithdata: { subscriptionId, userId, companyId, title, body, url, tag }.userIdis the recipient, andcompanyIdis the notification's company. - Do not add
"send-push"to thetriggermap. Onlynotifysendscarbon/send-push, withstep.sendEvent.
@carbon/auth
session.server.tsexportspushEndpointCookie: the signed,httpOnlycookiecarbon-push, on the session cookie's domain, with a 400-daymaxAge.clearAuthCookiesreads the cookie. If it holds an endpoint, it deletes everypushSubscriptionrow of that endpoint with the service role, then clears the cookie. A cross-site navigation (Sec-Fetch-Site: cross-site) skips this, per the GET-write rule inpackages/auth/AGENTS.md: the login loader runs it on a GET.- The service-role client loads inside that cleanup, not at module load, so importing the session module builds no Supabase client.
- If the delete fails, sign-out still succeeds and the error goes to the log. The next 404 or 410 removes the row.
@carbon/jobs
- Add
web-push(and@types/web-pushas a dev dependency). - Change
notify.ts:- Compute
wantsPush:isPushConfigured(). The stepfilter-recipients-by-preferencestays as it was: it filters email and Slack only. - Add the step
resolve-push-subscriptions. It reads thepushSubscriptionrows of every recipient (userIds, the same list as the in-app rows) whoseupdatedAtis within a session's lifetime (pushSessionMaxAgeMs: 12 h in a controlled environment, the 7-day session cookie elsewhere), and builds onecarbon/send-pushevent per row, with the row'suserId. - Send the events with
step.sendEvent("fan-out-push", …).
- Compute
- Add
send-push.ts(function idsend-push, 3 retries):- Read the row by
subscriptionIdanduserIdwith the service role. If no row matches, return: the browser was disabled, signed out or handed to another user since the fan-out. - Call
webpush.sendNotificationwith the VAPID details,TTL: 86400andurgency: "normal". - If the status is 404 or 410, delete the row and return.
- If the status is 401 or 403, log a warning with the push service's body and keep the row. WNS (401) and FCM (403) send these for a subscription made with another VAPID key. Apple sends 403 when it refuses our token, which hits every Safari row, so the row is never deleted on these codes.
- If the status is 429 or 5xx, throw, so that Inngest retries.
- For any other error, throw
NonRetriableError. - Put the status code on the step output, so the run record shows it.
- Read the row by
- Register
sendPushFunctioninpackages/jobs/src/inngest/index.ts. - Put the error-to-action mapping in the pure function
pushDeliveryOutcome(statusCode), with a unit test.
ERP
account.models.ts:- Add
pushSubscriptionValidator:{ endpoint: url, keys: { p256dh, auth }, oldEndpoint?: url }, andpushSubscriptionEndpointValidator:{ endpoint: url }.
- Add
account.service.ts, with no@mcptag:getPushSubscription(client, { userId, endpoint })upsertPushSubscription(client, { userId, companyId, endpoint, p256dh, auth, userAgent }),onConflict: "endpoint"deletePushSubscription(client, { userId, endpoint })deleteBrowserPushSubscriptions(client, { endpoint, exceptUserId? }): every user's rows for a browser endpoint. The route passes the service-role client.
- The resource route
apps/erp/app/routes/api+/push-subscription.ts, gated byrequirePermissions(request, {}). If push is not configured,GETreturns{ enabled: false }and every write returns 404.GET ?endpoint=: return{ enabled }for the signed-in user. If the row exists, set thecarbon-pushcookie again, so a row saved before the cookie existed still ends at sign-out.PUT: validate the body. IfoldEndpointis set, delete that row. If thecarbon-pushcookie names a different endpoint, delete that endpoint's rows (service role): it is this browser's previous subscription. Delete the rows of other users with the same endpoint (service role). Upsert the row. Set thecarbon-pushcookie.DELETE: delete the row of this user and endpoint. Clear the cookie.
- The app shell loader (
x+/_layout.tsx) returnspushPublicKey, which isnullwhen push is not configured.
UI Changes
apps/erp/public/push-worker.js (new)
install:skipWaiting().activate:clients.claim().push: parse the JSON payload. If it has atag, close the shown notifications whosedata.tagmatches. CallshowNotification(title, { body, icon: "/carbon-mark-dark.png", data: { url, tag } }).notificationclick: close the notification. Find a window client on the same origin that the worker controls, then focus it and navigate it todata.url. If no client exists, or the focus or the navigation fails, callclients.openWindow(data.url).navigate()rejects for a client the worker does not control.pushsubscriptionchange: takeevent.newSubscription, else the registration's current subscription, else subscribe again with the old subscription's key. If none exists, stop.PUT /api/push-subscriptionthe result, witholdEndpointonly when an old subscription exists.
The icon is /carbon-mark-dark.png, the file that the ERP's site.webmanifest names.
apps/erp/app/utils/push.ts (new)
urlBase64ToUint8Array: converts the base64url public key forpushManager.subscribe().- The bell row's snooze:
parsePromptDismissal,isPromptSnoozed,nextPromptDismissal,readPromptDismissalanddismissBrowserNotificationsPrompt. They keepbrowserNotificationsPromptin localStorage, per browser. - The browser setting:
rememberBrowserNotifications(on)andareBrowserNotificationsEnabled()keepbrowserNotificationsEnabledin localStorage. restoreStepdecides what a page load does:remember,saveorskip.push.test.tscovers the key conversion, the snooze rules andrestoreStep.
apps/erp/app/hooks/usePushSubscription.ts (new)
usePushSubscription({ publicKey }) returns one state and 2 actions:
| State | Meaning |
|---|---|
unsupported |
No serviceWorker, PushManager or Notification in window. Safari on iPhone or iPad without "Add to Home Screen" is in this state. |
denied |
Notification.permission === "denied" |
off |
The browser has no subscription, or the signed-in user has no row for it (GET status check) |
on |
The browser has a subscription and the signed-in user owns its row |
Actions:
turnOn(): request permission, register/push-worker.js, subscribe withuserVisibleOnly: true,PUTthe subscription, then setbrowserNotificationsEnabled. If the browser's subscription was made with an older VAPID key,subscribeunsubscribes it first and thePUTcarries its endpoint asoldEndpoint.turnOff():DELETEthe row, unsubscribe in the browser, then clearbrowserNotificationsEnabled.
useRestoreBrowserNotifications({ publicKey, userId }) runs once per tab and user:
- If permission is not
granted, clearbrowserNotificationsEnabledand stop: the user revoked or reset it in the browser, so the bell may ask again. - If the browser has a subscription and the user owns its row, set
browserNotificationsEnabled. - If neither the user owns the row nor
browserNotificationsEnabledis set, stop. - Subscribe (replacing a subscription made with an older VAPID key), then
PUTit for the user signed in now. This runs on every tab load, also when the row exists: the save refreshesupdatedAt, whichnotifyreads to skip browsers whose session has ended.
The bell (Layout/Topbar/Notifications.tsx, EnableBrowserNotifications.tsx)
- The bell calls
useRestoreBrowserNotifications. The bell is always mounted, so every page load in a tab reaches it. - The inbox tab shows a row above the list or the empty state. Its title is "Enable browser notifications", and its text is "Get your Carbon notifications as they happen." Its buttons are Enable and Not now.
- The row shows only when all 4 conditions are true:
- Push is configured.
- Permission is not
denied. browserNotificationsEnabledis not set.- The prompt is not snoozed.
- The row hides itself when its status check says the user is already on.
Account → Notifications (x+/account+/notifications.tsx)
- The loader returns
push: { publicKey } | null. The value isnullwhenisPushConfigured()is false. - If
pushis not null, the card Browser notifications sits above the topic table:off: the text "Get your Carbon notifications as they happen." and the button Enable.on: the text "Browser notifications are on for this browser." and the button Disable.denied: the text "Notifications are blocked for Carbon in this browser's site settings."unsupported: the text "This browser does not support push notifications. On iPhone or iPad, add Carbon to the Home Screen first."
- Disable also snoozes the bell row for good.
- The topic table keeps only its Email and Slack columns: push has no per-topic switch.
- All new strings use Lingui macros, and
/translatefilled the 12 other locales.
Other
No change to MES or to useNotifications. AvatarMenu.tsx is unchanged: sign-out cleanup lives in @carbon/auth.
Acceptance Criteria
- A user clicks Enable at Account → Notifications and allows the prompt. The card says "Browser notifications are on for this browser".
- After Enable, the database has exactly 1
pushSubscriptionrow for that endpoint, owned by the user. The browser has thecarbon-pushcookie. - A second notification about the same job shows a second banner, not a silent replacement.
- With every Carbon tab closed and the browser still running, assigning a job to the user shows "Job assigned to you". A click opens the job.
- A user who belongs to 2 companies gets the push of a job assigned in each company, whichever company is open.
- The topic table has no Browser column. Every notification, of every topic, pushes to each enabled browser of its recipient.
- An
IntegrationSyncnotification creates an in-app row and also pushes, like every in-app notification. - After sign-out, the endpoint has no row and the next assignment to the previous user sends no push to that browser.
- Another user signs in to that browser. The browser gets that user's notifications with no prompt, and none of the previous user's.
- Disable deletes the row and clears
browserNotificationsEnabled. The next user to sign in gets no push and no bell row. - The bell shows "Enable browser notifications" only while nobody has enabled them in this browser. Not now hides it for 30 days.
- With no
SESSION_SECRET(getVapidDetails()is null), Account → Notifications shows no card, and the bell shows no row.notifysends nocarbon/send-pushevent and does not fail. -
pushDeliveryOutcomehas unit tests for 201, 404, 410, 413, 429 and 503.push.test.tscovers the snooze rules. -
notificationPreferenceValidatoraccepts onlyemailandslack. - Scoped typecheck passes for
@carbon/auth,@carbon/jobs,@carbon/notifications,@carbon/env,@carbon/lib,erpanddocs. Biome passes.migration.test.tspasses.
Risks
| Risk | Severity | Mitigation |
|---|---|---|
| A session that ends without any sign-out path keeps its row | Low | Bounded: every page load saves the row again, and notify skips rows older than a session's lifetime (12 h in a controlled environment, the 7-day session cookie elsewhere). The next visit's login page or sign-in also replaces it. |
| The login loader runs the push cleanup on a GET | Low | A cross-site navigation skips it, which is what the GET-write rule guards against; such rows lapse through the updatedAt cutoff. |
Changing the VAPID key pair (rotating SESSION_SECRET) breaks every subscription |
Low | The next page load replaces a subscription made with an older key (hasApplicationServerKey), and the settings card shows it as off until then. A push to an old-key row gets 401 or 403, and send-push logs a warning and keeps the row. The browser's next page load replaces it, or it ages out after a session's lifetime. |
| If the user revokes the permission in the browser, the browser-wide flag would stay set | Low | Fixed: the restore clears browserNotificationsEnabled whenever permission is not granted, so the bell can ask again. |
Safari can refuse pushManager.subscribe() without a user click, which the restore needs only when the browser lost its subscription |
Low | The restore logs the error. Enable still works. |
| Safari on iPhone or iPad supports push only for a Home Screen web app | Low | The unsupported text says so. The manifest already has display: standalone. |
IntegrationSync pushes every sweep: the outbound sweep runs every 30 minutes (15,45 * * * *) and, while failures remain, notifies the integration's last editor (updatedBy) |
Low | Accepted by the user: push mirrors in-app exactly. notify.ts documents it on the IntegrationSync default. |
| A recurring reminder (weekly training) pushes every cycle; email has a delivery cap, push does not | Low | The same notification is also in the bell each week. |
Company backups would carry pushSubscription rows |
Low | Fixed: the table is in SECRET_TABLES, so it is never exported and an in-place restore keeps the current rows. |
| A strict CSP later blocks the worker | Low | The strict policy already allows worker-src 'self' (packages/auth/src/lib/security.ts). |
| A large group notification sends many push events | Low | One event per browser, the same scale as the email fan-out. Inngest queues the events. |
web-push is a new production dependency |
Low | The user approved it. It is the reference library of the Web Push standard. |
Open Questions
- Should push need a paid plan? — Answer (user): No. Push is free on all plans.
- Which library sends the push? — Answer (user):
web-pushin@carbon/jobs. - Which apps get push? — Answer (user): ERP only.
- How does a user opt in? — Answer (user): At Account → Notifications. A "Browser" switch per topic came first; the user later removed it, so push mirrors in-app. Later the user also added the bell's "Enable browser notifications" row, with the copy of option A.
- Do digests push? — Answer (user): One push per notification at creation. No digest for push.
- What happens without VAPID keys? — Answer (user): Carbon skips the channel and hides the controls. Superseded 2026-10-09: the keys are derived from
SESSION_SECRET, so only a process without one has no channel. - What happens to a dead subscription? — Answer (user): Carbon deletes it on 404 or 410.
- Is a subscription per user or per user and company? — Answer (user, replaces the first autonomous answer "per user and company"): The signed-in user gets the notifications of every company they belong to. One row per browser endpoint.
- What happens on sign-out? — Answer (user): Signing out stops the notifications in that browser, on every sign-out path.
- Is the setting per user or per browser? — Answer (user): Per browser. Once enabled, whoever signs in gets their own notifications.
- Which events push? — Answer (user, replaces the first autonomous answer "destinations with Push, Email or Slack"): Every notification, exactly like in-app, including in-app-only events.
- How does the user check that push works? — Autonomous at first: a "Send a test notification" button. Answer (user, later): remove it; a real notification is the check.
- What happens when the browser rotates a subscription? — Autonomous:
push-worker.jshandlespushsubscriptionchangeand sends the new subscription. - Should Carbon register the existing
serviceWorker.js? — Autonomous: No. A newpush-worker.jsholds only the push handlers. Later (user, 2026-10-09): deleteserviceWorker.js. - Should Carbon skip the push when a Carbon tab has focus? — Autonomous: No. Chrome requires a visible notification for each push.
Changelog
- 2026-10-08: Created by the autonomous
/featurerun (.ai/runs/2026-10-08-web-push-notifications.md). The user answered 7 questions before the run. The run resolved the other 7 itself and marks them Autonomous above. - 2026-10-08: Implemented on
naveenkash/carbon-browser-notifications. The test POST route setstagtocarbon-test, so a second test replaces the first. - 2026-10-08: Two changes after testing:
push-worker.jsno longer passestagtoshowNotification. Edge gives the tag to macOS as the notification's identifier, and macOS replaces a notification with the same identifier silently, so no banner appears. The worker closes older notifications with the samedata.tagitself, then shows the new notification under a fresh identifier.- The bell's inbox tab shows an "Enable browser notifications" row (
EnableBrowserNotifications.tsx). It is the soft ask: the native prompt opens only from its Enable click. The settings card is now titled "Browser notifications", with Enable and Disable buttons.
- 2026-10-08: A subscription now belongs to the browser and the user signed into it, not to one company.
endpointbecame unique: one row per browser. A second migration did this at first; before release it was folded into20261008002726.notifyreads subscriptions byuserIdonly, so a user gets the push of every company they belong to.- Signing out stops pushes on every path, through the
carbon-pushcookie andclearAuthCookies(@carbon/auth). The change removes the client-side unsubscribe fromAvatarMenu. - Opening a page never claims the browser: the hook reads
GET /api/push-subscription?endpoint=.
- 2026-10-08: Browser notifications became a setting of the browser (
browserNotificationsEnabled).useRestoreBrowserNotificationssaves the browser for each user who signs in. Not now and Disable snooze the bell row per browser. - 2026-10-08: The spec body was rewritten to match the shipped design. The earlier sections described the per-company rows, the "This device" card and the AvatarMenu unsubscribe.
- 2026-10-08: Two changes from self-review:
VAPID_SUBJECTnow has atypeinpackages/env/src/schema.ts.validateEnvreports a subject that does not start withmailto:orhttps://at startup, not on each send.restoreStep(apps/erp/app/utils/push.ts) holds the decision ofuseRestoreBrowserNotifications:remember,saveorskip.push.test.tscovers the 3 cases.
- 2026-10-08: From the third self-review:
carbon/send-pushcarries the recipient'suserId, andsend-pushsends only when the row still belongs to that user. The guarantee "only the recipient's browser" is now a check, not a result of how ids are assigned.- The 2 unreleased migrations are one:
20261008002726createspushSubscriptionwithUNIQUE ("endpoint").
- 2026-10-08: From the CodeRabbit review of PR #1867:
pushsubscriptionchangeno longer gives up whenoldSubscriptionis null. The Push API makes both subscriptions nullable.endBrowserPushbuilds the service-role client inside itstry, so sign-out still clears its cookies when the client cannot be built.- A workflow push takes its author's subject as the title and their message as the body.
packages/database/AGENTS.mddocuments the user-owned preference rows (notificationPreference,userModulePreference,pushSubscription) as an exception to the table template.
- 2026-10-08: Push mirrors in-app, at the user's request. The per-topic Browser switch is gone. Push is no longer a
NotificationDestinationor aNotificationPreferenceChannel, andwantsPushDeliveryis removed.notifypushes to every recipient of the in-app row, so in-app-only events such asIntegrationSyncpush too. ThenotificationPreferenceCHECK still allowspush, unused. - 2026-10-08: The "Send a test notification" button is removed, at the user's request: the card's
onstate shows only Disable,usePushSubscriptionhas nosendTest, and/api/push-subscriptionhas noPOSTbranch. - 2026-10-08: Risk fixes from the fourth self-review:
- Every page load saves the browser's row again (
updatedAt).notifyskips rows older than a session's lifetime, so a session that ends without a sign-out stops getting pushes within that window. clearAuthCookiesskips the push cleanup on a cross-site navigation (the GET-write rule).- A subscription made with an older VAPID key is replaced on the next page load or Enable, and its old row is deleted.
- The restore clears
browserNotificationsEnabledwhen permission is no longergranted. pushSubscriptionjoinedSECRET_TABLES, so backups never carry it.- The migration no longer widens the
notificationPreference.channelCHECK.
- Every page load saves the browser's row again (
- 2026-10-09: The VAPID env vars are gone, at the user's request.
getVapidDetails()(@carbon/env/push.server) derives the pair fromSESSION_SECRETwith HKDF-SHA256, so push works on every deployment with no setup.VAPID_PUBLIC_KEY,VAPID_PRIVATE_KEY,VAPID_SUBJECTand thepushenv group are removed. RotatingSESSION_SECRETrotates the pair; each browser re-subscribes on its next visit.deriveVapidDetailsis pinned bypackages/env/src/push.server.test.ts. - 2026-10-09: Two fixes from a manual test:
pushDeliveryOutcomemaps 401 and 403 torejected. WNS answered 401 for a subscription made with the old env-var key, andsend-pushfailed on it for each notification. Nowsend-pushlogs a warning and completes. It keeps the row, at the user's request: Apple sends 403 for a token it refuses, and a delete would remove every Safari row.notificationclickuses only the tabs the worker controls, and opens a new window when the focus or the navigation fails. Before,navigate()rejected on an uncontrolled tab and the click opened nothing.PUT /api/push-subscriptiondeletes the endpoint that thecarbon-pushcookie remembers when it differs from the new one. A browser that lost its subscription makes a new one with nooldEndpoint, and its old row waited for a failed push.deriveVapidDetailshas a known-answer test, cross-checked with OpenSSL. A change to the hash, the salt or the info label changes every deployment's key, so the test fails.
- 2026-10-09: Cleanup from self-review. The
"send-push"entry left thetriggermap: nothing called it, and onlynotifysends pushes.pushDeliveryOutcomelost itsdeliveredresult, because web-push throws only for a non-2xx status.supportsPushmoved toapps/erp/app/utils/push.ts, so the bell row and the hook share one check. The route's two service-role deletes becamedeleteBrowserPushSubscriptions. The push cookie and the session cookie share one options object. - 2026-10-09:
apps/erp/public/serviceWorker.jsis deleted, at the user's request. No code registered it. Registered at scope/, it would replacepush-worker.js. - 2026-10-22:
push-worker.jsis renamedservice-worker.js(SERVICE_WORKER_URL,apps/erp/app/utils/service-worker.ts). It also serves the offline page, so every page load registers it, not only Enable. A browser keeps one registration per scope, and the push subscription with it, so the rename keeps existing subscriptions. Each push now carriesbadge, the unread count for the installed app's icon. See.claude/rules/service-workers.md.