The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
docs(channels): rewrite the channels README around runtime behaviour
Steven Enamakel58266b4d9d9c
diff --git a/crates/openhuman-core/src/channels/README.md b/crates/openhuman-core/src/channels/README.mdindex 69a5627ca0..099135f04c 100644--- a/crates/openhuman-core/src/channels/README.md+++ b/crates/openhuman-core/src/channels/README.md@@ -1,61 +1,165 @@-# Channels+# channels-Multi-platform messaging integration. Re-exports the `Channel` trait vocabulary, owns the host glue for every provider (Slack, Discord, Telegram, WhatsApp, WhatsApp Web, IRC, Signal, iMessage, Email, Lark, Mattermost, DingTalk, QQ, Linq, Yuanbao, and the local CLI REPL), the runtime supervisor that brings channels online, inbound dispatch into the agent loop, and proactive outbound delivery. Does NOT own the channel system prompt copy (lives in `agent/context/channels_prompt.rs`; `system_prompt.rs` here owns only when it is re-rendered), per-channel credential storage (delegated to `security/credentials/`), or provider transport implementations (vendored in `tinychannels`; see below).+This domain connects OpenHuman to external messaging platforms: Slack, Discord, Telegram, WhatsApp (Cloud API and, behind a feature, WhatsApp Web), IRC, Signal, iMessage, Email, Lark, Mattermost, DingTalk, QQ, Linq, Yuanbao, and the local CLI REPL. A message that arrives on one of those platforms is turned into an agent turn, and the agent's reply is sent back to the same chat. The domain also owns the `channels.*` RPC namespace the settings UI uses to connect and test providers, and the subscriber that delivers proactive messages (briefings, cron output) to the user's chosen channel.-## Feature gate+Most provider code is not here. Transports, provider construction, capability flags, remote-control commands, in-chat approval rendering and progressive reply choreography live in the vendored `tinychannels` crate (`vendor/tinychannels/`). This folder is the host side: it supplies credentials, the agent, approvals, voice, persistence and events, and decides policy.-The domain lives behind the `channels` feature (default-ON, #4801), except two dependency-free carve-outs that always-on code reaches directly: `traits` (the `Channel`/`SendMessage` re-export, named by the always-on agent-harness interactive loop in `agent/session_host/`) and `CliChannel` (the stdin/stdout REPL that loop drives in every build, re-exported from the unconditional `tinychannels-runtime` crate). Everything else (`providers`, `host`, `controllers`, `runtime`, `bus`, `proactive`, `commands`, `context`, `routes`, `system_prompt`, the provider re-exports, `doctor_channels`, `start_channels`, `build_system_prompt` and the `test_support` re-export) is `#[cfg(feature = "channels")]`. The feature owns the optional `tinychannels` crate (`channels = ["dep:tinychannels", "tinychannels/email", "tinychannels/lark"]`); the always-on pins (config schema, the `DomainEvent` inbound envelope, security pairing) resolve through the unconditional `tinychannels-bus` contract crate instead. Measured, the gate sheds no transitive packages: its value is compile surface and binary size. `voice` also re-enables `dep:tinychannels`, for `EmailChannel` alone. The full rationale is the comment above the `channels` feature in `crates/openhuman-core/Cargo.toml`.+## How it works-## Public surface+There are two inbound paths. They look similar but run in different places.-- `pub use tinychannels_bus::{Channel, ChannelMessage, ChannelSendExt, SendMessage}` (`traits.rs`): the provider contract, sourced from the transport-free `tinychannels-bus` contract crate so it resolves even in `channels`-less builds.-- `ChannelDefinition` / `ChannelAuthMode` (re-exported from `tinychannels::controllers` through `controllers/definitions.rs` and `mod.rs`): declarative provider metadata.-- `pub fn start_channels` (`runtime/startup.rs`, re-exported from `mod.rs`): boots all enabled channels under the supervisor.-- `pub fn doctor_channels` (`commands.rs`): diagnoses connectivity for the doctor CLI.-- `pub fn build_system_prompt`: re-exported from `crate::agent::context::channels_prompt`.-- `pub(crate) enum ChannelSystemPrompt` (`system_prompt.rs`): the prompt a turn is seeded with, `fixed` (tests) or `refreshing` (production), which renders `build_system_prompt_with_identity` for the active agent definition.-- Per-provider channel structs re-exported from `providers/<name>.rs` (all thin `pub use tinychannels::providers::...` shims): `DingTalkChannel`, `DiscordChannel`, `EmailChannel`, `IMessageChannel`, `IrcChannel`, `LarkChannel`, `LinqChannel`, `MattermostChannel`, `QQChannel`, `SignalChannel`, `SlackChannel`, `TelegramChannel`, `WhatsAppChannel`, `YuanbaoChannel`. Cargo-feature-gated: `WhatsAppWebChannel` (`whatsapp-web`). `CliChannel` comes from `tinychannels-runtime` and is ungated.-- Stable `pub use providers::<name>` paths for every provider, in `mod.rs`.-- RPC `channels.{list, describe, connect, disconnect, status, set_default, get_default, test, telegram_login_start, telegram_login_check, discord_link_start, discord_link_check, discord_list_guilds, discord_list_channels, discord_check_permissions, send_message, send_reaction, create_thread, update_thread, list_threads}`, declared in `controllers/schemas.rs`.+### Path 1: native listeners (`start_channels`)-## Submodule map+When the user has connected at least one listening integration, the core spawns the channel runtime. `spawn_channels_service` in `core/runtime/services.rs` captures the current channel session token, loads the config, checks `channels_config.has_listening_integrations()`, and calls `start_channels_with_session`. Setting `OPENHUMAN_DISABLE_CHANNEL_LISTENERS=1` skips the whole thing.-| Path | Purpose |-| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |-| `providers/` | Per-provider re-exports from `tinychannels` ([README](providers/README.md)) |-| `host/` | `build_channel_host`, the OpenHuman implementation of `tinychannels::host` that ported providers call back into (adapters in `host/adapters.rs`: `VoiceTranscriber`, `VoiceSynthesizer`, `CoreApprovalGate`, `ConversationHistoryStore`, `OpenHumanEventSink`, `CoreShutdownRegistry`, `ConfigAllowlistStore`); `host/remote_control.rs` (`RemoteControlHost` behind `/status`, `/sessions`, `/new`) and `host/channel_events.rs` (`ChannelApprovalSurfaceSubscriber`, `ChannelTurnStateSubscriber`), which give every capable provider in-chat approvals and remote control |-| `runtime/` | Startup, supervision, and the inbound dispatch loop into the agent ([README](runtime/README.md)) |-| `controllers/` | `channels.*` RPC namespace, `OpenHumanChannelBackend`, provider definitions ([README](controllers/README.md)) |-| `tests/` | Cross-channel integration test suite (`#[cfg(all(feature = "channels", test))]`) |+`runtime/startup/start_channels.rs` then does the boot work in this order:-Flat files: `bus.rs` (`ChannelInboundSubscriber`, handles `DomainEvent::ChannelInboundMessage` published by the socket transport layer in `platform/socket/event_handlers.rs`; the progressive reply is `tinychannels::delivery::progressive::ProgressiveReply` over `bus/delivery.rs`'s `BackendProgressiveSender`, the REST relay transport; registered by `register_domain_subscribers` in `core/runtime/subscribers.rs`, not here), `commands.rs` (`doctor_channels`, printing `tinychannels::runtime::check_channels_health`), `context.rs` (`ChannelRuntimeContext`, per-sender conversation history, timeouts), `proactive.rs` (`ProactiveMessageSubscriber`, subscribes `DomainEvent::ProactiveMessageRequested` and delivers to the active channel), `routes.rs` (per-sender route overrides and runtime commands, including `tinychannels::remote` commands on providers with the `remote_control` capability), `system_prompt.rs`, `traits.rs` (ungated `Channel`/`SendMessage` re-export).+1. Initialises the event bus and registers the subscribers a messaging core needs (health, thread persistence, Composio triggers, the web-chat surface subscribers, task sources) plus the native `agent.run_turn` handler. That handler must exist before the dispatch loop starts, because every inbound message is answered through it.+2. Resolves the chat model (`resolve_chat_workload` in `startup/chat_workload.rs` picks the managed cloud model or the user's per-workload provider), installs the live `SecurityPolicy`, builds the tool registry, and loads skills.+3. Builds the system prompt as a `ChannelSystemPrompt::refreshing` (see "System prompt" below). The fixed suffix is the XML tool-instruction block plus an advisory "Host access" section rendered by `startup/prompt.rs`.+4. Builds the `ChannelHost` capability surface (`host::build_channel_host`) and calls `tinychannels::build_channels` with a credential-hydrated config (`hydrate_channel_credentials` in `startup/credentials.rs` fills the email password and Yuanbao app secret from the keyring) and `RuntimeProxyClients` (the configured HTTP proxy).+5. Optionally connects the relay WebSocket runtime (`startup/relay.rs`) when `channels_config.relay` is configured.+6. Spawns one supervised listener per provider (`runtime/supervision.rs`), registers the cron delivery subscriber, the cron channel bridge, the proactive subscriber, and the turn-state and approval-surface subscribers from `host/channel_events.rs`.+7. Runs the dispatch loop until the session is cancelled.-## Calls into+```text+ provider listener (one per channel, supervised, backoff + jitter)+ | ChannelMessage relay websocket (optional)+ v | RuntimeChannelMessage+ mpsc(100) --> bridge task --> mpsc(100) <++ |+ v+ run_message_dispatch_loop+ (bounded by compute_max_in_flight_messages)+ |+ v one worker per message+ process_channel_runtime_message (processor/turn.rs)+ 1. publish ChannelMessageReceived+ 2. slash command? --> routes.rs, stop+ 3. yes/no for a parked approval? --> ApprovalGate, stop+ 4. typing indicator, ACK reaction+ 5. history = system prompt + per-sender history + msg+ 6. resolve_target_agent ("orchestrator") + tool scope+ 7. BUS.native().request("agent.run_turn", ...)+ inside ApprovalChatContext when chat_approvals+ 8. draft updates / final reply on the channel+ 9. publish ChannelMessageProcessed+```-- `crates/openhuman-core/src/agent/` — the agent turn is dispatched over `BUS.native()` to the `agent.run_turn` handler registered by `agent::bus::register_agent_handlers`, so `runtime/dispatch/` never imports the harness directly.-- `crates/openhuman-core/src/agent/context/channels_prompt.rs` — channel system prompt rendering, re-exported as `build_system_prompt`.-- `crates/openhuman-core/src/security/credentials/` — `AuthService` lookups for connect/disconnect and for secret hydration at startup (email password, Yuanbao app secret).-- `crates/openhuman-core/src/security/approval/` — `ApprovalGate` for the approval-reply intercept and `ApprovalChatContext` scoping of turns on every provider with the `chat_approvals` capability.-- `crates/openhuman-core/src/config/` — `Config` / `ChannelsConfig` (schema types come from `tinychannels_bus::config` via `config/schema/channels.rs`).-- `crates/openhuman-core/src/memory/conversations/` — memory v2 conversation ingestion (from the session host's `ConversationTurnCommitted` event; channel turns do no per-turn recall or autosave) and `forget_channel`, which `disconnect_channel` with `clear_memory` uses to forget a channel's `channel:<name>`-tagged conversations.-- `crates/openhuman-core/src/backend/client.rs` — `BackendClient` for controller messaging ops and Telegram/Discord link flows.-- `crates/openhuman-core/src/web_chat/` — web-channel event publishing, session invalidation (`/new`), and the web surface subscribers registered at startup.-- `crates/openhuman-core/src/voice/` — STT/TTS behind the `host/` adapters.-- `crates/openhuman-core/src/core/bus.rs` and `core/events.rs` — the process-wide `BUS` and the `DomainEvent::Channel*` variants published from `runtime/dispatch/` and `runtime/supervision.rs`.-- `vendor/tinychannels/` — provider transports, `tinychannels::build_channels` (provider construction), `ChannelManager`/`ChannelBackend`, the `tinychannels::host` capability boundary, progressive delivery (`delivery::progressive`), remote control (`remote`), in-chat approvals (`approvals`), the relay transport registry (`relay::runtime`), connect-form parsing, and per-provider `ChannelCapabilities`; `vendor/tinychannels/crates/tinychannels-bus` — the transport-free trait/type contract.+Per-sender history is kept in memory in `ChannelRuntimeContext` (`context.rs`), keyed by `conversation_history_key` (channel, sender, reply target, thread). When a turn fails with a context-window overflow, the processor compacts that sender's history and asks the user to resend. Turns have a timeout (`message_timeout_secs`). Channel turns do no per-turn memory recall or autosave: memory reaches a session through `context.md`, injected by the session host, and committed turns are ingested from the `ConversationTurnCommitted` event.-## Called by+The listener supervisor reports through `OpenHumanListenerObserver`, which publishes `DomainEvent::ChannelConnected`, `ChannelDisconnected` and `HealthRestarted`. The full runtime walk-through, including account lifetime and logout, is in [runtime/README.md](runtime/README.md).-- `crates/openhuman-core/src/core/all.rs`: registers `controllers::all_channels_registered_controllers()` under the `channels` feature gate.-- `crates/openhuman-core/src/core/runtime/services.rs`: `spawn_channels_service` calls `channels::start_channels(config)` unless `OPENHUMAN_DISABLE_CHANNEL_LISTENERS` is set or `has_listening_integrations()` is false.-- `crates/openhuman-core/src/core/runtime/subscribers.rs`: `bootstrap_core_runtime` subscribes `bus::ChannelInboundSubscriber` and calls `proactive::register_web_only_proactive_subscriber()`.-- `crates/openhuman-core/src/agent/session_host/`: the interactive loop drives the ungated `CliChannel`.-- `crates/openhuman-core/src/cron/bus.rs`: `CronDeliverySubscriber` is handed the started channel map by `runtime/startup.rs`; it names channels only through `tinychannels_bus`.+### Path 2: backend-relayed inbound (`ChannelInboundSubscriber`)++The desktop app usually has no native listeners. Messages for hosted bots arrive over the backend socket instead: `platform/socket/event_handlers.rs` publishes `DomainEvent::ChannelInboundMessage`. `bus::ChannelInboundSubscriber` (`bus/subscriber.rs`) handles it. It is registered on the always-on boot path by `register_domain_subscribers` in `core/runtime/subscribers.rs`, not by `start_channels`, so it works on a core that never starts listeners.++The subscriber derives a thread id from (channel, sender, reply target, thread) with `derive_inbound_thread_id`, starts a turn through `web_chat::start_chat`, and watches the web-channel event stream for that request. The reply is shown progressively with `tinychannels::delivery::progressive::ProgressiveReply`: a draft that is edited as text streams in, typing refreshes, and filler bubbles on slow turns, then a finalize. The transport underneath is `BackendProgressiveSender` (`bus/delivery.rs`), which sends through `BackendClient` with idempotency keys and maps typed `BackendApiError`s (`ChannelEditUnsupported`, `MessageNotFound`) to the recoveries the progressive driver expects.++```text+ backend socket --> DomainEvent::ChannelInboundMessage+ |+ v+ ChannelInboundSubscriber+ | web_chat::start_chat(thread_id, ...)+ v+ web channel events --> ProgressiveReply+ |+ v+ BackendProgressiveSender --> backend REST+```++### Outbound: proactive messages++`proactive.rs` subscribes to `DomainEvent::ProactiveMessageRequested`. Every proactive message goes to the web channel (`web_chat::publish_web_channel_event`). If the user has set an active external channel and that channel is in the started channel map, it is sent there too. The always-on boot registers a web-only variant (`register_web_only_proactive_subscriber`); the full runtime registers one with the real channel map and publishes its active-channel handle, so `channels.set_default` (through `set_runtime_active_channel`) takes effect without a restart.++### Slash commands and remote control++`routes.rs` intercepts messages starting with `/` before any turn runs. Portable commands (`/models`, `/providers` and the per-sender route override they set) come from `tinychannels::routes`. On providers with the `remote_control` capability, `/status`, `/sessions`, `/new` and `/help` are parsed and executed by `tinychannels::remote`, with `host/remote_control.rs` (`RuntimeRemoteControl`) answering from the runtime context, the thread store and the web-chat session cache.++### In-chat approvals++When a tool call needs approval on a channel whose provider has `chat_approvals`, three pieces cooperate. The dispatch loop runs the turn inside an `ApprovalChatContext` whose thread id is the history key. `ChannelApprovalSurfaceSubscriber` (`host/channel_events.rs`) turns `ApprovalRequested` events into a prompt in that chat through `tinychannels::approvals::ApprovalSurface`. When the user replies yes or no, `try_route_approval_reply` (`runtime/dispatch/processor/approval.rs`) hands it to `ApprovalGate::decide` instead of starting a new turn. Any other text runs as a fresh turn, which cancels the parked call. Providers without the capability (email, CLI, webhooks) keep the "no chat context, allow" behaviour, since a prompt there would only time out.++### System prompt++`system_prompt.rs` owns when the prompt is rendered, not its text. `ChannelSystemPrompt` has two variants. `Fixed` is a literal used by tests. `Refreshing` keeps the render inputs (`ChannelPromptInputs`: tool descriptions, skills, model, the fixed suffix) and re-renders only when the identity fingerprint changes. The fingerprint is a hash of `(mtime, len)` for the workspace-root `SOUL.md` and `IDENTITY.md`, so a steady-state message costs two `stat` calls and gets the same `Arc<String>` back, which keeps the provider prefix cache warm. The render itself is `build_system_prompt_with_identity` from `agent/context/channels_prompt.rs`, with the project context (identity files) placed after the tool schemas and access block.++## Layout++| Path | What it does |+| --- | --- |+| `mod.rs` | Module declarations, the feature-gate split, stable `channels::<provider>` paths and the public re-exports. |+| `traits.rs` | Ungated re-export of `Channel`, `ChannelMessage`, `ChannelSendExt`, `SendMessage` from `tinychannels-bus`. |+| `contract_schema.rs` | Ungated conversion of `tinychannels-bus` controller schemas into core `ControllerSchema`s; shared with `openhuman-tinyhumans`. |+| `providers/` | One-line re-exports of each provider module from `tinychannels::providers`. See [providers/README.md](providers/README.md) for the provider table and how to add one. |+| `host/` | The OpenHuman implementation of the `tinychannels::host` boundary: `build_channel_host` and its adapters (`adapters.rs`), the approval-surface and turn-state subscribers (`channel_events.rs`), and the remote-control host (`remote_control.rs`). |+| `runtime/` | Startup, listener supervision, the account-lifetime session, and the dispatch pipeline. See [runtime/README.md](runtime/README.md). |+| `controllers/` | The `channels.*` RPC namespace and `OpenHumanChannelBackend`. See [controllers/README.md](controllers/README.md). |+| `bus.rs`, `bus/` | `ChannelInboundSubscriber` (`subscriber.rs`), the backend progressive sender (`delivery.rs`), and the inbound thread-id re-export (`thread_id.rs`). |+| `context.rs` | `ChannelRuntimeContext`, per-sender history maps, history compaction, and timeout/backoff constants re-exported from `tinychannels::context`. |+| `routes.rs` | Slash-command parsing and per-sender route selection (provider and model overrides). |+| `proactive.rs` | `ProactiveMessageSubscriber` and the active-channel handle. |+| `system_prompt.rs` | `ChannelSystemPrompt`, `ChannelPromptInputs`, identity fingerprinting. |+| `commands.rs` | `doctor_channels`: builds channels from the hydrated config and prints `tinychannels::runtime::check_channels_health` results. |+| `tests/` | Cross-channel integration suite (see Tests). |++## Key types and entry points++- `start_channels` / `start_channels_with_session` (`runtime/startup/start_channels.rs`) boot the native runtime. The `_with_session` form takes a `CancellationToken` captured before config loading, which is what `spawn_channels_service` uses.+- `session::channel_session` and `session::invalidate_channel_session` (`runtime/session.rs`) hold the process's single `tinychannels::runtime::ChannelSession`. Logout calls `invalidate_channel_session` from `security/credentials/ops/credential.rs`, which cancels the running runtime and everything it owns.+- `ChannelRuntimeContext` (`context.rs`) is the shared state every dispatch worker reads: channel map, tools, prompt, model, histories, route overrides, timeouts, and the full `Config` in production.+- `process_channel_runtime_message` and `run_message_dispatch_loop` (`runtime/dispatch/processor/`) are the per-message pipeline and its bounded loop.+- `resolve_target_agent` (`runtime/dispatch/routing.rs`) routes every channel turn to the `orchestrator` agent and builds its visible tool set, falling back to `AgentScoping::unscoped()` when the registry or definition is missing.+- `build_channel_host` (`host/mod.rs`) assembles the `ChannelHost` from `CoreShutdownRegistry`, `VoiceTranscriber`, `VoiceSynthesizer`, `CoreApprovalGate`, `ConversationHistoryStore`, `OpenHumanEventSink` and `ConfigAllowlistStore`. Reactions, turn dispatch, the run ledger and pairing are left unset.+- `ChannelInboundSubscriber` (`bus/subscriber.rs`) is the backend-relayed inbound path.+- `ProactiveMessageSubscriber` (`proactive.rs`) is outbound proactive delivery.+- `ChannelSystemPrompt` (`system_prompt.rs`) is the seed prompt for every turn.+- `OpenHumanChannelBackend` (`controllers/backend.rs`) implements `tinychannels::ChannelBackend` for the RPC handlers.+- `ChannelDefinition` and `ChannelAuthMode` are re-exported from `tinychannels::controllers` (through `controllers/definitions.rs`) for declarative provider metadata.+- `build_system_prompt` is a re-export of `agent::context::channels_prompt::build_system_prompt`.++## RPC / CLI surface++The `channels` namespace is registered from `controllers::all_channels_registered_controllers()` in `core/all.rs`, under `DomainGroup::Channels` and behind the `channels` feature. Schemas come from the `tinychannels-bus` contract.++- Provider metadata: `channels.list`, `channels.describe`.+- Connection lifecycle: `channels.connect`, `channels.disconnect` (optionally forgetting the channel's stored conversations), `channels.status`, `channels.test`.+- Default channel for proactive delivery: `channels.set_default`, `channels.get_default`.+- Discord: `channels.discord_list_guilds`, `channels.discord_list_channels`, `channels.discord_check_permissions`.+- Messaging through the backend: `channels.send_message`, `channels.send_reaction`, `channels.create_thread`, `channels.update_thread`, `channels.list_threads`.++The managed-bot link methods `channels.telegram_login_start`, `telegram_login_check`, `discord_link_start` and `discord_link_check` are part of the contract but are not registered here. They are listed in `HOSTED_CHANNEL_FUNCTIONS` (`controllers/schemas.rs`) and served by `openhuman-tinyhumans` (`hosted/channel_link/`), which converts their schemas with `channels::contract_schema::contract_controller_schema`.++The in-app web chat (RPC namespace `channel`, singular) is a separate domain in `web_chat/`.++## Boundaries++- Provider transports, provider construction (`tinychannels::build_channels`), `ChannelManager`/`ChannelBackend`, per-provider `ChannelCapabilities`, remote-control commands (`tinychannels::remote`), approval prompts (`tinychannels::approvals`), progressive delivery, the relay transport, connect-form parsing and health checks all belong to `tinychannels` (`vendor/tinychannels/`, repo `tinyhumansai/tinychannels`). The transport-free trait and type contract is `vendor/tinychannels/crates/tinychannels-bus`. Fix provider bugs there, not with a host-side branch on a channel name; add a capability flag upstream instead.+- The channel system prompt text is in `agent/context/channels_prompt.rs`.+- The agent turn itself is run by the `agent.run_turn` native handler registered by `agent::bus::register_agent_handlers`. The dispatch code never imports the harness directly.+- Credential storage is `security/credentials/` (`AuthService`); the approval gate and `ApprovalChatContext` are `security/approval/`.+- Config schema types come from `tinychannels_bus::config` through `config/schema/channels.rs`.+- Conversation memory ingestion and `forget_channel` are in `memory/conversations/`.+- Backend REST calls go through `backend::BackendClient`; Telegram and Discord link flows that need a TinyHumans account live in `openhuman-tinyhumans`.+- Speech-to-text and text-to-speech are the `voice/` domain, reached through the `host/` adapters.+- Web-chat turns, the web-channel event stream, and the surface subscribers are `web_chat/`.+- Cron delivery is `cron/bus.rs` (`CronDeliverySubscriber`) and `cron/channel_bridge.rs`; `start_channels` hands them the started channel map.++## Gotchas++- The `channels` feature (default on; `channels = ["dep:tinychannels", "tinychannels/email", "tinychannels/lark"]` in `crates/openhuman-core/Cargo.toml`) gates almost everything. Three pieces stay ungated because always-on code names them: `traits` (the agent session host's interactive loop and `cron::bus`), `CliChannel` (re-exported from the unconditional `tinychannels-runtime` crate), and `contract_schema` (used by `openhuman-tinyhumans`). The config schema, the `DomainEvent` inbound envelope and security pairing resolve through `tinychannels-bus`, which is unconditional. The gate sheds no transitive packages; its value is compile surface and binary size. The `voice` feature also enables `dep:tinychannels` (for `EmailChannel` only), so a build without `channels` still links the crate unless `voice` is off too. `WhatsAppWebChannel` additionally needs the `whatsapp-web` feature.+- `start_channels` is skipped on cores with no listening integrations, which includes most desktop installs. Anything every core needs (the `ChannelInboundSubscriber`, the web-only proactive subscriber, tool-timeout seeding, self-improvement subscribers, the flows trigger subscriber) is registered in `core/runtime/subscribers.rs`, not in `start_channels`. Put new always-needed wiring there.+- Several registrations in `start_channels` overlap with `bootstrap_core_runtime` (agent handlers, the agent definition registry). They are written to be idempotent; keep them that way.+- The channel session token must be captured before the first `await` on config loading. Otherwise a logout during startup leaves a listener running for the old account.+- The system prompt is frozen for the process except for the identity files. Tools, skills, model and security posture still need a restart to reach channel turns.+- History keys include the sender and thread, not only the channel. Keying on the channel alone would merge different participants of a shared Slack or Discord channel into one session.## Tests-- Unit, flat files: `bus_tests.rs`, `bus_inbound_thread_id_tests_tests.rs`, `commands_tests.rs`, `context_tests.rs`, `proactive_tests.rs`, `routes_tests.rs`, `traits_tests.rs` (`bus/`'s `delivery.rs`, `subscriber.rs` and `thread_id.rs` are source submodules, not tests; `bus_test_support_tests.rs` is a debug-build helper module). Progressive delivery, remote control, approvals, relay registry, health checks, the CLI channel and connect-form parsing are tested upstream in `vendor/tinychannels`.-- Cross-channel integration suite (`tests/`, see its module doc): `common.rs` fixtures plus `discord_integration`, `health`, `identity`, `prompt`, `runtime_dispatch`, `runtime_tool_calls`, `telegram_integration`.-- Host adapters: `host/host_tests.rs`, `host/channel_events_tests.rs`.-- Controllers: `controllers/{backend_tests,ops_tests,schemas_tests}.rs` (+ `ops_connect_status_tests.rs`/`ops_yuanbao_email_tests.rs`).-- Runtime: `runtime/{startup_tests,startup_email_secret_tests_tests,startup_yuanbao_secret_tests_tests,supervision_tests,dispatch_tests}.rs`, `runtime/dispatch/{mod_scoping_tests_tests,mod_approval_surface_gating_tests_tests,routing_connected_fallback_tests_tests}.rs`.+Unit tests sit beside their modules as `*_tests.rs` files (for example `bus_tests.rs`, `routes_tests.rs`, `host/host_tests.rs`, `controllers/ops_tests.rs`, `runtime/startup_tests.rs`). The cross-channel integration suite in `tests/` (declared as `#[cfg(all(feature = "channels", test))] mod tests` in `mod.rs`) covers end-to-end dispatch, tool calls, health restarts, prompt assembly, and the Discord and Telegram flows; its `mod.rs` describes each file. Behaviour owned by `tinychannels` is tested upstream.++```bash+cargo test -p openhuman channels::+pnpm debug rust channels::+```