mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 14:47:44 +01:00
Clicking Send and hearing nothing back is the complaint. The machinery to answer it was fully built and switched off, in three independent places. 1. NOTHING EVER SET notifyOnClose. It is plumbed through /api/inject, stored on the run payload, formatted by a pure unit-tested function — and the only caller that ever set it true was a test fixture. Every dispatch declined to announce itself. 2. THE ONE CHANNEL IT WOULD HAVE USED IS UNCONFIGURED. notifyRunClosed sent via Telegram and returned early when selfTelegramTarget() was null. In production TELEGRAM_BOT_TOKEN is set and TELEGRAM_CHAT_ID is not, so even an opted-in run would have gone nowhere, silently. 3. WEB PUSH IS WIRED TO NOTHING. VAPID keys are configured, the service worker, the subscribe route, the NotificationsPill and the use-push-subscription hook all exist — and the only consumer of the send path is the HTTP endpoint itself. The operator's installed PWA could be reached and never was. So: notifyRunClosed now delivers on EVERY configured channel rather than the first one that happens to exist, push included — the channel that actually reaches the phone of someone who dispatched and pocketed the device. The fan-out is extracted to lib/push-fanout.ts so a server-side caller does not self-HTTP its own API (same reasoning that pulled inject-core out of the route), and it reports WHY nothing was sent: "not configured" and "no subscriptions" need opposite fixes and a silent zero looks identical for both. A run that opted in and reached nobody is logged as the product failure it is. WHO GETS TOLD is the interesting decision. "UI dispatches stay silent so the fleet's normal churn never spams the phone" was protecting something real, but it assumed a UI dispatch means the operator is watching Control. They are not — they dispatched and walked away, which is the entire point of an always-on builder. The honest split is human vs machine, and that is knowable without a heuristic: getApiActor reports HOW the request authenticated. A cookie session is a person; a Bearer token is a runner, a hook, or a scheduled loop. Autopilot stays silent, a click gets an answer, and an explicit value still wins in either direction so chat can opt in and a noisy loop can opt out. The rule lives in notify-close-format.ts (pure, shared) rather than inlined at both dispatch routes, which is where it was about to become two copies that drift. Negative-tested: disabling it reproduces the shipped silence. Also fixes a source-level guard it tripped: autopilot-defaults asserted /api/inject contains the literal "getApiUserId" to prove the route still accepts a runner Bearer token. getApiActor delegates to it and satisfies the same property, so the assertion now checks the invariant instead of the name. Co-authored-by: t <t@t.t> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>