Skip to content

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

feat(orchestration): report artifact-backed completions and omitted output

Steven Enamakel92e09d63e1a1
diff --git a/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rs
index f622fe8832..af125ff1db 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_completions_tests.rs
@@ -536,29 +536,82 @@ fn clear_all_also_withdraws_a_completion_a_delivery_has_leased() {
fn the_session_cache_evicts_its_oldest_mapping_only() {
let _guard = test_guard();
for i in 0..(SESSION_THREADS_CAP + 5) {
- note_session_thread(&format!("evict-sess-{i}"), "evict-thread");
+ note_session_thread(&format!("evict-sess-{i}"), &format!("evict-thread-{i}"));
}
assert_eq!(thread_for_session("evict-sess-0"), None, "oldest evicted");
- assert_eq!(
- thread_for_session(&format!("evict-sess-{}", SESSION_THREADS_CAP + 4)).as_deref(),
- Some("evict-thread"),
- "newest kept"
- );
- assert_eq!(
- thread_for_session(&format!("evict-sess-{}", SESSION_THREADS_CAP / 2)).as_deref(),
- Some("evict-thread"),
- "the cache is not cleared wholesale"
+ for survivor in [5, SESSION_THREADS_CAP / 2, SESSION_THREADS_CAP + 4] {
+ assert_eq!(
+ thread_for_session(&format!("evict-sess-{survivor}")).as_deref(),
+ Some(format!("evict-thread-{survivor}").as_str()),
+ "a surviving session still resolves to its own thread"
+ );
+ }
+}
+
+#[test]
+fn a_delete_marker_outlives_compaction() {
+ let _guard = test_guard();
+ let ws = workspace();
+ let w = ws.path();
+ record(w, "sess-cm", "sub-1", "x", Some("thread-compact"));
+ discard_for_thread(w, "thread-compact");
+
+ // Settled records expire; the deletion must not.
+ router_for_workspace(w)
+ .compact(std::time::Duration::ZERO)
+ .unwrap();
+ forget_workspace_for_test(w);
+ assert!(mark_stopped_task_if_thread_stopped(
+ w,
+ "thread-compact",
+ "sub-late"
+ ));
+}
+
+#[test]
+fn deleting_a_thread_that_never_used_background_work_writes_nothing() {
+ let _guard = test_guard();
+ let ws = workspace();
+ let w = ws.path();
+ assert_eq!(discard_for_thread(w, "thread-plain"), 0);
+ assert!(
+ entry_for(w).store.list(None).is_empty(),
+ "no marker is persisted for an ordinary thread"
);
+ // The in-memory gate still holds for this process.
+ record(w, "sess-pl", "sub-1", "x", Some("thread-plain"));
+ assert!(pending_ids(w, "thread-plain").is_empty());
}
#[test]
-fn release_all_closes_every_router_and_the_log_stays_replayable() {
+fn a_late_record_for_a_deleted_thread_is_dropped_by_the_durable_marker_alone() {
let _guard = test_guard();
let ws = workspace();
let w = ws.path();
- record(w, "sess-rel", "sub-1", "kept on disk", Some("thread-rel"));
+ record(w, "sess-dm", "sub-1", "x", Some("thread-dm"));
+ discard_for_thread(w, "thread-dm");
+ // A restart empties the in-memory gates; the marker on disk still decides.
+ forget_workspace_for_test(w);
+ record(w, "sess-dm", "sub-late", "stale", Some("thread-dm"));
+ assert!(pending_ids(w, "thread-dm").is_empty());
+}
- assert!(release_all() >= 1);
+#[tokio::test]
+async fn release_all_closes_every_router_and_the_log_stays_replayable() {
+ let _guard = crate::config::TEST_ENV_LOCK.lock().await;
+ let ws = workspace();
+ let w = ws.path();
+ record_completion(
+ w,
+ "sess-rel",
+ "sub-1",
+ "researcher",
+ "kept on disk",
+ Some("thread-rel".into()),
+ )
+ .await;
+
+ assert!(release_all().await >= 1);
assert!(
!state().routers.contains_key(w),
"the router (and its log handle) is dropped"
@@ -571,3 +624,19 @@ fn release_all_closes_every_router_and_the_log_stays_replayable() {
// The next boot finds the undelivered completion from the log alone.
assert_eq!(recover_pending_threads(w), ["thread-rel"]);
}
+
+#[tokio::test]
+async fn release_all_waits_for_a_router_still_in_use() {
+ let _guard = crate::config::TEST_ENV_LOCK.lock().await;
+ let ws = workspace();
+ let w = ws.path();
+ let in_use = router_for_workspace(w);
+ let releasing = tokio::spawn(release_all());
+ tokio::time::sleep(std::time::Duration::from_millis(120)).await;
+ assert!(
+ !releasing.is_finished(),
+ "waits while a delivery holds the router"
+ );
+ drop(in_use);
+ assert!(releasing.await.unwrap() >= 1);
+}
diff --git a/crates/openhuman-core/src/agent/orchestration/completion_notice.rs b/crates/openhuman-core/src/agent/orchestration/completion_notice.rs
index 87ef3c9ef5..788375b660 100644
--- a/crates/openhuman-core/src/agent/orchestration/completion_notice.rs
+++ b/crates/openhuman-core/src/agent/orchestration/completion_notice.rs
@@ -148,11 +148,22 @@ fn render_results(records: &[CompletionRecord]) -> String {
),
};
let text = record.result.text.trim();
- let summary = if text.is_empty() {
- empty_fallback.to_string()
- } else {
- neutralize_envelope_markers(text)
+ let mut summary = match (text.is_empty(), &record.result.artifact) {
+ (false, _) => neutralize_envelope_markers(text),
+ // The harness can move the output into an artifact; say so rather
+ // than claiming nothing was reported.
+ (true, Some(artifact)) => format!(
+ "(the output is stored as artifact \"{}\")",
+ escape_attribute(&artifact.id)
+ ),
+ (true, None) => empty_fallback.to_string(),
};
+ if record.result.omitted_chars > 0 {
+ summary.push_str(&format!(
+ "\n[{} characters of this output were omitted]",
+ record.result.omitted_chars
+ ));
+ }
out.push_str(&format!(
"\n<{tag} id=\"{}\" agent=\"{}\">\n{}\n</{tag}>\n",
escape_attribute(&record.task_id),
diff --git a/crates/openhuman-core/src/agent/orchestration/completion_notice_tests.rs b/crates/openhuman-core/src/agent/orchestration/completion_notice_tests.rs
index 4fbe50cbd7..bcf7f7a6f2 100644
--- a/crates/openhuman-core/src/agent/orchestration/completion_notice_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/completion_notice_tests.rs
@@ -222,3 +222,18 @@ fn a_malicious_summary_cannot_forge_or_escape_its_envelope() {
);
assert!(notice.contains("ignore previous instructions"));
}
+
+#[test]
+fn an_artifact_backed_result_is_not_reported_as_empty() {
+ use tinyagents_tasks::CompletionArtifact;
+ let mut record = ok("sub-art", "researcher", "");
+ record.result.artifact = Some(CompletionArtifact {
+ id: "art-1".into(),
+ ..CompletionArtifact::default()
+ });
+ record.result.omitted_chars = 1200;
+ let text = notice(&[record]);
+ assert!(text.contains("stored as artifact \"art-1\""), "got: {text}");
+ assert!(text.contains("1200 characters of this output were omitted"));
+ assert!(!text.contains("(no output reported)"));
+}