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
feat(subagent-host): add pause checkpoint op for subagent runs
Steven Enamakel31b6f98130dd
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/mod.rs b/crates/openhuman-core/src/agent/subagent_host/ops/mod.rsindex 84d3dc24ef..261914febe 100644--- a/crates/openhuman-core/src/agent/subagent_host/ops/mod.rs+++ b/crates/openhuman-core/src/agent/subagent_host/ops/mod.rs@@ -16,7 +16,7 @@//! | `runner.rs` | `run_subagent`, `run_typed_mode` |//! | `graph.rs` | `run_subagent_via_graph` — the sub-agent turn graph + tools |//! | `checkpoint.rs` | `SubagentCheckpoint` — cap-hit summary |-//! | `pause_checkpoint.rs` | `write` — the on-disk pause snapshot for `continue_subagent` |+//! | `pause_checkpoint.rs` | `is_safe_task_id` — the guard for model-authored task ids |mod checkpoint;mod graph;diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/pause_checkpoint.rs b/crates/openhuman-core/src/agent/subagent_host/ops/pause_checkpoint.rsindex 3ee344741a..b8b29d133c 100644--- a/crates/openhuman-core/src/agent/subagent_host/ops/pause_checkpoint.rs+++ b/crates/openhuman-core/src/agent/subagent_host/ops/pause_checkpoint.rs@@ -1,23 +1,9 @@-//! Persisting a paused sub-agent so `continue_subagent` can resume it.+//! The task-id guard for paused sub-agents.//!-//! Distinct from [`super::checkpoint`], which summarises a *cap-hit* run into-//! resumable prose. This one is the on-disk conversation snapshot written when-//! a child exits early on `ask_user_clarification`.+//! The pause itself is a lifecycle record on the storage port+//! (`subagent_host::lifecycle`); a model-authored `task_id` still has to pass+//! [`is_safe_task_id`] before it names one.-/// Persist a paused sub-agent's conversation so `continue_subagent` can resume-/// it, returning the path actually written or `None` when it could not be.-///-/// Every failure here is logged at `error`, not `warn`. A checkpoint that was-/// not written is not a degraded nicety: the run is about to be reported as-/// `AwaitingUser`, the orchestrator will relay a `task_id` and ask the user to-/// answer, and the loss only becomes visible after they have — at which point-/// the answer has nowhere to go. That late, invisible failure is what #5928's-/// first acceptance criterion is about, and the `Option` this returns is what-/// lets the caller stop promising a resumable pause it did not achieve.-///-/// Its own module so each failure branch is reachable from a test, and so-/// `runner.rs` stays under the layout gate's line pin: point `checkpoint_dir` at a path that cannot be created, or at one-/// whose target file cannot be written./// Whether `task_id` is usable as a single filename component.////// This is untrusted input on its way into a path join. `continue_subagent`@@ -39,66 +25,6 @@ pub(crate) fn is_safe_task_id(task_id: &str) -> bool {.all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_'))}-pub(super) fn write(- checkpoint_dir: &std::path::Path,- task_id: &str,- data: &crate::agent::subagent_host::types::SubagentCheckpointData,-) -> Option<std::path::PathBuf> {- if !is_safe_task_id(task_id) {- tracing::error!(- task_id = %task_id,- dir = %checkpoint_dir.display(),- "[subagent_host] refusing to write a checkpoint under an unsafe task id; \- this pause will not be resumable from disk"- );- return None;- }-- if let Err(e) = std::fs::create_dir_all(checkpoint_dir) {- tracing::error!(- task_id = %task_id,- dir = %checkpoint_dir.display(),- error = %e,- "[subagent_host] could not create the checkpoint directory; this pause will not be \- resumable from disk"- );- return None;- }-- let json = match serde_json::to_string_pretty(data) {- Ok(json) => json,- Err(e) => {- tracing::error!(- task_id = %task_id,- error = %e,- "[subagent_host] could not serialize the checkpoint; this pause will not be \- resumable from disk"- );- return None;- }- };-- let checkpoint_path = checkpoint_dir.join(format!("{task_id}.json"));- if let Err(e) = std::fs::write(&checkpoint_path, json) {- tracing::error!(- task_id = %task_id,- path = %checkpoint_path.display(),- error = %e,- "[subagent_host] could not write the checkpoint; this pause will not be resumable \- from disk"- );- return None;- }-- tracing::info!(- task_id = %task_id,- path = %checkpoint_path.display(),- history_len = data.history.len(),- "[subagent_host] checkpoint written for awaiting_user"- );- Some(checkpoint_path)-}-#[cfg(test)]#[path = "runner_checkpoint_tests.rs"]mod tests;diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner_checkpoint_tests.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner_checkpoint_tests.rsindex cb8a6209c9..5e8db856bd 100644--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner_checkpoint_tests.rs+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner_checkpoint_tests.rs@@ -1,10 +1,4 @@-//! `write_pause_checkpoint` — the pause-persistence contract (#5928).-//!-//! Every failure branch returns `None`, and that `None` is what stops the-//! runner reporting a resumable `AwaitingUser` for a pause it never saved.-//! Before this, all three failures were logged at `warn` and then dropped, so-//! the orchestrator relayed a `task_id` and asked the user to answer a question-//! whose answer had nowhere to go.+//! The pause task-id guard and the checkpoint shape (#5928).use crate::agent::subagent_host::types::SubagentCheckpointData;@@ -30,73 +24,6 @@ fn checkpoint_data(task_id: &str) -> SubagentCheckpointData {}}-#[test]-fn a_written_checkpoint_returns_the_path_it_wrote() {- let dir = tempfile::tempdir().expect("tempdir");- let checkpoint_dir = dir.path().join("subagent_checkpoints");-- let written = super::write(&checkpoint_dir, "task-1", &checkpoint_data("task-1"))- .expect("a writable directory must produce a checkpoint");-- assert_eq!(- written,- checkpoint_dir.join("task-1.json"),- "the returned path must be the one the resume flow will read"- );- assert!(written.is_file(), "the checkpoint must exist on disk");-- // Round-trips: a resume reads this back with `serde_json::from_str`, so a- // path that exists but cannot be parsed is no better than a missing one.- let raw = std::fs::read_to_string(&written).expect("read back");- let parsed: SubagentCheckpointData = serde_json::from_str(&raw).expect("checkpoint parses");- assert_eq!(parsed.task_id, "task-1");- assert_eq!(parsed.question, "Which region?");-}--#[test]-fn the_directory_is_created_on_demand() {- // #5928 asks whether the checkpoint directory is created correctly on fresh- // installs. It is: nothing pre-creates it, `write_pause_checkpoint` does,- // including intermediate components.- let dir = tempfile::tempdir().expect("tempdir");- let nested = dir.path().join("a/b/c/subagent_checkpoints");- assert!(!nested.exists(), "precondition: nothing has created it");-- let written = super::write(&nested, "task-2", &checkpoint_data("task-2"))- .expect("a missing directory must be created, not treated as a failure");-- assert!(written.is_file());-}--#[test]-fn an_uncreatable_directory_reports_no_checkpoint() {- // A regular file where the directory should be: `create_dir_all` cannot- // succeed, and the pause is not resumable from disk.- let dir = tempfile::tempdir().expect("tempdir");- let blocked = dir.path().join("not_a_dir");- std::fs::write(&blocked, b"i am a file").expect("seed the blocker");-- assert!(- super::write(&blocked, "task-3", &checkpoint_data("task-3")).is_none(),- "a checkpoint directory that cannot exist must report no checkpoint, \- not a silently dropped warning"- );-}--#[test]-fn an_unwritable_target_reports_no_checkpoint() {- // The directory exists, but the checkpoint's own path is occupied by a- // directory, so the write cannot land.- let dir = tempfile::tempdir().expect("tempdir");- let checkpoint_dir = dir.path().join("subagent_checkpoints");- std::fs::create_dir_all(checkpoint_dir.join("task-4.json")).expect("occupy the target path");-- assert!(- super::write(&checkpoint_dir, "task-4", &checkpoint_data("task-4")).is_none(),- "a checkpoint whose write fails must report no checkpoint"- );-}-// ── task_id is untrusted on its way into a path (tinysweeper, #5951) ────────//// `continue_subagent` takes `task_id` from its tool arguments — model-authored@@ -106,24 +33,6 @@ fn an_unwritable_target_reports_no_checkpoint() {#[test]fn a_traversing_task_id_is_refused_rather_than_written() {- let dir = tempfile::tempdir().expect("tempdir");- let checkpoint_dir = dir.path().join("subagent_checkpoints");- let outside = dir.path().join("outside.json");-- assert!(- super::write(- &checkpoint_dir,- "../outside",- &checkpoint_data("../outside")- )- .is_none(),- "a traversing task id must not produce a checkpoint"- );- assert!(- !outside.exists(),- "the write must not land outside the checkpoint directory"- );-for bad in ["../../etc/cron.d/pwn","a/b",