Skip to content

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

fix(agent): keep the reserved Gmail actions read-only and harden the stub guard

Shanud1094a1dd3e3
diff --git a/src/openhuman/agent/harness/archivist/helpers.rs b/src/openhuman/agent/harness/archivist/helpers.rs
index 4ef54ee11b..c4a4596eef 100644
--- a/src/openhuman/agent/harness/archivist/helpers.rs
+++ b/src/openhuman/agent/harness/archivist/helpers.rs
@@ -11,9 +11,21 @@ use std::time::{SystemTime, UNIX_EPOCH};
/// delegation return path uses it to notice a sub-agent that emitted a
/// tool call instead of executing one (#6033).
pub(crate) fn looks_like_unexecuted_tool_call(text: &str) -> bool {
- text.contains("<tool_call>")
- || text.contains("{\"tool_calls\"")
- || text.contains("\"tool_use\"")
+ contains_tool_call_payload(text) || text.contains("\"tool_use\"")
+}
+
+/// Whether `text` carries a **call-shaped** payload — an XML tool-call span
+/// or a `tool_calls` JSON key.
+///
+/// Narrower than [`looks_like_unexecuted_tool_call`] on purpose: `"tool_use"`
+/// alone appears in ordinary prose about the protocol, which is fine for
+/// deciding whether stripping is worth attempting but not for deciding that
+/// a sub-agent produced no answer.
+///
+/// The JSON key is matched without assuming it opens the object, so a
+/// pretty-printed `{\n "tool_calls": [...]\n}` is recognised too.
+pub(crate) fn contains_tool_call_payload(text: &str) -> bool {
+ text.contains("<tool_call>") || text.contains("\"tool_calls\"")
}
/// Strip tool-call JSON blocks from an assistant response, leaving only the
diff --git a/src/openhuman/agent/harness/subagent_runner/tool_prep.rs b/src/openhuman/agent/harness/subagent_runner/tool_prep.rs
index 756708bf03..c39b77394b 100644
--- a/src/openhuman/agent/harness/subagent_runner/tool_prep.rs
+++ b/src/openhuman/agent/harness/subagent_runner/tool_prep.rs
@@ -54,6 +54,16 @@ const TOOL_FILTER_TOP_K_HEAVY: usize = 12;
/// produced a 276k-token first-iteration prompt, so an essential displaces
/// the lowest-ranked hit rather than growing the surface.
///
+/// **Every entry must be read-only.** These actions are forced onto a
+/// delegation whatever it asked for, so a write action here would hand a
+/// "read my email" task an unrequested side-effecting capability — and a
+/// `ComposioActionTool` does not override `external_effect`, so the
+/// approval middleware (which gates on `external_effect_with_args`) would
+/// not stop it. Prompt-injected instructions inside a fetched email could
+/// then act on the mailbox with no human in the loop. Send and the rest of
+/// the write surface stay where they were: reachable when the prompt
+/// actually asks for them, via the ranker.
+///
/// Only Gmail is seeded, deliberately. A wrong entry spends a slot on
/// every prompt for that toolkit, so add one only with a fixture-backed
/// repro — the ranker's general behaviour is the upstream fix.
@@ -64,8 +74,6 @@ const TOOLKIT_ESSENTIAL_ACTIONS: &[(&str, &[&str])] = &[(
"GMAIL_FETCH_EMAILS",
// The follow-up once `GMAIL_LIST_MESSAGES` has handed back bare ids.
"GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID",
- // Keeps the write path reachable when a read prompt wins the ranking.
- "GMAIL_SEND_EMAIL",
],
)];
diff --git a/src/openhuman/agent/harness/subagent_runner/tool_prep_tests.rs b/src/openhuman/agent/harness/subagent_runner/tool_prep_tests.rs
index 012b5f1aaf..58d137698a 100644
--- a/src/openhuman/agent/harness/subagent_runner/tool_prep_tests.rs
+++ b/src/openhuman/agent/harness/subagent_runner/tool_prep_tests.rs
@@ -95,14 +95,14 @@ fn essentials_are_reserved_ahead_of_ranked_hits() {
let names: Vec<&str> = selected.iter().map(|&i| actions[i].name.as_str()).collect();
assert_eq!(
- &names[..3],
- &[
- "GMAIL_FETCH_EMAILS",
- "GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID",
- "GMAIL_SEND_EMAIL"
- ],
+ &names[..2],
+ &["GMAIL_FETCH_EMAILS", "GMAIL_FETCH_MESSAGE_BY_MESSAGE_ID"],
"essentials come first, in table order"
);
+ assert!(
+ !names.contains(&"GMAIL_SEND_EMAIL"),
+ "a read prompt must not be handed the send action: {names:?}"
+ );
assert!(
names.contains(&"GMAIL_LIST_MESSAGES"),
"ranked hits still follow the essentials"
@@ -284,3 +284,28 @@ fn gmail_read_prompt_keeps_a_content_returning_action() {
);
}
}
+
+#[test]
+fn every_essential_action_is_read_only() {
+ // Essentials are forced onto a delegation whatever it asked for, so a
+ // write action here would hand a read task an unrequested
+ // side-effecting capability that the approval middleware does not gate
+ // (a ComposioActionTool does not override `external_effect`).
+ const WRITE_VERBS: &[&str] = &[
+ "SEND", "CREATE", "DELETE", "UPDATE", "PATCH", "MOVE", "MODIFY", "ADD", "REMOVE", "TRASH",
+ "REPLY", "FORWARD", "DRAFT",
+ ];
+ for (toolkit, essentials) in TOOLKIT_ESSENTIAL_ACTIONS {
+ for essential in *essentials {
+ let verb = essential
+ .split('_')
+ .nth(1)
+ .unwrap_or_default()
+ .to_ascii_uppercase();
+ assert!(
+ !WRITE_VERBS.contains(&verb.as_str()),
+ "{toolkit} essential {essential} is a write action; essentials must be read-only"
+ );
+ }
+ }
+}
diff --git a/src/openhuman/agent/orchestration/tools/dispatch.rs b/src/openhuman/agent/orchestration/tools/dispatch.rs
index 290a9786fe..f034fc03f2 100644
--- a/src/openhuman/agent/orchestration/tools/dispatch.rs
+++ b/src/openhuman/agent/orchestration/tools/dispatch.rs
@@ -169,6 +169,12 @@ pub(crate) async fn dispatch_subagent(
);
}
+ // Past this point the run is synchronous whichever mode was requested:
+ // the async branch above returns when it is taken, so a `PreferAsync`
+ // that fell through registers no durable worker either and its result
+ // must say so (#6033).
+ let mode = DispatchMode::Blocking;
+
let parent_session = parent_ctx
.as_ref()
.map(|p| p.session_id.clone())
@@ -497,10 +503,28 @@ fn format_subagent_failure(tool_name: &str, message: &str) -> String {
/// carries an answer and passes through untouched.
pub(crate) fn is_unexecuted_tool_call_stub(output: &str) -> bool {
use crate::openhuman::agent::harness::archivist::helpers::{
- looks_like_unexecuted_tool_call, strip_tool_calls_from_response,
+ contains_tool_call_payload, strip_tool_calls_from_response,
};
- looks_like_unexecuted_tool_call(output)
- && strip_tool_calls_from_response(output).trim().is_empty()
+ if !contains_tool_call_payload(output) {
+ // Prose merely naming a protocol field is not a stub.
+ return false;
+ }
+ // A whole-text JSON payload carrying `tool_calls` is a stub however it
+ // is formatted — line-based stripping cannot see that the object's
+ // inner members belong to the call rather than to an answer.
+ if let Ok(serde_json::Value::Object(map)) =
+ serde_json::from_str::<serde_json::Value>(output.trim())
+ {
+ if map.contains_key("tool_calls") {
+ return true;
+ }
+ }
+ // Otherwise (XML spans, mixed prose): a stub is what leaves no words
+ // behind once the markup is stripped. Structural punctuation is not an
+ // answer.
+ !strip_tool_calls_from_response(output)
+ .chars()
+ .any(char::is_alphanumeric)
}
/// The sentence appended to a blocking delegation's result.
@@ -512,6 +536,12 @@ pub(crate) fn is_unexecuted_tool_call_stub(output: &str) -> bool {
/// (#6033).
const INLINE_RESULT_NOTE: &str = "\n\n[INLINE_RESULT] This delegation ran inline and is complete as returned — there is no sub-agent worker for it. Do NOT call wait_subagent, list_subagents or continue_subagent for this delegation.";
+/// The same disclosure for a run that did **not** finish. It must not claim
+/// the result is complete — that would contradict the
+/// `[SUBAGENT_INCOMPLETE]` guardrail it is appended to — so it says only
+/// that there is no worker, and what to do instead.
+const NO_WORKER_NOTE: &str = "\n\n[INLINE_RESULT] This delegation ran inline and registered no sub-agent worker, so there is nothing to collect: do NOT call wait_subagent, list_subagents or continue_subagent for it. Re-delegate with a corrected prompt instead.";
+
/// Append [`INLINE_RESULT_NOTE`] when the dispatch was blocking.
pub(crate) fn with_inline_result_note(output: String, mode: DispatchMode) -> String {
if mode == DispatchMode::Blocking {
@@ -528,14 +558,16 @@ pub(crate) fn incomplete_envelope(
output: &str,
mode: DispatchMode,
) -> String {
- with_inline_result_note(
- format!(
- "[SUBAGENT_INCOMPLETE] the {tool_name} sub-agent {reason} and did not \
- finish. Below is partial progress only — do NOT report it as done or \
- re-run the identical delegation unchanged.\n\nPartial progress:\n{output}"
- ),
- mode,
- )
+ let envelope = format!(
+ "[SUBAGENT_INCOMPLETE] the {tool_name} sub-agent {reason} and did not \
+ finish. Below is partial progress only — do NOT report it as done or \
+ re-run the identical delegation unchanged.\n\nPartial progress:\n{output}"
+ );
+ if mode == DispatchMode::Blocking {
+ format!("{envelope}{NO_WORKER_NOTE}")
+ } else {
+ envelope
+ }
}
#[cfg(test)]
diff --git a/src/openhuman/agent/orchestration/tools/dispatch_tests.rs b/src/openhuman/agent/orchestration/tools/dispatch_tests.rs
index cc90228432..506e64d8d8 100644
--- a/src/openhuman/agent/orchestration/tools/dispatch_tests.rs
+++ b/src/openhuman/agent/orchestration/tools/dispatch_tests.rs
@@ -266,4 +266,49 @@ fn the_incomplete_envelope_frames_a_stub_without_claiming_success() {
assert!(envelope.contains("do NOT report it as done"));
assert!(envelope.contains("returned an unexecuted tool call"));
assert!(envelope.contains("[INLINE_RESULT]"));
+ assert!(
+ !envelope.contains("complete as returned"),
+ "an unfinished run must never be described as complete"
+ );
+ assert!(envelope.contains("Re-delegate with a corrected prompt"));
+}
+
+#[test]
+fn an_unfinished_envelope_never_claims_completeness() {
+ // The completed note and the not-finished note are deliberately
+ // different: appending "is complete as returned" under a
+ // [SUBAGENT_INCOMPLETE] header would contradict the guardrail.
+ let done = super::with_inline_result_note("answer".to_string(), super::DispatchMode::Blocking);
+ assert!(done.contains("complete as returned"));
+
+ let unfinished = super::incomplete_envelope(
+ "delegate_to_integrations_agent",
+ "hit its iteration cap",
+ "partial",
+ super::DispatchMode::Blocking,
+ );
+ assert!(!unfinished.contains("complete as returned"));
+ assert!(unfinished.contains("nothing to collect"));
+}
+
+#[test]
+fn a_pretty_printed_tool_call_payload_is_still_a_stub() {
+ // The marker is matched as a JSON key, not as "{\"tool_calls\"", so
+ // whitespace before it does not hide the payload; and the leftover
+ // braces are punctuation, not an answer.
+ assert!(super::is_unexecuted_tool_call_stub(
+ "{\n \"tool_calls\": [\n {\"name\": \"GMAIL_FETCH_EMAILS\"}\n ]\n}"
+ ));
+}
+
+#[test]
+fn prose_naming_a_protocol_field_is_not_a_stub() {
+ // "tool_use" alone is enough for the archivist to attempt a strip, but
+ // never enough to decide a sub-agent produced no answer.
+ assert!(!super::is_unexecuted_tool_call_stub(
+ "The \"tool_use\" field is how the provider reports a call."
+ ));
+ assert!(!super::is_unexecuted_tool_call_stub(
+ "I could not read the inbox: the connection is not authorised."
+ ));
}
diff --git a/src/openhuman/agent/orchestration/tools/tools_e2e_tests.rs b/src/openhuman/agent/orchestration/tools/tools_e2e_tests.rs
index ec3a608ca7..f34aa1e156 100644
--- a/src/openhuman/agent/orchestration/tools/tools_e2e_tests.rs
+++ b/src/openhuman/agent/orchestration/tools/tools_e2e_tests.rs
@@ -81,7 +81,18 @@ async fn archetype_delegation_tool_runs_child_agent_e2e() {
.expect("tool execution");
assert!(!result.is_error, "{}", result.output());
- assert_eq!(result.output(), "archetype-delegation-child-answer");
+ // This archetype delegation asks for async but has no delivery thread in
+ // a test, so it falls back to running inline — and a fallback registers
+ // no durable worker either, so the result says so (#6033).
+ let output = result.output();
+ assert!(
+ output.starts_with("archetype-delegation-child-answer"),
+ "the child's answer must lead the result: {output}"
+ );
+ assert!(
+ output.contains("[INLINE_RESULT]"),
+ "an async delegation that fell back to blocking must disclose that no worker exists: {output}"
+ );
assert!(provider.saw(ARCHETYPE_DELEGATION_CANARY));
}