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
Integrate awaited turn cancellation for reviewer deadlines
Steven Enamakeld465d4c279d6
diff --cc crates/openhuman-embed/README.mdindex 5d28376921,a1e18849c3..ac8c942d46--- a/crates/openhuman-embed/README.md+++ b/crates/openhuman-embed/README.md@@@ -79,24 -77,45 +79,50 @@@ that controllers emit. `CoreAgent` runfacade does not model yet; a raw call that keeps coming back is a candidatefor a typed method here.+ ## Cancelling one turn++ Acquire `Turn::cancellation_handle()` before sending a turn. The handle is+ cloneable and `cancel().await` waits for the turn to stop and for tracked+ commands to be reaped. The agent remains available for later turns:++ ```rust,no_run+ # async fn demo(agent: &openhuman_embed::Agent) -> Result<(), Box<dyn std::error::Error>> {+ let mut turn = agent.turn("Run the job.");+ let cancel = turn.cancellation_handle();+ let running = tokio::spawn(turn.send());+ // When the host receives an abort request:+ cancel.cancel().await;+ assert!(matches!(running.await?, Err(openhuman_embed::CoreError::TurnCancelled { .. })));+ # Ok(())+ # }+ ```++ Cancellation is scoped to this turn, including while waiting for inference.+ Before send, cancellation prevents dispatch; after completion it is a no-op.+ On Unix, the built-in shell, Node, Python and npm commands kill their process+ group, including descendants. Other platforms stop the direct command. Host+ tools that spawn independent tasks or processes must provide their own cleanup;+ MCP server lifecycles remain owned by the agent. Keep polling `send()` while+ awaiting cancellation, for example in a spawned task as above.+## Using it-Add the dependency with the default contributor features, or pick a narrow-host build:+Use the [pinned consumer bootstrap](CONSUMERS.md) to prepare source,+recursive submodules and the consumer-root Cargo patches together. It generates:```toml-[dependencies]-openhuman-embed = { git = "https://github.com/tinyhumansai/openhuman", package = "openhuman-embed" }+[features]+default = []+embed = ["dep:openhuman-embed"]-# or-openhuman-embed = { git = "https://github.com/tinyhumansai/openhuman", package = "openhuman-embed", default-features = false, features = ["inference", "mcp"] }+[dependencies]+openhuman-embed = { path = "vendor/openhuman/crates/openhuman-embed", optional = true, default-features = false }```+The dependency and generated patch sections belong in the host's workspace+root. Enabling `embed` still includes the core and its HTTP libraries; the+host's default build can leave that optional dependency disabled.+### A runtime and several agentsFor hosted TinyHumans inference and services, build the runtime withdiff --cc crates/openhuman-embed/src/error.rsindex de7a178f89,8564acf322..c4fd27234d--- a/crates/openhuman-embed/src/error.rs+++ b/crates/openhuman-embed/src/error.rs@@@ -26,35 -26,12 +26,41 @@@ use openhuman_core::core::StructuredRpc/// Error returned by every typed facade call.#[derive(Debug, thiserror::Error)]pub enum CoreError {+ /// The host cancelled the call and its provider future has stopped.+ #[error("{method}: cancelled")]+ Cancelled {+ /// Cancelled operation.+ method: &'static str,+ },+ /// The entire logical call exceeded its deadline, including repairs.+ #[error("{method}: deadline exceeded")]+ DeadlineExceeded {+ /// Expired operation.+ method: &'static str,+ },+ /// Requested JSON failed strict validation after bounded repair.+ #[error("{method}: {failure}")]+ StructuredOutput {+ /// Operation that refused the answer.+ method: &'static str,+ /// Safe accounting and classification metadata.+ failure: crate::structured::StructuredOutputFailure,+ },++ /// Model call refused before dispatch by a shared run or turn budget.+ #[error("{method}: {source}")]+ BudgetExceeded {+ /// Method that attempted the call.+ method: &'static str,+ /// Refusal including spend so far and outstanding reservations.+ source: crate::budget::BudgetExceeded,+ },+ /// The host cancelled this turn through its cancellation handle.+ #[error("{method}: turn cancelled")]+ TurnCancelled {+ /// RPC method the turn was dispatching.+ method: &'static str,+ },/// The domain returned a structured error envelope.#[error("{method}: {message}")]Domain {diff --cc crates/openhuman-embed/src/lib.rsindex 0e21a78857,7eb65983ad..ce783fc8f3--- a/crates/openhuman-embed/src/lib.rs+++ b/crates/openhuman-embed/src/lib.rs@@@ -118,11 -116,9 +118,12 @@@ pub mod modulespub mod process;#[cfg(feature = "channels")]pub mod profiles;+pub mod repository;+/// Explicit ordered fallback and truncation policies.+pub mod routing;mod runtime;mod turn;+ mod turn_cancellation;/// Core internals for `openhuman-tinyhumans` and `openhuman-rpc` only; see/// the module docs. Not part of the host-facing API.diff --cc crates/openhuman-embed/src/turn.rsindex 631ace0e29,5400b3e760..88d5a903ae--- a/crates/openhuman-embed/src/turn.rs+++ b/crates/openhuman-embed/src/turn.rs@@@ -257,11 -256,9 +257,12 @@@ pub struct Turnseed: Option<Vec<(String, String)>>,meter: Option<Box<dyn FnOnce(Option<LastTurnUsage>) + Send>>,response_format: Option<crate::complete::ResponseFormat>,+ structured_retries: u8,max_tokens: Option<u32>,+ provider_options: serde_json::Value,+ require_tool_call: bool,untrusted_input: bool,+ cancellation: Option<crate::TurnCancellation>,}impl Turn {@@@ -276,11 -272,9 +277,12 @@@seed: None,meter: None,response_format: None,+ structured_retries: 0,max_tokens: None,+ provider_options: serde_json::Value::Null,+ require_tool_call: false,untrusted_input: false,+ cancellation: None,}}@@@ -628,10 -599,6 +662,11 @@@// variant classification are logged; the error itself propagates// to the caller untouched.let tag = match err {++ crate::error::CoreError::TurnCancelled { .. } => "turn_cancelled",+ crate::error::CoreError::Cancelled { .. } => "cancelled",+ crate::error::CoreError::DeadlineExceeded { .. } => "deadline",+ crate::error::CoreError::StructuredOutput { .. } => "structured_output",+ crate::error::CoreError::BudgetExceeded { .. } => "budget_exceeded",crate::error::CoreError::Domain { .. } => "domain",crate::error::CoreError::Unavailable { .. } => "unavailable",crate::error::CoreError::Rpc { .. } => "rpc",diff --cc crates/openhuman-embed/tests/README.mdindex 87c6da7bb2,1c58a5bad6..51a55aadf4--- a/crates/openhuman-embed/tests/README.md+++ b/crates/openhuman-embed/tests/README.md@@@ -36,12 -36,9 +36,14 @@@ recorded on the wrong server| [`composio_agents.rs`](composio_agents.rs) | Two agents with their own `ComposioHostCredential` reach Composio with their own key only. || [`memory_facade.rs`](memory_facade.rs) | `Runtime::memory` over TinyMemory's in-memory reference engine keeps two tenant roots apart. || [`saas_profiles.rs`](saas_profiles.rs) | A `ProfileRuntime` (SaaS mode, in-process): two users on thread `t1` see only their own messages and ride their own credential, a held `ProfileHandle` keeps its profile from release, a relayed Telegram message lands on the user's `channel:` thread with its `channel_outbound` reply on that user's events only, and the process refuses any other core afterwards. Inference is `common::echo_inference` behind `common::PointedTransport`. |+| [`repository_tools.rs`](repository_tools.rs), [`repository_host_only.rs`](repository_host_only.rs) | Host-backed repository queries validate before dispatch, require redaction, fence and bound output, and remain isolated from shell/write/network under HostOnly, read-only, untrusted-input turns. See [repository contract](../src/repository/README.md). |+| [`completion_routing.rs`](completion_routing.rs) | Ordered endpoint fallback, bounded 2x/4x truncation retries, final unpinned gateway routing, images and accounting across all attempts. |+| [`tool_required_routing.rs`](tool_required_routing.rs) | Native host tool metadata for GPT, Kimi and MiniMax model IDs; premature JSON refusal; required successful execution before final schema; gateway options survive. |+| [`completion_cancellation.rs`](completion_cancellation.rs) | Cancellation acknowledged after the provider future stops, pre-cancelled calls make no request, and deadlines are typed. |+| [`structured_validation.rs`](structured_validation.rs) | Full schema constraints, invalid/external schema refusal before dispatch, typed failures and bounded repair usage. || [`public_api.rs`](public_api.rs) | Compile-time check that the host-facing types and signatures stay exported. |+ | [`turn_cancellation.rs`](turn_cancellation.rs) | Cancellation before send, during inference and during a builtin shell command; repeated requests and agent reuse. |+ | [`process_cancellation.rs`](process_cancellation.rs) | On Linux, dropping a command future kills its shell descendants. |## Runningdiff --cc docs/TEST-COVERAGE-MATRIX.mdindex 87b8dddc3e,912c2b7530..f4de2aec6c--- a/docs/TEST-COVERAGE-MATRIX.md+++ b/docs/TEST-COVERAGE-MATRIX.md@@@ -660,12 -660,7 +660,13 @@@ The thread JSONL store moved to `tinyag| 16.1.10 | One runtime per process | RU+RI | `crates/openhuman-embed/src/runtime/builder_tests.rs`, `crates/openhuman-embed/tests/harness_embed.rs` | ✅ | A second `Runtime` (or `Harness`) returns `AlreadyRunning` rather than sharing process-global keyring/event-bus/subscribers; a failed build releases the slot so a retry is possible || 16.1.11 | Many agents on one runtime | RU+RI | `crates/openhuman-embed/src/agent/spec_tests.rs`, `crates/openhuman-embed/tests/runtime_agents.rs` | ✅ | Three agents with different providers, access tiers, skills, MCP servers and action dirs; turns land on their own provider; per-agent MCP visibility; thread-scoped resume; duplicate/invalid ids and widening are refused || 16.1.12 | API-key credential for library mode | RU+RI | `crates/openhuman-core/src/security/credentials/api_key_tests.rs`, `crates/openhuman-embed/tests/runtime_agents.rs` | ✅ | Key stored as an `api-key` auth profile; wins over an expired session; managed inference sends it as a bearer with no `x-api-key`; auth state reports `credential = "api-key"` |+| 16.1.14 | Host-backed read-only repository toolset | RI | `crates/openhuman-embed/tests/repository_tools.rs`, `crates/openhuman-embed/tests/repository_host_only.rs` | ✅ | Validated tree/range/search/symbol/git queries delegate only to the host; mandatory redaction, fenced bounded output, sanitized failures, and real HostOnly + readonly + untrusted-input refusal of shell/write/network. |+| 16.1.15 | Strict structured output and bounded repair | RI | `crates/openhuman-embed/tests/structured_validation.rs`, `crates/openhuman-embed/tests/structured_turns.rs` | ✅ | Wrong types and numeric combinators refused, invalid/external schemas make no call, repair bounded with usage, terminal length rejected even for complete JSON. |+| 16.1.16 | Explicit routing ladders and required exploration | RI | `crates/openhuman-embed/tests/completion_routing.rs`, `crates/openhuman-embed/tests/tool_required_routing.rs`, `crates/openhuman-embed/tests/structured_turns.rs` | ✅ | Ordered fallbacks, bounded truncation retries, unpinned terminal provider selection, image/options preservation, accumulated reported costs, actual answering model and refusal of schema-valid output before successful tool execution |+| 16.1.19 | Pinned standalone Embed source consumer | Script+RI | `scripts/__tests__/embed-consumer-bootstrap.test.mjs` | ✅ | Exact SHA verification, inherited workspace edition, generated active patches, stable locked offline builds with optional Embed enabled/disabled, default dependency tree without HTTP, no untracked secrets or Git metadata, refused malformed/escaping patches and existing destinations |+| 16.1.17 | Enforced shared turn/run budgets | RU+RI | `crates/openhuman-embed/tests/budget_fanout.rs`, `vendor/tinyagents/vendor/tinyinference/crates/tinyinference-llm/src/model/budget_tests.rs` | ✅ | Atomic parent/child reservations, physical provider admission, conservative unknown spend, cancellation and output cap |+| 16.1.18 | Ordered bounded fanout | RI | `crates/openhuman-embed/tests/budget_fanout.rs` | ✅ | Input-order results, per-branch and child error isolation, branch ceilings, shared-budget concurrent refusal and empty fanout |+ | 16.1.13 | Awaited per-turn cancellation | RI | `crates/openhuman-embed/tests/turn_cancellation.rs`, `crates/openhuman-embed/tests/process_cancellation.rs` | ✅ | Before send, during inference and during a builtin shell command; agent reuse, concurrent cancellation handles, failure/drop acknowledgement, bounded and unbounded descendant termination plus direct-child reaping on Linux |## Summary