Skip to content

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

fix(attachments): bind the thread folder for raw appends and delegated turns (#7714)

M3gA-Minda0b6cf439749
diff --git a/crates/openhuman-core/src/agent/attachments/mod.rs b/crates/openhuman-core/src/agent/attachments/mod.rs
index 03fa715112..d59a9ba0c1 100644
--- a/crates/openhuman-core/src/agent/attachments/mod.rs
+++ b/crates/openhuman-core/src/agent/attachments/mod.rs
@@ -424,27 +424,6 @@ pub(crate) async fn stage(
Ok(out)
}
-/// Config and scope for a delegated reference: the explicit workspace, else
-/// the thread's folder, which is where the turn staged its uploads (#7714).
-async fn acting_config(
- workspace: Option<&tinytools::WorkspaceDescriptor>,
- thread_id: Option<&str>,
-) -> anyhow::Result<(Config, AttachmentAccessScope)> {
- let mut config = crate::config::rpc::load_config_with_timeout()
- .await
- .map_err(anyhow::Error::msg)?;
- let action_dir = match workspace {
- Some(workspace) => workspace.root.clone(),
- None => thread_action_dir(&config, &config.workspace_dir, thread_id).await?,
- };
- config.action_dir = action_dir;
- let scope = AttachmentAccessScope {
- external_channel: false,
- workspace: workspace.map(|workspace| workspace.root.clone()),
- };
- Ok((config, scope))
-}
-
/// Explicit image forwarding for delegation. A filename mentioned in prose
/// grants no read; only the typed argument or a legacy image marker does.
pub(crate) async fn delegation_prompt(
@@ -452,7 +431,6 @@ pub(crate) async fn delegation_prompt(
args: &serde_json::Value,
workspace: Option<&tinytools::WorkspaceDescriptor>,
origin: Option<&crate::agent::turn_origin::AgentTurnOrigin>,
- thread_id: Option<&str>,
) -> anyhow::Result<String> {
let mut prompt = prompt.to_string();
if let Some(value) = args.get("image_paths") {
@@ -476,7 +454,16 @@ pub(crate) async fn delegation_prompt(
) {
anyhow::bail!("local attachment reads are disabled for external channel input");
}
- let (config, scope) = acting_config(workspace, thread_id).await?;
+ let mut config = crate::config::rpc::load_config_with_timeout()
+ .await
+ .map_err(anyhow::Error::msg)?;
+ if let Some(workspace) = workspace {
+ config.action_dir = workspace.root.clone();
+ }
+ let scope = AttachmentAccessScope {
+ external_channel: false,
+ workspace: workspace.map(|workspace| workspace.root.clone()),
+ };
stage(&prompt, "delegation", &config, &scope).await
}
@@ -485,7 +472,6 @@ pub(crate) async fn has_resolvable_image(
prompt: &str,
workspace: Option<&tinytools::WorkspaceDescriptor>,
origin: Option<&crate::agent::turn_origin::AgentTurnOrigin>,
- thread_id: Option<&str>,
) -> anyhow::Result<bool> {
let rehydrated = crate::agent::multimodal::rehydrate_image_placeholders(&[
tinyagents_session::transcript::TranscriptMessage::user(prompt),
@@ -500,13 +486,22 @@ pub(crate) async fn has_resolvable_image(
if paths.is_empty() {
return Ok(false);
}
+ let mut config = crate::config::rpc::load_config_with_timeout()
+ .await
+ .map_err(anyhow::Error::msg)?;
if matches!(
origin,
Some(crate::agent::turn_origin::AgentTurnOrigin::ExternalChannel { .. })
) {
anyhow::bail!("local attachment reads are disabled for external channel input");
}
- let (config, scope) = acting_config(workspace, thread_id).await?;
+ if let Some(workspace) = workspace {
+ config.action_dir = workspace.root.clone();
+ }
+ let scope = AttachmentAccessScope {
+ external_channel: false,
+ workspace: workspace.map(|workspace| workspace.root.clone()),
+ };
for path in paths {
let path = legacy::migrate_path(&config, &path, &scope)
.await?
diff --git a/crates/openhuman-core/src/agent/attachments/mod_access_tests.rs b/crates/openhuman-core/src/agent/attachments/mod_access_tests.rs
index 7933e0f472..c58c39b78c 100644
--- a/crates/openhuman-core/src/agent/attachments/mod_access_tests.rs
+++ b/crates/openhuman-core/src/agent/attachments/mod_access_tests.rs
@@ -80,7 +80,6 @@ async fn delegation_rejects_malformed_explicit_paths_and_external_reads_before_c
"mention picture.png in prose",
&serde_json::json!({}),
None,
- None,
None
)
.await
@@ -98,7 +97,6 @@ async fn delegation_rejects_malformed_explicit_paths_and_external_reads_before_c
"task",
&serde_json::json!({"image_paths": image_paths}),
None,
- None,
None
)
.await
@@ -109,7 +107,6 @@ async fn delegation_rejects_malformed_explicit_paths_and_external_reads_before_c
&serde_json::json!({"image_paths": ["picture.png"]}),
None,
Some(&external_origin()),
- None,
)
.await
.unwrap_err();
@@ -175,8 +172,9 @@ async fn thread_folder_upload_is_staged_where_the_turn_reads_it() {
);
// Stage the way `start_chat` does, then read the way the turn does: its
- // config acts in the thread folder and the request scope names no
- // workspace of its own.
+ // request scope comes from a run context carrying the thread folder as its
+ // workspace (`run_task`), which a delegated child inherits along with a
+ // freshly loaded, global `action_dir` config.
let staged = stage(
UPLOAD,
"bound",
@@ -190,13 +188,13 @@ async fn thread_folder_upload_is_staged_where_the_turn_reads_it() {
.unwrap();
let (_, files) = parse(&staged);
assert_eq!(files.len(), 1);
- let turn_config = Config {
- action_dir: folder.clone(),
- ..config.clone()
- };
- let turn_scope = AttachmentAccessScope::default();
- assert!(!is_missing_local_reference(&turn_config, &files[0].path, &turn_scope).await);
- let path = resolve_path(&turn_config, &files[0].path, &turn_scope)
+ let mut context = crate::agent::tinyagents::host::OpenHumanRunContext::new();
+ context.workspace = Some(tinytools::WorkspaceDescriptor::new(folder.clone()));
+ let mut request = tinyinference_llm::model::ModelRequest::new(Vec::new());
+ attach_request_scope(&mut request, &context);
+ let turn_scope = take_request_scope(&mut request.metadata);
+ assert!(!is_missing_local_reference(&config, &files[0].path, &turn_scope).await);
+ let path = resolve_path(&config, &files[0].path, &turn_scope)
.await
.unwrap();
assert_eq!(tokio::fs::read(path).await.unwrap(), b"a");
diff --git a/crates/openhuman-core/src/agent/attachments/mod_tests.rs b/crates/openhuman-core/src/agent/attachments/mod_tests.rs
index 11de97ad9c..498362977d 100644
--- a/crates/openhuman-core/src/agent/attachments/mod_tests.rs
+++ b/crates/openhuman-core/src/agent/attachments/mod_tests.rs
@@ -320,7 +320,6 @@ async fn vision_without_explicit_references_fails_before_configuration_or_infere
assert!(!has_resolvable_image(
"Describe a filename mentioned only in prose: picture.png",
None,
- None,
None
)
.await
@@ -329,7 +328,6 @@ async fn vision_without_explicit_references_fails_before_configuration_or_infere
"task",
&serde_json::json!({ "image_paths": [42] }),
None,
- None,
None
)
.await
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/archetype_delegation.rs b/crates/openhuman-core/src/agent/orchestration/tools/archetype_delegation.rs
index eeae608434..b699dd5961 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/archetype_delegation.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/archetype_delegation.rs
@@ -194,7 +194,6 @@ pub(crate) async fn execute_archetype_delegation_with_live_parent(
.and_then(|ctx| ctx.workspace())
.or(run_context.workspace.as_ref()),
run_context.origin.as_ref(),
- run_context.thread_id.as_deref(),
)
.await
{
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/collapsed_delegation.rs b/crates/openhuman-core/src/agent/orchestration/tools/collapsed_delegation.rs
index 9ae3b82be8..20aee7b8e8 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/collapsed_delegation.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/collapsed_delegation.rs
@@ -370,7 +370,6 @@ pub(crate) async fn execute_collapsed_delegation_with_live_parent(
.and_then(|ctx| ctx.workspace())
.or(run_context.workspace.as_ref()),
run_context.origin.as_ref(),
- run_context.thread_id.as_deref(),
)
.await
{
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs b/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs
index ca59d0c171..4105c24c42 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs
@@ -255,7 +255,6 @@ pub(crate) async fn dispatch_subagent_with_live_parent(
prompt,
parent_workspace_descriptor.as_ref(),
run_context.origin.as_ref(),
- run_context.thread_id.as_deref(),
)
.await
{
diff --git a/crates/openhuman-core/src/threads/ops/crud.rs b/crates/openhuman-core/src/threads/ops/crud.rs
index 4b98e09c1b..4c4f187ccc 100644
--- a/crates/openhuman-core/src/threads/ops/crud.rs
+++ b/crates/openhuman-core/src/threads/ops/crud.rs
@@ -174,6 +174,19 @@ async fn message_append_with_config(
|| request.message.content.contains("[FILE:");
let durable_files = crate::agent::attachments::parse(&request.message.content).1;
let durable_upload = !durable_files.is_empty();
+ // Raw and durable uploads both live under the thread's working folder,
+ // where the turn reads them (#7714).
+ let workspace = if raw_upload || durable_upload {
+ crate::agent::attachments::thread_action_dir(
+ config,
+ persistence_dir,
+ Some(&request.thread_id),
+ )
+ .await
+ .map_err(|error| ThreadsError::Message(format!("stage user attachments: {error}")))?
+ } else {
+ config.action_dir.clone()
+ };
if durable_upload {
let image_count = durable_files
.iter()
@@ -200,14 +213,6 @@ async fn message_append_with_config(
"attachment count exceeds configured limit".into(),
));
}
- // Uploads were staged under the thread's working folder, if any.
- let workspace = crate::agent::attachments::thread_action_dir(
- config,
- persistence_dir,
- Some(&request.thread_id),
- )
- .await
- .map_err(|error| ThreadsError::Message(format!("validate user attachment: {error}")))?;
for file in &durable_files {
let scope = crate::agent::attachments::AttachmentAccessScope {
external_channel: matches!(
@@ -261,7 +266,7 @@ async fn message_append_with_config(
request.message.content = crate::agent::attachments::stage_turn(
&request.message.content,
Some(config),
- None,
+ Some(&tinytools::WorkspaceDescriptor::new(workspace)),
Some(&request.thread_id),
origin,
)
diff --git a/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs b/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs
index a1f7c22467..fac7e54950 100644
--- a/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs
+++ b/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs
@@ -265,3 +265,37 @@ async fn poster_only_user_metadata_is_rejected_before_persistence() {
.is_empty()
);
}
+
+#[tokio::test]
+async fn raw_append_stages_in_the_bound_thread_folder() {
+ let (temp, config) = setup().await;
+ let folder = temp.path().join("project");
+ std::fs::create_dir_all(&folder).unwrap();
+ let folder = folder.canonicalize().unwrap();
+ conversations::blocking::ensure_thread(
+ config.workspace_dir.clone(),
+ conversations::CreateConversationThread {
+ id: "bound".into(),
+ title: "Bound".into(),
+ created_at: "2026-10-04T00:00:00Z".into(),
+ parent_thread_id: None,
+ labels: None,
+ personality_id: None,
+ working_dir: Some(folder.to_string_lossy().into_owned()),
+ },
+ )
+ .await
+ .unwrap();
+ let mut raw = request("raw", "[IMAGE:data:image/png;base64,iVBORw0KGgo=]", "user");
+ raw.thread_id = "bound".into();
+ let staged = append_with_test_config(raw, &config, None)
+ .await
+ .unwrap()
+ .value
+ .data
+ .unwrap();
+ let (_, files) = crate::agent::attachments::parse(&staged.content);
+ assert_eq!(files.len(), 1);
+ assert!(folder.join(&files[0].path).is_file());
+ assert!(!config.action_dir.join("uploads").exists());
+}
diff --git a/crates/openhuman-core/src/web_chat/run_task.rs b/crates/openhuman-core/src/web_chat/run_task.rs
index f3c8051754..fc895d9773 100644
--- a/crates/openhuman-core/src/web_chat/run_task.rs
+++ b/crates/openhuman-core/src/web_chat/run_task.rs
@@ -114,11 +114,11 @@ pub(crate) async fn run_chat_task(
// `action_dir`. Applied before checkout so the session agent, its security
// policy (which grants `action_dir` as a trusted root) and its tools are
// all built on the thread's folder.
- if let Some(dir) =
- crate::threads::ops::thread_working_dir(config.workspace_dir.clone(), thread_id).await?
- {
+ let thread_dir =
+ crate::threads::ops::thread_working_dir(config.workspace_dir.clone(), thread_id).await?;
+ if let Some(dir) = &thread_dir {
log::debug!("[web-channel] thread working folder applied thread_id={thread_id}");
- config.action_dir = dir;
+ config.action_dir = dir.clone();
}
let model_override = normalize_model_override(model_override);
// The cached session (or a cold-boot resumed one) is the thread's single
@@ -158,6 +158,12 @@ pub(crate) async fn run_chat_task(
agent.set_on_progress(Some(progress_tx));
agent.set_run_queue(Some(run_queue));
agent.set_thread_id(Some(thread_id));
+ // Also the turn's workspace, so attachment reads and delegated sub-agents
+ // (which load a fresh config) use the folder its uploads were staged in
+ // (#7714). Same pattern as `agent_chat`'s per-turn cwd.
+ if let Some(dir) = thread_dir {
+ agent.set_workspace_descriptor(Some(tinytools::WorkspaceDescriptor::new(dir)));
+ }
let turn_state_store = TurnStateStore::new(config.workspace_dir.clone());
// Stamp the resolved agent onto the bridge metadata so the trace exporter
// can attribute the run (`agent.id` attr / `agent.turn:<id>` trace name).