Skip to content

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

test(embed): cover physical dispatch observer outcomes

Steven Enamakel0d8fa1b32e8b
diff --git a/crates/openhuman-embed/src/complete_tests.rs b/crates/openhuman-embed/src/complete_tests.rs
index 24a9950f41..2a2fc0c8f1 100644
--- a/crates/openhuman-embed/src/complete_tests.rs
+++ b/crates/openhuman-embed/src/complete_tests.rs
@@ -169,6 +169,53 @@ async fn observer_fires_once_per_call_on_success_and_error() {
);
}
+#[derive(Default)]
+struct PhysicalRecorder(Arc<Mutex<Vec<(tinyagents_harness::observability::PhysicalDispatchMetadata, tinyagents_harness::observability::PhysicalDispatchOutcome)>>>);
+
+struct PhysicalTerminal {
+ recorder: Arc<Mutex<Vec<(tinyagents_harness::observability::PhysicalDispatchMetadata, tinyagents_harness::observability::PhysicalDispatchOutcome)>>>,
+ metadata: tinyagents_harness::observability::PhysicalDispatchMetadata,
+}
+
+impl tinyagents_harness::observability::PhysicalDispatchTerminal for PhysicalTerminal {
+ fn on_terminal(
+ self: Box<Self>,
+ outcome: tinyagents_harness::observability::PhysicalDispatchOutcome,
+ ) {
+ self.recorder.lock().unwrap().push((self.metadata.clone(), outcome));
+ }
+}
+
+impl tinyagents_harness::observability::PhysicalDispatchObserver for PhysicalRecorder {
+ fn on_start(
+ &self,
+ metadata: &tinyagents_harness::observability::PhysicalDispatchMetadata,
+ ) -> Box<dyn tinyagents_harness::observability::PhysicalDispatchTerminal> {
+ Box::new(PhysicalTerminal {
+ recorder: Arc::clone(&self.0),
+ metadata: metadata.clone(),
+ })
+ }
+}
+
+#[tokio::test]
+async fn physical_observer_reports_content_free_provider_outcome() {
+ let server = server_replying(body("hi", "stop")).await;
+ let recorder = Arc::new(PhysicalRecorder::default());
+ completer(&server)
+ .physical_observer(recorder.clone())
+ .complete(CompletionRequest::new("requested-model", vec![ChatMessage::user("private")]))
+ .await
+ .unwrap();
+
+ let events = recorder.0.lock().unwrap();
+ assert_eq!(events.len(), 1);
+ assert_eq!(events[0].0.requested_model.as_deref(), Some("requested-model"));
+ assert_eq!(events[0].1.status, tinyagents_harness::observability::PhysicalDispatchStatus::Succeeded);
+ assert_eq!(events[0].1.usage.as_ref().unwrap().input_tokens, 100);
+ assert_eq!(events[0].1.answered_model.as_deref(), Some("vendor/answered"));
+}
+
#[test]
fn json_reply_tolerates_one_code_fence() {
assert_eq!(
diff --git a/docs/gitbooks/en/developing/embed/concepts/completer.md b/docs/gitbooks/en/developing/embed/concepts/completer.md
index 5631c02fa2..9e7633a70b 100644
--- a/docs/gitbooks/en/developing/embed/concepts/completer.md
+++ b/docs/gitbooks/en/developing/embed/concepts/completer.md
@@ -52,3 +52,7 @@ Set `CompletionRequest::timeout_ms(120_000)` to bound each physical provider HTT
A physical timeout is an RPC transport failure, so an explicit `CompletionLadder` can try its next route. By contrast, `Completer::timeout(duration)` bounds the entire logical completion, including repair attempts, and returns terminal `DeadlineExceeded`. Cancellation also stops the ladder without fallback. You can use both bounds when the host needs separate physical and logical limits.
A timed-out physical attempt has unknown reported cost. Ladder aggregate cost stays unknown, and a budgeted call keeps its conservative reservation if no authoritative usage arrived. The remaining budget may therefore refuse a fallback before it sends another request. See the [routing guide](https://github.com/tinyhumansai/openhuman/blob/main/crates/openhuman-embed/ROUTING.md) for the explicit ladder API.
+
+## Provider dispatch observation
+
+Attach `Completer::physical_observer` to receive one content-free start and terminal outcome for each provider invocation. The observer runs inside budget admission, so a request refused by the budget produces no dispatch event. A dropped in-flight request reports cancellation; terminal outcomes carry duration and provider-reported usage when available. The existing `CompletionObserver` remains a logical completion hook and still fires once for the whole call, including structured repair attempts.