[Cron] Route scheduled notifications to the right channel (not default web)
Summary
When a user creates a scheduled / cron reminder from Telegram (e.g. “remind me to drink water”), delivery should go back to Telegram (or the channel where the request was made) — not only / not primarily the in-app web stream. Today, proactive cron delivery effectively centers web and only mirrors to an external channel if config.channels_config.active_channel is set and the runtime has a non–web-only proactive subscriber, so users on Telegram can see nothing useful in Telegram and everything in the desktop web UI instead.
Current behavior (verified in code)
-
cron_adddefault for agent jobs — Ifdeliveryis omitted, the tool usesmode: "proactive"with nochannel/to(seesrc/openhuman/tools/impl/cron/add.rstests,agent_job_defaults_to_proactive_delivery). -
Proactive routing —
ProactiveMessageSubscriber(src/openhuman/channels/proactive.rs):- Step 1: Always publishes a
proactive_messageto the web Socket.IO bus (client_id: "system") so the in-app UI always gets the event. - Step 2: If
active_channelis set and is not"web", alsosends on the matching externalChannel(e.g. Telegram) from the registered map. - The desktop / JSON-RPC path can register a
web_only()subscriber (channels_by_nameempty), in which case no external delivery exists at all.
- Step 1: Always publishes a
-
Explicit channel delivery already exists —
DeliveryConfigsupportsmode: "announce"withchannel+to;deliver_if_configuredinsrc/openhuman/cron/scheduler.rsemitsCronDeliveryRequested(see comments for “announce” vs “proactive”). The gap is defaults and agent/tool context, not a missing struct field. -
“Active channel” —
config.channels_config.active_channel(seesrc/openhuman/config/schema/channels.rs) is the global knob the proactive path uses. It is not the same as “I’m talking to the bot on Telegram right now” unless we set it from user behavior or persist the origin on the job.
Problem
- Wrong default UX: A reminder “born” in Telegram should not require the user to discover web-only notifications or a global active_channel setting.
- Inconsistent with intent: The user’s mental model is “this reminder lives in this chat” — the product should support per-job delivery or origin-based defaults.
- Security surface: Any
to(chat id) forannouncemust be authorized (same user / allowed list) to avoid cross-user sends.
Solution direction (product + engineering; pick/merge)
-
Per-job “reply channel” (preferred for clarity)
- When the agent / user schedules from channel context (e.g. Telegram inbound dispatch), pass default delivery into
cron_addasannounce(or a newmode: "same_as_origin") withchannel=telegramandto= verified chat / thread id from the inboundChannelMessage(or stored binding for that user). - Tool schema / prompts should say: default deliver to the channel you’re using unless the user names another.
- When the agent / user schedules from channel context (e.g. Telegram inbound dispatch), pass default delivery into
-
Inherit on create
- Extend the tool pipeline so
cron_addreceivessource_channel+source_reply_targetin JSON-RPCparamsfrom the channel layer (only when the tool is invoked from a channel turn), and persist them onCronJob(may require a small schema addition if not folded intodelivery).
- Extend the tool pipeline so
-
Smarter
proactive- Option A: For jobs created from an external channel, skip the always-on web
proactive_message(or make it opt-in) and deliver only to the stated channel. - Option B: Keep dual deliver (web + external) but reorder so the origin channel is first and the primary UX in logs/docs.
- Option A: For jobs created from an external channel, skip the always-on web
-
Active channel
- On inbound Telegram message, optionally auto-
set_active_channel(Some(\"telegram\"))) (with user consent in settings) so existing proactive jobs behave better without schema changes (weaker than per-job routing).
- On inbound Telegram message, optionally auto-
-
Docs & agent prompts
- Update
cron_adddescriptions so the model setsannounce+channel+tofor Telegram-originated reminders when the user asks for Telegram delivery; documentchannels_config.active_channelfor proactive.
- Update
Acceptance criteria
- [ ] A cron/reminder created from Telegram (test harness or manual) delivers to that Telegram chat by default, without requiring the user to use the desktop “web” view as the only surface.
- [ ] No unauthenticated or cross-tenant
to—announcetargets are validated against the same user’s bindings /allowed_users(reuse existing channel auth rules). - [ ] Config / RPC — Clear story for web-only desktop vs full channel runtime (proactive vs announce behavior documented; no silent “everything web” for channel-native flows).
- [ ] Tests — Unit or integration: cron job created with
announce+telegram+chat id delivers viaCronDeliveryRequested(mock channel) or equivalent; regression that default proactive still works for jobs that truly want in-app. - [ ] Docs — Short note in architecture or
crontool docs: delivery modes and when to use proactive vs announce.
Related files
src/openhuman/channels/proactive.rs— web-first +active_channelexternal sendsrc/openhuman/cron/scheduler.rs—deliver_if_configured(proactivevsannounce)src/openhuman/tools/impl/cron/add.rs— defaultproactivedelivery for agent jobssrc/openhuman/cron/types.rs—DeliveryConfigsrc/openhuman/channels/runtime/startup.rs—ProactiveMessageSubscriber::new/web_onlyregistration
Picking this up. Plan stays in scope: capture origin channel at cron-create time and feed it into DeliveryConfig so ProactiveMessageSubscriber routes back to the same channel (Telegram, etc.) instead of defaulting to web. Web stays as fallback when origin is unknown or the external send fails. Will also surface the target in the cron-create UI defaulting to current thread's channel.
Will open a PR against main shortly.