runtime: allow cross-runtime workdir sessions

This commit is contained in:
2026-08-05 16:02:16 +09:00
parent 636dc14616
commit 36df79e561
3 changed files with 55 additions and 25 deletions
+26 -2
View File
@@ -3166,6 +3166,14 @@ fn current_worker_session_lock(
.clone()
}
fn runtime_local_owner_worker_id(
caller_runtime_id: &str,
target_runtime_id: &str,
caller_worker_id: u64,
) -> Option<String> {
(caller_runtime_id == target_runtime_id).then(|| caller_worker_id.to_string())
}
async fn open_current_worker_workdir_session_locked(
api: &WorkspaceApi,
runtime_id: &str,
@@ -3194,10 +3202,14 @@ async fn open_current_worker_workdir_session_locked(
link.workdir_id
),
})?;
let owner_worker_id = format!("{runtime_id}-{worker_id}");
let owner_worker_id = runtime_local_owner_worker_id(runtime_id, &workdir.runtime_id, worker_id);
let session = api
.runtime
.open_workdir_session(&workdir.runtime_id, &workdir.workdir_id, &owner_worker_id)
.open_workdir_session(
&workdir.runtime_id,
&workdir.workdir_id,
owner_worker_id.as_deref(),
)
.await
.map_err(|error| error.into_error())?;
let key = (runtime_id.to_string(), worker_id);
@@ -11226,6 +11238,18 @@ mod tests {
);
}
#[test]
fn workdir_session_owner_is_only_sent_for_same_runtime_worker() {
assert_eq!(
runtime_local_owner_worker_id("embedded-worker-runtime", "arcadia", 5),
None
);
assert_eq!(
runtime_local_owner_worker_id("arcadia", "arcadia", 30).as_deref(),
Some("30")
);
}
#[tokio::test]
async fn current_worker_workdir_routes_require_a_live_runtime_worker_identity() {
let workspace = tempfile::tempdir().unwrap();