Skip to content

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

docs(test_support, web_chat): add readme files for test support and web chat modules

Steven Enamakel77e8ff5b7521
diff --git a/crates/openhuman-core/src/test_support/README.md b/crates/openhuman-core/src/test_support/README.md
index 348a5fc798..53174d97cd 100644
--- a/crates/openhuman-core/src/test_support/README.md
+++ b/crates/openhuman-core/src/test_support/README.md
@@ -76,6 +76,6 @@ This module owns no state of its own — it mutates/reads state owned by other d
- **In-process reset**: the core process is not restarted; specs reload the webview afterward so the renderer also starts blank.
- **Add new persistent state to `reset`**: per the module docstring, any new domain that survives `test_reset` is a leak that lets specs interfere — extend `rpc::reset` when adding persistent state.
- **Path-jail ordering**: `resolve_workspace_relative` rejects `..` (and root/prefix components) lexically before touching the filesystem; the `canonicalize` + `starts_with` check underneath only catches symlink escapes and used to fail open for non-existent targets (openhuman#6085). It canonicalizes the root first (macOS `/var`→`/private/var`); `walk_dir` uses `symlink_metadata` and skips symlinks so listings can't follow links out of the workspace.
-- **CI runs only `introspect` tests**: the `rpc_tests.rs` wipe test needs a memory driver that serves `Maintenance` (`memory-engine-seams`, off in the neither-set CI profile), so the CI Lite lane filters to `test_support::introspect::` and the `rpc` tests only run in a default-features `cargo test --features e2e-test-support`.
+- **CI runs only the `introspect` tests**: the CI Lite lane filters to `test_support::introspect::` because `rpc_tests.rs`'s `wipe_memory_tree` test fails under `--no-default-features` (the memory driver there does not serve `Maintenance`, so `wipe_all_rpc` errors). Run `cargo test -p openhuman --features e2e-test-support --lib -- test_support::` locally to cover both files.
- **`read_workspace_file` byte accounting**: `returned_bytes` is the raw byte count before lossy UTF-8 conversion (which substitutes U+FFFD and can change length) so specs can assert byte-accurate truncation.
- **`list_workspace_files` schema omits `entries`** for brevity, but the runtime payload includes them; `max_depth` defaults to 2, clamped to 6; entry cap is 2000.
diff --git a/crates/openhuman-core/src/web_chat/README.md b/crates/openhuman-core/src/web_chat/README.md
index dad1c647d0..702718d97e 100644
--- a/crates/openhuman-core/src/web_chat/README.md
+++ b/crates/openhuman-core/src/web_chat/README.md
@@ -1,44 +1,54 @@
# Web chat
The web/desktop channel's turn runner. Owns the `channel.web_*` RPC namespace,
-Socket.IO's `chat`/`cancel` events, and the whole request lifecycle from a raw
-message to a delivered reply. Distinct from `channels/`, which drives external
-messaging providers (Telegram, WhatsApp, …) through the same agent harness —
-this module is the desktop/web UI's own path and the hottest one in the
-product.
+the Socket.IO `chat:start`/`chat:cancel` handlers' business logic, and the
+whole request lifecycle from a raw message to a delivered, durably stored
+reply. `channels/` owns the external messaging providers (Telegram, WhatsApp,
+…); their inbound messages are dispatched through this module's `start_chat`
+too (`channels/bus_part_01.rs`), so this is the single turn runner behind both
+surfaces.
## Request lifecycle
-1. `core/socketio.rs` receives a `chat` socket event and calls
+1. `core/socketio.rs` receives a `chat:start` socket event and calls
[`start_chat`] (`ops_part_02.rs`) with the raw message, thread/client ids,
and any model/profile/locale/queue-mode overrides.
2. `start_chat` preprocesses `[FILE:…]`/`[IMAGE:…]` attachment markers
*before* prompt-injection scanning or persistence (a multi-MB base64 blob
must never reach those stages), runs `enforce_prompt_input`, and checks
for a parked chat-native approval reply before treating the message as a
- new turn.
-3. It resolves or builds the session `Agent` (`session.rs`), reusing a cached
- one from `THREAD_SESSIONS` when the `SessionCacheFingerprint` still
- matches, and hands off to `run_task::run_chat_task`, tracked in
- `InFlightEntry`/`ParallelEntry` (`types.rs`) for cancellation and
- interrupt/steer/queue semantics.
-4. `run_chat_task` spawns [`spawn_progress_bridge`] (`progress_bridge.rs`)
- alongside the agent run. The bridge forwards `AgentProgress` into
+ new turn. It then applies the queue mode (`QueueMode::Interrupt` default,
+ `Steer`, `Followup`, `Collect`, `Parallel`) against the thread's
+ `InFlightEntry`/`ParallelEntry` (`types.rs`).
+3. It spawns a tokio task that runs `run_task::run_chat_task` through
+ `run_turn_under_cancel_and_deadline` (`ops_part_01.rs`): a cooperative
+ `CancellationToken`, the wall-clock backstop (`web_turn_deadline`), the
+ `AgentTurnOrigin::WebChat` scope, and the
+ `APPROVAL_CHAT_CONTEXT` task-local scope all wrap the same future.
+4. `run_chat_task` resolves the session `Agent` (`session.rs`), reusing the
+ `THREAD_SESSIONS` entry when its `SessionCacheFingerprint` still matches
+ (a `Parallel` fork always builds a fresh agent and never touches the
+ cache), spawns [`spawn_progress_bridge`] (`progress_bridge.rs`), and awaits
+ `agent.run_single`. The bridge forwards `AgentProgress` into
`WebChannelEvent` socket events, mirrors turn state into
`crate::threads::turn_state::TurnStateStore`, and emits an
`inference_heartbeat` beat every `INFERENCE_HEARTBEAT_SECS` (20s) so a long
- silent prefill doesn't trip the frontend's disconnect timer.
-5. On completion, `presentation.rs` formats and segments the reply for
- delivery (natural-language prose only; code/structured output is never
- split) and calls `reply_persistence::persist_delivered_reply` to write the
- reply to the thread's conversation store *before* announcing it, so the
- answer survives a client reconnect or reload (#6034).
-6. Errors from the provider are normalized through `web_errors.rs`
- (`classify_inference_error`) into user-facing copy — budget-exhausted,
- non-retryable rate limit, fallback-chain-exhausted, etc. — using a
- per-thread `BudgetCorrelation` to reclassify an empty 200 as an
- out-of-credits turn when the last signal was on the same provider binding
- (#3386).
+ silent prefill doesn't trip the frontend's ~120s silence timeout (#4270).
+5. On `Ok`, the spawned task calls `presentation::deliver_response`, which
+ first calls `reply_persistence::persist_delivered_reply` to write the reply
+ to the thread's conversation store under the deterministic
+ `run_reply_message_id(request_id)` (so the answer survives a client
+ reconnect or reload, #6034) and then emits exactly one `chat_done` carrying
+ the model's unmodified text. The segmentation helpers in `presentation.rs`
+ are legacy and unused on this path.
+6. On `Err`, `run_chat_task`'s error branch first consults the per-thread
+ budget signal (`THREAD_BUDGET_SIGNALS`, `classify_budget_correlation` →
+ `BudgetCorrelation`) so an empty 200 on the same provider binding as a
+ recent budget-exhausted failure is reclassified as out-of-credits (#3386);
+ the spawned task then normalizes the error string through
+ `web_errors::classify_inference_error` into the user-facing `chat_error`
+ (budget-exhausted, non-retryable rate limit, fallback-chain-exhausted, turn
+ timeout, …) and decides via `sentry_suppression_reason` whether it pages.
## Public surface
@@ -51,34 +61,37 @@ product.
- Operations (`ops.rs` + `ops_part_0{1,2,3}.rs`): `start_chat`, `cancel_chat`,
`cancel_chat_scoped`, `cancel_should_target`, `channel_web_chat`,
`channel_web_cancel`, `channel_web_queue_status`, `channel_web_queue_clear`,
- `invalidate_thread_sessions`, `ChatRequestMetadata` — the turn's request
- surface and its in-flight/session state (`THREAD_SESSIONS`,
- `THREAD_BUDGET_SIGNALS`, in-flight/parallel maps).
+ `invalidate_thread_sessions`, plus `in_flight_entries_for_test` (exported
+ unconditionally; `test_support/introspect.rs` uses it). The turn's
+ in-flight/session state lives here (`THREAD_SESSIONS`,
+ `THREAD_BUDGET_SIGNALS`, `IN_FLIGHT`, parallel map).
+- `ChatRequestMetadata` (`types.rs`) — per-request metadata passed by every
+ caller of `start_chat`/`spawn_progress_bridge`.
- Schemas (`schemas.rs`): `all_web_channel_controller_schemas`,
`all_web_channel_registered_controllers`, `schemas` — RPC contract for the
`channel` namespace.
- Debug/test-only hooks: `set_test_forced_run_chat_task_error`,
`RUN_CHAT_TASK_TEST_LOCK`, `set_test_run_chat_task_block`,
- `TestRunChatTaskBlock`, `parallel_in_flight_entries_for_test`,
- `in_flight_entries_for_test`, `fresh_approval_surface_subscription` —
- compiled only under `#[cfg(test, debug_assertions)]`/`debug_assertions`, so
- none of them link into a release binary.
+ `TestRunChatTaskBlock`, `parallel_in_flight_entries_for_test`
+ (`#[cfg(any(test, debug_assertions))]`) and
+ `fresh_approval_surface_subscription` (`#[cfg(debug_assertions)]`), so none
+ of them link into a release binary.
## Files
| File | Purpose |
| --- | --- |
| `mod.rs` | Module wiring and re-exports; no business logic |
-| `ops.rs`, `ops_part_01.rs`, `ops_part_02.rs`, `ops_part_03.rs` | `start_chat`/`cancel_*`/`channel_web_*` operations, session cache, in-flight tracking, budget-signal correlation |
-| `run_task.rs` | `run_chat_task` — builds the session agent, runs the turn, spawns the progress bridge |
+| `ops.rs`, `ops_part_01.rs`, `ops_part_02.rs`, `ops_part_03.rs` | `start_chat`/`cancel_*`/`channel_web_*` operations, session cache, in-flight tracking, budget-signal correlation, `run_turn_under_cancel_and_deadline`; the parts are `include!`d into `ops.rs` |
+| `run_task.rs` | `run_chat_task` — resolves/builds the session agent, spawns the progress bridge, runs the turn, applies the budget correlation to its error |
| `session.rs` | Builds/fingerprints the cached session `Agent`, resolves target agent id, locale directive, provider role for a model override |
-| `progress_bridge.rs` | Forwards `AgentProgress` into `WebChannelEvent`s and `TurnStateStore`, emits the `inference_heartbeat` liveness beat |
-| `presentation.rs` | Local-model response segmentation into chat bubbles and emoji-reaction decisions; calls `reply_persistence` before announcing |
+| `progress_bridge.rs` | Forwards `AgentProgress` into `WebChannelEvent`s and `TurnStateMirror`, emits the `inference_heartbeat` liveness beat |
+| `presentation.rs` | `deliver_response` (one unsegmented `chat_done`, persisted first) and `deliver_response_single_bubble` (core-initiated turns); local-model emoji-reaction decision; legacy segmentation helpers |
| `reply_persistence.rs` | Durable write of the reply about to be announced, under a deterministic id shared with the client's own append |
| `event_bus.rs` | The `WebChannelEvent` broadcast channel plus approval/artifact/egress `DomainEvent` surface subscribers |
-| `web_errors.rs`, `web_errors_part_0{1,2,3}.rs` | Classifies raw provider error strings into user-facing copy; budget-exhausted / rate-limit / fallback-exhausted detection |
+| `web_errors.rs`, `web_errors_part_0{1,2,3}.rs` | Classifies raw provider error strings into user-facing copy; budget-exhausted / rate-limit / fallback-exhausted / timeout detection; the parts are `include!`d into `web_errors.rs` |
| `schemas.rs` | `ControllerSchema`/`RegisteredController` definitions for the `channel.web_*` RPC functions |
-| `types.rs` | `SessionEntry`, `SessionCacheFingerprint`, `InFlightEntry`, `ParallelEntry`, `WebChatTaskResult`, `ChatRequestMetadata`, RPC param structs |
+| `types.rs` | `SessionEntry`, `SessionCacheFingerprint`, `InFlightEntry`, `ParallelEntry`, `WebChatTaskResult`, `ChatRequestMetadata`, `WebChatParams` |
## RPC
@@ -97,52 +110,68 @@ Namespace `channel`, registered via
- Broadcasts `WebChannelEvent` (defined in `core/socketio.rs`) over an
in-process `tokio::sync::broadcast` channel. `core/socketio.rs` forwards it
to the connected Socket.IO client; `core/jsonrpc.rs` forwards the same
- stream to the JSON-RPC `/events` SSE endpoint.
+ stream to the JSON-RPC `/events` SSE endpoint; `channels/bus_part_01.rs`
+ subscribes to collect the reply for an inbound provider message.
- Subscribes to `DomainEvent` on `crate::core::bus::BUS` via three
- process-lifetime, `OnceLock`-guarded subscribers registered from
- `core/jsonrpc.rs`: `register_approval_surface_subscriber`
+ process-lifetime, `OnceLock`-guarded subscribers registered at startup from
+ `core/jsonrpc.rs` and `channels/runtime/startup_part_01.rs`:
+ `register_approval_surface_subscriber`
(`ApprovalRequested`/`PlanReviewRequested` → `approval_request` /
`plan_review_request`), `register_artifact_surface_subscriber`
- (`ArtifactPending`/`Ready`/`Failed` → `artifact_*`), and
+ (`ArtifactPending`/`ArtifactReady`/`ArtifactFailed` → `artifact_*`), and
`register_egress_surface_subscriber` (`ExternalTransferPending` →
`external_transfer_pending`, only when the transfer carries chat routing).
## Calls into
- `crate::agent::harness` — `Agent::from_config_for_agent_with_profile`,
- `run_queue::RunQueue`, and the tool-calling loop itself.
+ `run_queue::{RunQueue, QueueMode}`, and the tool-calling loop itself.
- `crate::agent::profiles::AgentProfileStore` — resolves the active profile
for `build_session_agent`.
- `crate::threads::turn_state::{TurnStateStore, TurnStateMirror}` — the
progress bridge mirrors turn state here for cross-surface visibility.
-- `crate::inference::provider` — `provider_for_role` resolves the
- provider binding used both for session fingerprinting and for `role_for_model_override`.
-- `crate::security::approval::APPROVAL_CHAT_CONTEXT` — scoped for the
- duration of a turn. `crate::web3::wallet::execution::current_owner()`
- relies on this task-local staying scoped through the inline `.await` chain
- in `run_chat_task`; detaching the tool loop onto a fresh `tokio::spawn`
- without re-scoping it would silently disable the quote-owner gate (see
- `web3/wallet/README.md`).
+- `crate::inference::provider::provider_for_role` — resolves the provider
+ binding for `provider_role_for_model_override`, which feeds the session
+ fingerprint.
+- `crate::security::approval::APPROVAL_CHAT_CONTEXT` — scoped by
+ `run_turn_under_cancel_and_deadline` around the `run_chat_task` future.
+ `crate::web3::wallet::execution::current_owner()` relies on this task-local
+ staying scoped through the inline `.await` chain in `run_chat_task`;
+ detaching the tool loop onto a fresh `tokio::spawn` without re-scoping it
+ would silently disable the quote-owner gate (see `web3/wallet/README.md`).
- `crate::memory::conversations` — `reply_persistence` appends the durable
reply row; `crate::memory::agent::memory_loader::MemoryCitation` carries
citations through to that row's metadata.
## Called by
-- `core/socketio.rs` — the `chat` and `cancel` Socket.IO handlers call
+- `core/socketio.rs` — the `chat:start` and `chat:cancel` handlers call
`start_chat` / `cancel_chat_scoped`, and forward `WebChannelEvent`s to the
client.
- `core/jsonrpc.rs` — subscribes the event stream for `/events` SSE and
registers the three `DomainEvent` surface subscribers at startup.
- `core/all.rs` — registers `all_web_channel_registered_controllers()` under
- the `channels` feature gate.
+ `DomainGroup::Channels`, deliberately *not* behind the `channels` feature
+ (the in-app chat is core product surface, #5002).
+- `channels/bus_part_01.rs` — inbound external-provider messages run through
+ `start_chat` with a per-sender `client_id`;
+ `channels/providers/telegram/remote_control.rs` calls
+ `invalidate_thread_sessions`.
+- `flows/ops_part_09.rs`/`ops_part_10.rs` and
+ `agent/task_dispatcher/executor.rs` — core-initiated turns reuse
+ `spawn_progress_bridge` and `presentation::deliver_response*` so they render
+ on the same socket surface.
+- `publish_web_channel_event` is also called from `cron`, `voice`,
+ `memory/tree/health`, `channels/proactive.rs`, and
+ `agent/task_dispatcher/registry.rs` for surface-level notifications.
## Tests
- `web_tests.rs` (+ `web_tests_part_01..04_tests.rs`) — end-to-end coverage
of `start_chat`/`cancel_*`/queue behavior.
-- `mod_test_support_tests.rs` — `test_support` module helpers re-exported
- through `mod.rs`.
+- `mod_test_support_tests.rs` — the `test_support` module
+ (`classify_error_for_test`, `ClassifiedErrorSnapshot`) exposed through
+ `mod.rs` for debug/test builds.
- Per-file unit tests: `event_bus_tests.rs`, `ops_budget_correlation_tests_tests.rs`,
`presentation_tests.rs` + `presentation_test_support_tests.rs`,
`progress_bridge_tests.rs`, `reply_persistence_tests.rs`, `run_task_tests.rs`.