News that finds you, including when nothing of ours is open

The dots covered Reports and Messages from the day those sections existed. The
announcement did not: only a chat reply produced an HX-Trigger, so a scheduled
run that filed a report or posted into Messages lit a green dot in a corner and
said nothing at all. That is precisely the arrival nobody is watching for -- a
chat reply is one you asked for a moment ago and are probably looking at.

So every kind announces, each with its own once-only flag, and the payload is a
list of items rather than of titles, because a notification is a thing you click
and a title cannot say where.

One arrival, three channels, and they must not all fire. A toast for somebody
looking at the page; a count in the tab title while it is hidden, cleared on
focus; a system notification for somebody elsewhere entirely. The service worker
is the only place that can tell them apart -- the server cannot see whether a
window is focused and the page cannot see a push it did not receive -- so it
stays quiet when one of its own windows has focus.

And web push, hand-rolled against RFC 8291 and RFC 8292 with the cryptography
already here for Fernet. It exists because everything else is polled by an open
page, and the arrival worth interrupting somebody for is a schedule firing at
seven in the morning with the laptop shut.

The trade is real and is written down rather than glossed: the POST goes to
Google's or Mozilla's push service, the payload is sealed end to end so they
cannot read it, and what they do learn is that this server sent something and
when. Opt-in per device, off until asked for, and the rest of the system works
without it. Nothing else in LLeMbas contacts an outside service on its own.

The encryption is tested by decrypting it back with an independent
implementation of the specification's other half. There is no other way to know:
a push service accepts the POST and forwards bytes it cannot read, so a wrong
derivation is a notification that never appears, with a 201 in the log.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jaroslav Beneš
2026-08-06 11:11:04 +02:00
parent 9761082fa1
commit 54ed030732
16 changed files with 1553 additions and 22 deletions
+26
View File
@@ -122,6 +122,18 @@ def _finished_reply(db, chat_id: str, message_id: str) -> Message | None:
return message
def _preview(text: str, limit: int = 160) -> str:
"""The opening of a reply, as the body of a notification.
A notification saying "a scheduled run finished" is one somebody has to open
something to understand, which is most of the reason notifications get
ignored. Flattened to one line because a push service and an operating
system will each do their own thing with newlines.
"""
flat = " ".join((text or "").split())
return flat[: limit - 1] + "" if len(flat) > limit else flat
async def deliver(schedule_id: str, message_id: str, *, since: datetime) -> None:
"""Put a finished reply where the schedule said it should go.
@@ -215,6 +227,20 @@ async def deliver(schedule_id: str, message_id: str, *, since: datetime) -> None
conversation.unread_notified = False
db.commit()
# The arrival this whole channel exists for: a run that fired while
# nobody was here, landing somewhere they are not looking. The first
# line of the reply is the body, because "a scheduled run finished"
# is a notification you have to open something to understand.
from lembas.services import push as push_service
push_service.announce_later(
owner.id,
title=schedule.title or "Scheduled run",
body=_preview(message.content or ""),
url="/messages",
kind="message",
)
async def fire(schedule_id: str, *, due_at: datetime | None = None) -> None:
"""Run one schedule now.