diff --git a/harness/harness-sdk/src/host_runs.rs b/harness/harness-sdk/src/host_runs.rs index 6c3e323c..16e6a22c 100644 --- a/harness/harness-sdk/src/host_runs.rs +++ b/harness/harness-sdk/src/host_runs.rs @@ -241,9 +241,10 @@ impl Host { } Ok(json!({"closed": closed, "errors": errors})) } - "session/send" => self.session_send(&p).await, + // Keep nested routing futures off the small Windows process-main stack. + "session/send" => Box::pin(self.session_send(&p)).await, "session/state" => self.session_state(&p).await, - "run/start" => self.run_start(&p).await, + "run/start" => Box::pin(self.run_start(&p)).await, "run/wait" => self.run_wait(&p).await, "run/respond" => self.run_respond(&p).await, "run/cancel" => { @@ -333,7 +334,7 @@ impl Host { "Safety overrides apply only to new turns" ); if kind == "message" { - return self.run_start(&json!({"session_id":sid,"text":input["text"],"submission_id":text(p,"submission_id")?,"limits":p["limits"],"safety":p["safety"],"instruction_addendum":p["instruction_addendum"],"auto_approver_context":p["auto_approver_context"],"compaction":p["compaction"],"output":p["output"],"content":input["content"]})).await; + return Box::pin(self.run_start(&json!({"session_id":sid,"text":input["text"],"submission_id":text(p,"submission_id")?,"limits":p["limits"],"safety":p["safety"],"instruction_addendum":p["instruction_addendum"],"auto_approver_context":p["auto_approver_context"],"compaction":p["compaction"],"output":p["output"],"content":input["content"]}))).await; } ensure!( p.get("auto_approver_context").is_none_or(Value::is_null) diff --git a/harness/harness-sdk/tests/attachments.rs b/harness/harness-sdk/tests/attachments.rs index cbaf9993..afd02e63 100644 --- a/harness/harness-sdk/tests/attachments.rs +++ b/harness/harness-sdk/tests/attachments.rs @@ -7,7 +7,7 @@ use std::{ time::Duration, }; use tokio::io::{AsyncReadExt, AsyncWriteExt}; -async fn exercise(managed: bool) { +async fn exercise(managed: bool, small_stack: bool) { let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); let url = format!("http://{}/v1", listener.local_addr().unwrap()); let requests = Arc::new(Mutex::new(vec![])); @@ -46,11 +46,32 @@ async fn exercise(managed: bool) { } }); let root = tempfile::tempdir().unwrap(); - let binary = PathBuf::from(env!("CARGO_BIN_EXE_sdk-test-host")); + let original = PathBuf::from(env!("CARGO_BIN_EXE_sdk-test-host")); + let binary = if small_stack { + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + let path = root.path().join("small-stack-host"); + let quoted = original.to_str().unwrap().replace('\'', "'\\''"); + std::fs::write( + &path, + format!("#!/bin/sh\nulimit -s 1024\nexec '{quoted}' \"$@\"\n"), + ) + .unwrap(); + std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o700)).unwrap(); + path + } + #[cfg(not(unix))] + { + panic!("Process-stack wrapper is Unix-only") + } + } else { + original.clone() + }; let builder = || { Harness::builder() .state_dir(root.path()) - .executable(&binary) + .executable(&original) .sandbox(Sandbox::Off) }; let harness = if managed { @@ -176,9 +197,19 @@ async fn exercise(managed: bool) { #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn attachments_work_in_process_and_managed_subprocess() { tokio::time::timeout(Duration::from_secs(120), async { - exercise(false).await; - exercise(true).await + exercise(false, false).await; + exercise(true, false).await }) .await .unwrap(); } + +/// Reproduce the small Windows process-main stack on Unix using an owned +/// wrapper. The normal native Windows test already exercises its real stack. +#[cfg(unix)] +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn managed_attachments_fit_a_small_host_stack() { + tokio::time::timeout(Duration::from_secs(120), exercise(true, true)) + .await + .unwrap(); +}