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
fix(agent): refuse invalid artifact offsets, never advertise a continuation that cannot advance (#6284)
M3gA-Minda33d2b089fbf
diff --git a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rs b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rsindex 39cd57ce88..72fe8c00fc 100644--- a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rs+++ b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod.rs@@ -52,13 +52,17 @@ pub(crate) fn artifact_read_target(tool_name: &str, args: &Value) -> Option<Arti.trim_start_matches("./").strip_prefix(ARTIFACT_ROOT).is_some_and(|rest| rest.starts_with('/'));+ // An absent or null offset starts at 0. A present one that is not a+ // non-negative integer that fits `usize` is not a read `file_read` serves+ // (it rejects it), so it is not an artifact read either; never reinterpret+ // it as 0.+ let offset = match args.get("offset") {+ None | Some(Value::Null) => 0,+ Some(value) => usize::try_from(value.as_u64()?).ok()?,+ };under_root.then(|| ArtifactRead {path: path.to_string(),- offset: args- .get("offset")- .and_then(Value::as_u64)- .and_then(|o| usize::try_from(o).ok())- .unwrap_or(0),+ offset,})}@@ -84,8 +88,13 @@ pub(crate) fn page_artifact_read(return content;}let start = read.offset;- // Saturating: the offset comes from the model's arguments.- let total = start.saturating_add(content.len());+ let Some(total) = start.checked_add(content.len()) else {+ // Only reachable with an offset no real read carries (`file_read`+ // rejects offsets past its at-most-10-MiB file). Bound the result but+ // advertise no continuation, since none could advance.+ let cut = crate::util::floor_char_boundary(&content, budget_bytes);+ return content[..cut].to_string();+ };let with_path = |next: usize| {format!("\n\n[artifact page: bytes {start}..{next} of {total}. Continue with file_read {{\"path\":\"{}\",\"offset\":{next}}}]",@@ -110,9 +119,9 @@ pub(crate) fn page_artifact_read(};let cut = crate::util::floor_char_boundary(&content, budget_bytes - longest);let trailer = if use_path {- with_path(start.saturating_add(cut))+ with_path(start + cut)} else {- without_path(start.saturating_add(cut))+ without_path(start + cut)};format!("{}{trailer}", &content[..cut])}diff --git a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rs b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rsindex b4e4bc57b8..924af826bc 100644--- a/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rs+++ b/crates/openhuman-core/src/agent/harness/tool_result_artifacts/mod_tests.rs@@ -352,7 +352,7 @@ fn artifact_read_target_follows_only_use_skill_into_a_wrapped_tool() {}#[test]-fn a_page_near_the_maximum_offset_does_not_overflow() {+fn a_page_near_the_maximum_offset_neither_overflows_nor_advertises_a_stuck_continuation() {let read = ArtifactRead {path: "artifacts/tool-results/s/shell/c.txt".to_string(),offset: usize::MAX - 10,@@ -364,4 +364,33 @@ fn a_page_near_the_maximum_offset_does_not_overflow() {page.is_ok(),"an offset near usize::MAX must not overflow the page arithmetic");+ let page = page.unwrap();+ assert!(+ page.len() <= 1_000,+ "the result is still bounded, got {} bytes",+ page.len()+ );+ assert!(+ !page.contains("Continue with"),+ "no continuation may be advertised when the next offset cannot advance"+ );+}++#[test]+fn artifact_read_target_rejects_an_explicit_invalid_offset() {+ let path = "artifacts/tool-results/s/shell/c.txt";+ for bad in [json!(-1), json!(1.5), json!("12")] {+ assert_eq!(+ artifact_read_target("file_read", &json!({"path": path, "offset": bad.clone()})),+ None,+ "offset {bad} is not a read file_read serves, so it must not become an artifact read at 0"+ );+ }+ for absent in [json!({"path": path}), json!({"path": path, "offset": null})] {+ assert_eq!(+ artifact_read_target("file_read", &absent).map(|read| read.offset),+ Some(0),+ "an absent or null offset reads from the start"+ );+ }}