usage.threshold) can become a Web Push notification. One sink in cloud-api reads the backbone and decides per person and event type. Preferences are stored per person, not per device.
Routes
Clerk session or acompute-scoped API key.
GET /api/v1/notifications/preferences
approval.requested, approval.resolved, agent.run.completed, thread.needs_user, message.received, agent.message.sent, call.ended, inbox.item.created, vendor.ticket.created, subscription.login_needed, subscription.signed_in, usage.threshold, attention.opened, attention.resolved. title and description come from the registry (the same titles as GET /api/v1/events/catalog), so a client renders switches without its own copy. default is what enabled is when the person hasn’t changed it. pushConfigured: false means the server has no VAPID keys, so nothing is sent whatever the switches say.
PUT /api/v1/notifications/preferences
true / false sets a type; null puts it back to its default. The change is all or nothing. Answers the same body as GET. Errors: 400 {"error":"unknown_event"} for a name that isn’t a notifiable event type (platform-only types such as message.status included), 400 {"error":"bad_value"} for an empty map or a value that isn’t true, false or null.
GET /api/v1/notifications/quiet-hours
start and end are 24-hour HH:MM in timeZone (an IANA zone such as America/New_York), so the window follows daylight saving time. start later than end wraps midnight; start equal to end means no quiet hours. letThrough is the lowest level that still goes out during quiet hours: urgent (the default), needs_you or none.
PUT /api/v1/notifications/quiet-hours
GET keys; the rest keep their stored (or default) values. Answers the same body as GET. Errors: 400 {"error":"bad_value"} for an empty body, an unknown key, a time that isn’t HH:MM (00:00 to 23:59), an unknown time zone, a letThrough other than urgent, needs_you or none, or a value of the wrong type.
POST /api/v1/notifications/ack?t=<token>
No auth: the token is the credential, and it was only sent to that person’s devices. Marks an urgent push sent during quiet hours as opened, so it stops repeating (paging). The push worker (public/allternit-push-sw.js) calls it with mode: "no-cors" when the notification is clicked, or when the push arrives while the app is open in front. Always answers 204, also for an unknown token.
Defaults
message.received and call.ended default on because the app already pushed messages and missed calls before the sink existed.
Finished runs. With no switch set, agent.run.completed pushes only when the run failed (status failed, error, timeout) or ran 2 minutes or longer (durationMs, durationSec or duration_s). A shorter successful run, or one with no duration, does not push; on the iPhone the Live Activity’s end state covers it. Turned on explicitly, every finished run pushes. Turned off, none does.
The push sink
cmd/allternit-cloud-api/src/routes/notifications.rs, started from main.rs only when the VAPID env is set. Every 3 seconds it reads user events (platform_events, subject = 'user') stored in the last 10 minutes that it hasn’t seen, and for each one:
- claims it in
notification_push_log(INSERT … ON CONFLICT DO NOTHING), so a restart, a second replica or a rescan never pushes it twice; - skips it when it happened at the producer more than 12 hours ago;
- checks the owner’s preference, and for
agent.run.completedwith no switch set, the finished-run rule; - builds the notification (copy and links) and adds
eventId; - for
message.received, applies the message limits (one per conversation per 20 seconds, 40 an hour) and skips it when a direct channel push went to the same person in the last 2 minutes (see below); - holds it when the owner is in quiet hours;
- sends it to every device the owner registered (a coding-session permission ask to iPhones only, see below), and records
sent,off,unreachable(no device took it),skippedorheld.
060_notification_preferences.sql adds notification_preferences, notification_push_log and an index on platform_events (created_at) WHERE subject = 'user'. It is applied by hand to production, after 057.
Copy and links
The payload is the Web Push JSON withtype: "event" ("message" for message.received) and the data keys below. Links use the push-links scheme: /?allternit_thread=<threadId>&bot=<botId> when the event has both, /?allternit_channel=<provider> for a message without a thread, / otherwise.
Answer pages. A
thread.needs_user event whose data.url is an https://artifacts.allternit.com/… link (with page_id) is an agent waiting on an answer page: the notification opens that page as is, fragment included (the page’s reply key rides in it), and its tag is needs-page-<page_id>. Any other url is ignored. The answer-me-with-html relay on a paired Mac sends these through POST /api/v1/runtime/events when a plan page or a page with open decisions has not been opened for 90 seconds.
<bot> is the forwarded botName, or “Your bot”.
Coding-session permission asks (approval.requested with source: "gizzi-permission") reach browsers through the gizzi remote-control lane (services/remote-control-push). The sink sends them to iPhones only (APNs), never as a second Web Push.
Data keys
Every sink push carries these indata, for the service worker and the iPhone app alike:
A push for an inbox item uses the item as its
tag (approval:ap1 becomes approval-ap1), so its other pushes replace it. An approval’s link is /?allternit_inbox=<inboxId> (URL-encoded), which opens that item.
Categories
The category comes from the runtime’sinboxKind first, then the event name, so an email draft that arrives as thread.needs_user still gets approval buttons.
An approval with no
inboxId (an older runtime) gets no category: there is nothing for a button to act on. Buttons act through the runtime’s inbox routes (POST /api/v1/inbox/:id/approve, dismiss, snooze) over the relay; cloud has no approve route of its own.
Direct pushes
These don’t go through the sink, because the backbone carries no event for them:
A message relayed to a runtime through a channel address (
channel_inbound) used to be pushed directly. The runtime records the same message and forwards it as message.received, so now the direct push only goes out for a runtime that has never forwarded an event (an older build), and follows the message.received preference. Once a runtime forwards, the sink sends it, with the sender and text. While the sink isn’t working (VAPID unset, or migration 060 not applied yet) every relayed message keeps its direct push. For the one message where both could fire (the first event a runtime ever forwards), the sink sees the direct push in push_log and skips its own.
Focus filter
PUT /api/v1/notifications/focus
Clerk session or compute-scoped API key. The iPhone app sends it when a Focus with the Allternit filter turns on or off, and again on foreground and background refresh to confirm it.
{ok: true, deviceId, focus}. allowedBotIds may be null, which means no bot is allowed. allowApprovals is optional (default true). Errors: 400 bad_value (missing deviceId or active, wrong types, more than 200 bots), 404 unknown_device (no iPhone with that deviceId registered for this person).
While the filter is active and was confirmed in the last 24 hours, alerts to that iPhone from bots not in allowedBotIds, and alerts with no bot, arrive with interruption-level: passive and no sound. Nothing is dropped. Approvals keep their normal level when allowApprovals is true. Stored on the device row (apns_device_tokens.focus, focus_at; migration 120_ios_system_surfaces.sql).
Status snapshots and revoke
The runtime forwardsstatus.snapshot through POST /api/v1/runtime/events whenever its status changes (at most one per 5 seconds). It is never a notification and never a backbone event. Cloud keeps the latest per runtime in status_snapshots with a content hash; the same content again answers duplicate. GET /api/v1/status/summary serves them (iPhone push).
The fields cloud reads today: needsYou (a list of inbox ids). The rest (activeBots, attentionBots, pendingApprovals, paused, focus, bots, needsYouRows, loops, lastRoutine) is stored as sent, for the Live Activity, widget and summary.
When a sink push for an inbox item reaches at least one iPhone, cloud records the tag in notification_delivered. On each new snapshot, every inbox id that was in the previous needsYou and is not in this one (answered on another device, on the web, or it expired) has its delivered tags removed from the person’s iPhones by a background push, and the rows are deleted. Web Push gets no revoke push: an open page closes its own notifications, and Safari drops subscriptions that receive silent pushes.
Agent messages
agent.message.sent (“Messages from your agents”) is written when an agent calls send_user_message with a push. It is on by default, at level Normal, so quiet hours hold it, and it is private by default. It takes the AGENT_MESSAGE category and shares the per-thread message limiter with message.received. Agent pushes are also limited at the source to 4 per thread per hour and 20 per user per day. The 12-hour stale rule above applies. A runtime that is not linked to the person’s account forwards nothing, so an unpaired runtime never pushes. An incognito chat never pushes. Tapping the push opens the thread or session.
Scheduled-task approvals
When a scheduled run started by the local API scheduler stops at an approval, the scheduler raises one attention item (needs you, with Retry). The runtime seesautomation_run.by equal to scheduler and sends no second notice. A run started by gizzi’s own /cron fallback has no by and notifies from the runtime. See automation.
Quiet hours
Levels
Every push has a level (notifications::level):
While a person is in quiet hours (their
notification_quiet_hours row is on and the current time in their zone is inside the window), a push below their letThrough level is not sent:
- the sink records the event as
heldinnotification_push_logand adds a row tonotification_held(event_idunique, so a restart or second replica never holds it twice). Preferences, staleness and the direct-push dedupe are checked first, so only pushes that would have gone out are held. Message limits aren’t spent on held messages; - the direct pushes (in-app thread messages, in-app missed calls, relayed channel messages) add a
notification_heldrow (source = 'direct') instead of sending; - in-app call rings still ring when
allowCallsis true. When it is false the ring sends nothing, and the missed call that follows is held; - with
letThrough: "none", critical problems are held too, and named first in the summary.
Paging
An urgent push that goes out during quiet hours pages. The sink records it innotification_repeat with a random ack_token and adds data.ack, the full URL of POST /api/v1/notifications/ack. About once a minute the sink loop claims due rows (acked_at empty, next_at passed, fewer than 3 resends) in one UPDATE … FOR UPDATE SKIP LOCKED … RETURNING and sends each one again with Urgency: high (the worker shows it with renotify, so it alerts again). Resends come every 5 minutes, at most 3 times. A page stops when it is acked, when a newer page with the same tag replaces it, or when approval.resolved or attention.resolved with the same tag arrives (whether or not that event is pushed). Rows are pruned after 2 days.
About once a minute the sink loop runs the summary pass. For each person with open notification_held rows who is no longer in quiet hours, it claims all of them in one UPDATE … SET summarized_at = now() … RETURNING, so restarts and replicas never send it twice, and sends one push: title While you were away, body counting by kind (for example 3 messages, 1 approval and 2 threads need you; order: urgent problems, messages, missed calls, approvals, threads, problems, other updates), url /, tag quiet-summary, type: "event", data.event quiet.summary. Messages and missed calls count every push; the other kinds count each tag once, so a re-sent approval or problem counts once. Nothing held is re-sent on its own, so held pushes older than 12 hours are counted like the rest. Held rows are pruned after 7 days.
Migration 102_notification_quiet_hours.sql adds notification_quiet_hours and notification_held; 107_quiet_hours_levels.sql adds let_through (default urgent) and notification_repeat. Before it is applied, quiet hours read as off and every push goes out as before.
Usage alerts
The cost tracker (services/cost_service.rs, every minute) emits the usage.threshold event into the backbone when a person’s monthly cloud spend crosses their budget alert threshold, and again when it reaches 100% of the budget. Each crossing is emitted once: the event’s source id is <user>:<YYYY-MM>:<level>:<budget in cents>, so the minute-by-minute check never repeats it, a new month starts over, and changing the budget counts as a new crossing. data:
cost_alerts rows the tracker already wrote every 24 hours are unchanged.
Status holds pushes
A person’s status ofdnd, away or autopilot makes them quiet, the same as being inside quiet hours:
- A push below their saved let-through level (
letThroughin quiet hours,urgentwhen nothing is saved) is held innotification_heldinstead of sent. Urgent pushes still arrive. - An urgent push while the status holds pages, as described under Paging.
- The held summary push waits. The sink loop sends it on its first run (about once a minute) after the status is back to
onlineand quiet hours are over.