Skip to content

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

fix(subagent-host): keep observer cancellation authoritative over leader commits

Steven Enamakelc37552c609e1
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_result.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_result.rs
index 3cd0cafe09..eb8b57aa73 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_result.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_result.rs
@@ -39,18 +39,6 @@ pub(crate) async fn resolve_inline_driver_outcome(
.unwrap_or_else(|poisoned| poisoned.into_inner())
.remove(task_key);
- // TinyAgents returns an observer's cancellation independently from the
- // leader's durable lifecycle. The leader may commit after this observer
- // receives its cancellation but before this adapter reads persistence.
- // In that race, the explicit observer result remains authoritative for
- // this invocation; consulting the leader's record would turn cancellation
- // into a status mismatch and a provider error.
- if let Some(outcome) = cached.as_ref().filter(|host| {
- host.persistence_disposition == SubagentPersistenceDisposition::ObserverCancelled
- }) {
- return Ok((outcome.clone(), public_job_id));
- }
-
// The driver's persistence CAS result is authoritative. Another
// invocation can win terminal/pause persistence while this executor's
// host-side cache still contains its local loser. Read the same scoped
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs
index 4ef15f53f0..d458dae4eb 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle_tests.rs
@@ -473,5 +473,47 @@ async fn driver_inline_projection_returns_the_durable_winner_not_a_local_loser()
);
}
+#[tokio::test]
+async fn observer_cancel_survives_a_leader_commit_before_host_projection() {
+ let directory = tempfile::tempdir().unwrap();
+ let key = key();
+ let bundle = OpenHumanDriverBundle::new(directory.path().join("checkpoints")).unwrap();
+
+ // Model the Tiny driver ordering: this invocation has already received
+ // ObserverCancelled, then the independent leader commits before the host
+ // adapter reads the durable lifecycle record.
+ let mut observer = cached_outcome(SubagentRunStatus::Cancelled);
+ observer.persistence_disposition =
+ tinyagents_orchestration::subagent::SubagentPersistenceDisposition::ObserverCancelled;
+ bundle
+ .host_outcome
+ .lock()
+ .unwrap()
+ .insert(key.clone(), observer);
+ let mut leader = SubagentOutcome::cancelled("task");
+ leader.status = SubagentOutcomeKind::Completed;
+ leader.output = "leader result".into();
+ bundle
+ .persistence
+ .record_terminal(&key, &leader, None)
+ .await
+ .unwrap();
+
+ let result = tinytools::ToolResult::error(
+ serde_json::json!({"task_id":"public-job-42", "status":"cancelled"}).to_string(),
+ );
+ let (projected, public_job_id) =
+ resolve_inline_driver_outcome(result, &bundle, &key, "fallback-agent")
+ .await
+ .expect("observer cancellation must survive the leader's later commit");
+
+ assert_eq!(public_job_id, "public-job-42");
+ assert!(matches!(projected.status, SubagentRunStatus::Cancelled));
+ assert_eq!(
+ projected.persistence_disposition,
+ tinyagents_orchestration::subagent::SubagentPersistenceDisposition::ObserverCancelled
+ );
+}
+
#[path = "lifecycle_terminal_tests.rs"]
mod terminal_tests;