Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

docs(channels, web3): add README documentation for runtime and x402 modules

Steven Enamakel60ebd3fdfe76
diff --git a/crates/openhuman-core/src/channels/runtime/README.md b/crates/openhuman-core/src/channels/runtime/README.md
index 545d4cc492..80beb6e430 100644
--- a/crates/openhuman-core/src/channels/runtime/README.md
+++ b/crates/openhuman-core/src/channels/runtime/README.md
@@ -1,40 +1,40 @@
# Runtime
-Boots every enabled channel, keeps their listeners alive, and dispatches inbound messages into the agent loop.
+Boots every enabled channel, keeps their listeners alive, and dispatches inbound messages into the agent loop. `mod.rs` exports only `start_channels`; `dispatch` and `supervision` internals are `pub(crate)` for `channels/tests/` under `#[cfg(test)]`.
## Files
| Path | Purpose |
| --- | --- |
-| `startup.rs` (+ `startup_part_01.rs`, `startup_part_02.rs`) | `start_channels` — reads config, resolves per-channel secrets (email, yuanbao), constructs each enabled `Channel`, and spawns a supervised listener per channel into a shared dispatch queue |
-| `supervision.rs` | `spawn_supervised_listener` — wraps a channel listener task so a crashed listener is respawned instead of silently dying |
-| `dispatch/` | The inbound message pipeline that turns a received `RuntimeChannelMessage` into an agent turn and a reply |
-| `test_support.rs` | Test/debug-only helpers (`#[cfg(any(test, debug_assertions))]`) shared across the runtime's own tests and `channels/tests/` |
+| `startup.rs` (+ `startup_part_01.rs`, `startup_part_02.rs` via `include!`) | `start_channels` — builds the `channels::host` capability surface, hydrates secrets that live outside `config.toml` (`hydrate_channel_credentials`: email password, Yuanbao app secret, via `security::credentials::AuthService`), calls `tinychannels::build_channels`, registers the startup bus subscribers, spawns a supervised listener per channel and the optional relay runtime, then runs the dispatch loop |
+| `supervision.rs` | `spawn_supervised_listener` — re-runs `Channel::listen` in a loop with exponential backoff plus full jitter, publishing `DomainEvent::ChannelConnected` / `ChannelDisconnected` / `HealthRestarted`; re-exports `tinychannels::runtime::compute_max_in_flight_messages` |
+| `dispatch/` | The inbound pipeline that turns a `RuntimeChannelMessage` into an agent turn and a reply |
+| `test_support.rs` | `#[cfg(any(test, debug_assertions))]` dispatch harness (`run_dispatch_harness`, `DispatchHarnessOptions`) used by `channels/tests/` and raw coverage |
## Inbound path
-1. A provider listener (spawned in `startup_part_01.rs`, one per enabled channel) receives a message and sends it as a `RuntimeChannelMessage` on a bounded `mpsc` channel (capacity 100).
-2. `spawn_supervised_listener` (`supervision.rs`) owns the listener task and restarts it if it exits unexpectedly, so a single crashed provider connection doesn't take the process down.
-3. `run_message_dispatch_loop` (`dispatch/processor.rs`, called once from `startup_part_01.rs` after every listener is spawned) drains the shared receiver with bounded concurrency (`compute_max_in_flight_messages`) and hands each message to `process_channel_message`.
-4. `process_channel_message` runs the full per-message pipeline: typing indicator, ACK reaction, approval-reply interception (`try_route_approval_reply`, gated by `channel_has_approval_surface`), agent-scoping (`dispatch/routing.rs`: `resolve_target_agent` + `build_visible_tool_set`), the agent turn itself, draft updates, and the reply send.
+1. Each provider listener (`spawn_supervised_listener`, one per channel from `tinychannels::build_channels`) sends `traits::ChannelMessage`s on a bounded `mpsc` (capacity 100). A bridge task in `startup_part_01.rs` wraps each into `RuntimeChannelMessage` and forwards it to the dispatch queue (also capacity 100). The relay runtime (`start_relay_runtime`) writes `RuntimeChannelMessage`s to that queue directly so relay inbound keeps its original TinyChannels envelope.
+2. `run_message_dispatch_loop` (`dispatch/processor_part_03.rs`) drains the queue under a semaphore sized by `compute_max_in_flight_messages(listener_count)` and spawns a worker per message that calls `process_channel_runtime_message` (`processor_part_02.rs`). `process_channel_message` is the `traits::ChannelMessage` wrapper for the same pipeline.
+3. `process_channel_runtime_message` publishes `DomainEvent::ChannelMessageReceived`, then: if `channel_has_approval_surface` and `try_route_approval_reply` claims the message as a yes/no answer to a parked approval, stops there; otherwise starts typing, sends the ACK reaction (`select_acknowledgment_reaction`, threaded messages only), opens a streaming draft when the channel supports it, resolves scoping (`resolve_target_agent` + `build_visible_tool_set`), dispatches the turn over `BUS.native()` to the `agent.run_turn` handler (`agent::bus::register_agent_handlers`), sends the reply, and publishes `DomainEvent::ChannelMessageProcessed`.
## `dispatch/`
| Path | Purpose |
| --- | --- |
-| `helpers.rs` | Stateless helpers: per-turn context block for non-web channels, deterministic ACK-emoji picker, worker/typing-task lifecycle utilities |
-| `routing.rs` | `AgentScoping`, `resolve_target_agent`, `build_visible_tool_set` — picks the active agent and its visible/delegation tool surface for a turn, reading `Config` + `AgentDefinitionRegistry` + connected integrations |
-| `processor.rs` (+ `processor_part_01.rs..03.rs`) | `channel_has_approval_surface` (per-channel approval-context gate), `try_route_approval_reply`, `process_channel_message`, `run_message_dispatch_loop` |
-| `mod.rs` | Wires the three submodules and their `#[cfg(test)]` / `#[cfg(any(test, debug_assertions))]` re-exports |
+| `helpers.rs` | Stateless helpers: per-turn context block for non-web channels, deterministic ACK-emoji picker, worker join logging, scoped typing task |
+| `routing.rs` | `AgentScoping`, `resolve_target_agent`, `build_visible_tool_set`, `connected_with_fallback` — picks the active agent for the channel and its visible/delegation tool surface from `Config`, `AgentDefinitionRegistry`, and the connected-integrations snapshot |
+| `processor.rs` (+ `processor_part_01.rs..03.rs`) | `RuntimeChannelMessage`, `channel_has_approval_surface`, `try_route_approval_reply`, `process_channel_message`, `process_channel_runtime_message`, `run_message_dispatch_loop` |
+| `mod.rs` | Declares the three submodules and the `#[cfg(test)]` / `#[cfg(any(test, debug_assertions))]` re-exports the test modules reach through `super::*` |
-Approval-surface gating and per-sender agent scoping are the two policy points a new channel provider needs to account for: whether inbound approval replies (yes/no) short-circuit a fresh agent turn, and which agent/tools a given sender is routed to.
+Two policy points here: `channel_has_approval_surface` is `true` only for `TELEGRAM_APPROVAL_CLIENT_ID`, so other channels still run in the legacy "no chat context, silently allow" state until they get a surface subscriber; and scoping is per channel (`resolve_target_agent(&msg.channel)`), falling back to `AgentScoping::unscoped()` (every registered tool visible) when the registry is not initialised or the target agent is unknown.
## Called by
-`channels::start_channels` is exported from `channels/mod.rs` and invoked from `crates/openhuman-core/src/core/runtime/services.rs` during boot, unless `OPENHUMAN_DISABLE_CHANNEL_LISTENERS` is set. It is skipped for web-chat-only cores (see `core/jsonrpc.rs` boot comments and `skills/bus.rs`).
+`channels::start_channels` is re-exported from `channels/mod.rs` and spawned by `spawn_channels_service` in `crates/openhuman-core/src/core/runtime/services.rs`, unless `OPENHUMAN_DISABLE_CHANNEL_LISTENERS` is set or `channels_config.has_listening_integrations()` is false. Web-chat-only desktop cores therefore never run it; `bus::ChannelInboundSubscriber` and the web-only proactive subscriber are registered on the always-on boot path in `core/jsonrpc.rs` instead.
## Tests
-- `startup_tests.rs`, plus secret-resolution coverage in `startup_email_secret_tests_tests.rs` and `startup_yuanbao_secret_tests_tests.rs`.
+- `startup_tests.rs`, `startup_email_secret_tests_tests.rs`, `startup_yuanbao_secret_tests_tests.rs` (secret hydration precedence).
- `supervision_tests.rs`.
-- `dispatch_tests.rs` (top-level dispatch loop behavior), `dispatch/mod_scoping_tests_tests.rs` (agent scoping), `dispatch/mod_approval_surface_gating_tests_tests.rs` (approval-surface gate), `dispatch/routing_connected_fallback_tests_tests.rs` (fallback routing when no connected agent matches).
+- `dispatch_tests.rs` (helpers: ACK reaction categories, context block shape), `dispatch/mod_scoping_tests_tests.rs` (`build_visible_tool_set` / `AgentScoping`), `dispatch/mod_approval_surface_gating_tests_tests.rs` (`channel_has_approval_surface`), `dispatch/routing_connected_fallback_tests_tests.rs` (`connected_with_fallback`: authoritative snapshot vs cached fallback on unavailable/timeout).
+- End-to-end dispatch coverage lives in `channels/tests/` (`runtime_dispatch`, `runtime_tool_calls`, `discord_integration`, `telegram_integration`, `health`).
diff --git a/crates/openhuman-core/src/web3/x402/README.md b/crates/openhuman-core/src/web3/x402/README.md
index 1e47245faa..e608e69199 100644
--- a/crates/openhuman-core/src/web3/x402/README.md
+++ b/crates/openhuman-core/src/web3/x402/README.md
@@ -75,9 +75,10 @@ which handles a 402 only as a silent fallback for any endpoint.
- **Budget enforcement** (`SpendingBudget`, defaults: 1 USDC per request, 10
USDC per day, 100 USDC per month, in atomic units) is checked against the
in-memory ledger before a payment is built. Daily and monthly totals sum
- the `Settled` records for the current UTC day / calendar month; the session
- total (records tagged with this process's `x402-<uuid>` session id) is
- reported by `get_summary` but is not a cap. `init_ledger` seeds the limits
+ the `Settled` records for the current UTC day / calendar month. The session
+ total reported by `get_summary` counts records whose `session_id` equals the
+ ledger's `x402-<uuid>` boot id; it is not a cap, and both writers currently
+ store an empty `session_id`, so it reads as zero. `init_ledger` seeds the limits
from `OPENHUMAN_X402_PER_REQUEST_MAX` / `OPENHUMAN_X402_DAILY_MAX` /
`OPENHUMAN_X402_MONTHLY_MAX` when set; `update_budget` changes them for the
running process only and does not rewrite historical records.