runtime: remove runtime-owned id

This commit is contained in:
2026-07-13 17:38:09 +09:00
parent 6fedf81785
commit 49f085916e
17 changed files with 268 additions and 496 deletions
+19 -42
View File
@@ -36,9 +36,7 @@ use worker_runtime::http_server::{
RuntimeHttpWorkerLifecycleResponse, RuntimeHttpWorkerResponse, RuntimeHttpWorkersResponse,
RuntimeHttpWorkingDirectoriesResponse, RuntimeHttpWorkingDirectoryResponse,
};
use worker_runtime::identity::{
RuntimeId as EmbeddedRuntimeId, WorkerId as EmbeddedWorkerId, WorkerRef as EmbeddedWorkerRef,
};
use worker_runtime::identity::{WorkerId as EmbeddedWorkerId, WorkerRef as EmbeddedWorkerRef};
use worker_runtime::interaction::{
WorkerInput as EmbeddedWorkerInput, WorkerInputKind as EmbeddedWorkerInputKind,
};
@@ -1128,10 +1126,7 @@ pub struct EmbeddedWorkerRuntime {
}
fn embedded_runtime_options() -> EmbeddedRuntimeOptions {
let runtime_id = EmbeddedRuntimeId::new(EMBEDDED_RUNTIME_ID)
.expect("embedded runtime id is a non-empty literal");
EmbeddedRuntimeOptions {
runtime_id: Some(runtime_id),
display_name: Some("embedded".to_string()),
..EmbeddedRuntimeOptions::default()
}
@@ -1159,12 +1154,9 @@ impl EmbeddedWorkerRuntime {
store_root: impl Into<PathBuf>,
backend: std::sync::Arc<dyn worker_runtime::execution::WorkerExecutionBackend>,
) -> Result<Self, worker_runtime::error::RuntimeError> {
let runtime_id = EmbeddedRuntimeId::new(EMBEDDED_RUNTIME_ID)
.expect("embedded runtime id is a non-empty literal");
let runtime = worker_runtime::Runtime::with_fs_store_and_execution_backend(
FsRuntimeStoreOptions {
root: store_root.into(),
runtime_id: Some(runtime_id),
display_name: Some("embedded".to_string()),
limits: EmbeddedRuntimeOptions::default().limits,
},
@@ -1181,13 +1173,8 @@ impl EmbeddedWorkerRuntime {
}
pub fn from_runtime(workspace_id: impl AsRef<str>, runtime: worker_runtime::Runtime) -> Self {
let runtime_id = runtime
.runtime_id()
.ok()
.map(|id| id.as_str().to_string())
.unwrap_or_else(|| EMBEDDED_RUNTIME_ID.to_string());
Self {
runtime_id,
runtime_id: EMBEDDED_RUNTIME_ID.to_string(),
host_id: host_id_for_embedded_workspace(workspace_id.as_ref()),
runtime,
execution_enabled: false,
@@ -1196,10 +1183,7 @@ impl EmbeddedWorkerRuntime {
}
fn worker_ref(&self, worker_id: &str) -> Option<EmbeddedWorkerRef> {
Some(EmbeddedWorkerRef::new(
EmbeddedRuntimeId::new(self.runtime_id.clone())?,
EmbeddedWorkerId::parse(worker_id)?,
))
Some(EmbeddedWorkerRef::new(EmbeddedWorkerId::parse(worker_id)?))
}
fn can_stop_embedded_worker(
@@ -1704,7 +1688,7 @@ impl WorkspaceWorkerRuntime for EmbeddedWorkerRuntime {
match self.runtime.delete_worker(&worker_ref) {
Ok(result) => WorkerDeleteResult {
state: WorkerOperationState::Accepted,
runtime_id: result.runtime_id.to_string(),
runtime_id: self.runtime_id.clone(),
worker_id: result.worker_id.to_string(),
deleted: result.deleted,
diagnostics: Vec::new(),
@@ -2256,11 +2240,10 @@ impl WorkspaceWorkerRuntime for RemoteWorkerRuntime {
.profile
.clone()
.unwrap_or_else(|| embedded_profile_selector(&request.intent));
let runtime_id = EmbeddedRuntimeId::new(self.runtime_id.clone());
let profile_source = match default_profile_source_archive_http_source(
&profile,
&self.workspace_id,
runtime_id.as_ref(),
Some(self.runtime_id.as_str()),
&self.resource_broker,
&self.backend_base_url,
) {
@@ -2380,7 +2363,7 @@ impl WorkspaceWorkerRuntime for RemoteWorkerRuntime {
{
Ok(response) => WorkerDeleteResult {
state: WorkerOperationState::Accepted,
runtime_id: response.worker.runtime_id.to_string(),
runtime_id: self.runtime_id.clone(),
worker_id: response.worker.worker_id.to_string(),
deleted: response.worker.deleted,
diagnostics: Vec::new(),
@@ -2598,7 +2581,7 @@ fn default_profile_source_archive_source(
fn default_profile_source_archive_http_source(
profile: &ProfileSelector,
workspace_id: &str,
runtime_id: Option<&EmbeddedRuntimeId>,
runtime_id: Option<&str>,
resource_broker: &BackendResourceBroker,
backend_base_url: &str,
) -> Result<ProfileSourceArchiveSource, String> {
@@ -2636,7 +2619,7 @@ enum ProfileSourceArchiveTransport {
fn default_embedded_config_bundle(
profile: &ProfileSelector,
workspace_id: &str,
runtime_id: Option<&EmbeddedRuntimeId>,
runtime_id: Option<&str>,
resource_broker: &BackendResourceBroker,
archive_transport: ProfileSourceArchiveTransport,
) -> Result<ConfigBundle, String> {
@@ -2844,17 +2827,11 @@ fn remote_lifecycle_rejected(
fn embedded_runtime_diagnostic(error: &EmbeddedRuntimeError) -> RuntimeDiagnostic {
match error {
EmbeddedRuntimeError::RuntimeStopped { .. } => diagnostic(
EmbeddedRuntimeError::RuntimeStopped => diagnostic(
"embedded_runtime_stopped",
DiagnosticSeverity::Warning,
"Embedded Runtime is stopped".to_string(),
),
EmbeddedRuntimeError::WrongRuntime { .. }
| EmbeddedRuntimeError::WrongRuntimeCursor { .. } => diagnostic(
"embedded_runtime_wrong_identity",
DiagnosticSeverity::Warning,
"Embedded Runtime rejected a worker/runtime identity mismatch".to_string(),
),
EmbeddedRuntimeError::WorkerNotFound { .. } => diagnostic(
"embedded_worker_not_found",
DiagnosticSeverity::Warning,
@@ -3218,7 +3195,7 @@ mod tests {
fn embedded_builtin_decodal_profiles_resolve_through_archive() {
let root = tempfile::tempdir().unwrap();
let broker = BackendResourceBroker::default();
let runtime_id = EmbeddedRuntimeId::new("runtime-test".to_string()).unwrap();
let runtime_id = "runtime-test";
for selector in [
ProfileSelector::RuntimeDefault,
ProfileSelector::Builtin("builtin:companion".to_string()),
@@ -3230,7 +3207,7 @@ mod tests {
let bundle = default_embedded_config_bundle(
&selector,
"workspace-test",
Some(&runtime_id),
Some(runtime_id),
&broker,
ProfileSourceArchiveTransport::BackendResourceHandle,
)
@@ -3241,7 +3218,7 @@ mod tests {
.fetch_profile_source_archive(
worker_runtime::resource::BackendResourceFetchRequest {
handle: handle.clone(),
runtime_id: runtime_id.as_str().to_string(),
runtime_id: runtime_id.to_string(),
worker_id: None,
audit_correlation_id: handle.audit_correlation_id.clone(),
},
@@ -3269,11 +3246,11 @@ mod tests {
fn remote_default_bundle_inlines_profile_archive_for_standalone_runtime() {
let root = tempfile::tempdir().unwrap();
let broker = BackendResourceBroker::default();
let runtime_id = EmbeddedRuntimeId::new("remote:test".to_string()).unwrap();
let runtime_id = "remote:test";
let bundle = default_embedded_config_bundle(
&ProfileSelector::Builtin("builtin:coder".to_string()),
"workspace-test",
Some(&runtime_id),
Some(runtime_id),
&broker,
ProfileSourceArchiveTransport::Inline,
)
@@ -3294,11 +3271,11 @@ mod tests {
#[test]
fn remote_profile_source_archive_url_uses_workspace_id_not_host_id() {
let broker = BackendResourceBroker::default();
let runtime_id = EmbeddedRuntimeId::new("remote:test".to_string()).unwrap();
let runtime_id = "remote:test";
let source = default_profile_source_archive_http_source(
&ProfileSelector::Builtin("builtin:coder".to_string()),
"workspace-actual",
Some(&runtime_id),
Some(runtime_id),
&broker,
"http://127.0.0.1:8787/",
)
@@ -3319,12 +3296,12 @@ mod tests {
#[test]
fn embedded_archive_rejects_unknown_selectors() {
let broker = BackendResourceBroker::default();
let runtime_id = EmbeddedRuntimeId::new("runtime-test".to_string()).unwrap();
let runtime_id = "runtime-test";
assert!(
default_embedded_config_bundle(
&ProfileSelector::Builtin("builtin:missing".to_string()),
"workspace-test",
Some(&runtime_id),
Some(runtime_id),
&broker,
ProfileSourceArchiveTransport::BackendResourceHandle,
)
@@ -3334,7 +3311,7 @@ mod tests {
default_embedded_config_bundle(
&ProfileSelector::Named("custom".to_string()),
"workspace-test",
Some(&runtime_id),
Some(runtime_id),
&broker,
ProfileSourceArchiveTransport::BackendResourceHandle,
)
+21 -25
View File
@@ -3,7 +3,7 @@ use chrono::{Duration, Utc};
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use uuid::Uuid;
use worker_runtime::identity::{RuntimeId, WorkerId};
use worker_runtime::identity::WorkerId;
use worker_runtime::profile_archive::ProfileSourceArchive;
use worker_runtime::resource::{
BackendResourceClient, BackendResourceError, BackendResourceFetchRequest,
@@ -29,7 +29,7 @@ impl BackendResourceBroker {
pub fn issue_profile_source_archive_handle(
&self,
workspace_id: impl Into<String>,
runtime_id: Option<&RuntimeId>,
runtime_id: Option<&str>,
worker_id: Option<&WorkerId>,
archive: ProfileSourceArchive,
) -> BackendResourceHandle {
@@ -41,7 +41,7 @@ impl BackendResourceBroker {
kind: BackendResourceKind::ProfileSourceArchive,
workspace_id: workspace_id.clone(),
scope_id: Some("workspace-profile-source".to_string()),
runtime_id: runtime_id.map(|id| id.as_str().to_string()),
runtime_id: runtime_id.map(|id| id.to_string()),
worker_id: worker_id.map(|id| id.to_string()),
resource_id: archive.reference.id.clone(),
digest: archive.reference.digest.clone(),
@@ -57,7 +57,7 @@ impl BackendResourceBroker {
profile_source_graph: Some(archive.reference.source_graph.clone()),
};
let stored = StoredResource {
runtime_id: runtime_id.map(|id| id.as_str().to_string()),
runtime_id: runtime_id.map(|id| id.to_string()),
worker_id: worker_id.map(|id| id.to_string()),
handle: handle.clone(),
archive,
@@ -167,7 +167,7 @@ fn verify_handle_shape(handle: &BackendResourceHandle) -> Result<(), BackendReso
mod tests {
use super::*;
use std::collections::BTreeMap;
use worker_runtime::identity::{RuntimeId, WorkerId};
use worker_runtime::identity::WorkerId;
use worker_runtime::profile_archive::{
ProfileSourceArchive, ProfileSourceArchiveRef, ProfileSourceGraphSummary, sha256_hex,
};
@@ -214,13 +214,13 @@ mod tests {
fn request(
handle: BackendResourceHandle,
runtime_id: &RuntimeId,
runtime_id: &str,
worker_id: Option<&WorkerId>,
) -> BackendResourceFetchRequest {
BackendResourceFetchRequest {
audit_correlation_id: handle.audit_correlation_id.clone(),
handle,
runtime_id: runtime_id.as_str().to_string(),
runtime_id: runtime_id.to_string(),
worker_id: worker_id.map(|id| id.to_string()),
}
}
@@ -228,17 +228,17 @@ mod tests {
#[test]
fn broker_issues_and_verifies_profile_source_archive_handles() {
let broker = BackendResourceBroker::default();
let runtime_id = RuntimeId::new("runtime-test").unwrap();
let runtime_id = "runtime-test";
let handle = broker.issue_profile_source_archive_handle(
"workspace-test",
Some(&runtime_id),
Some(runtime_id),
None,
archive(),
);
let response = broker
.fetch_profile_source_archive(BackendResourceFetchRequest {
handle: handle.clone(),
runtime_id: runtime_id.as_str().to_string(),
runtime_id: runtime_id.to_string(),
worker_id: None,
audit_correlation_id: handle.audit_correlation_id.clone(),
})
@@ -250,19 +250,15 @@ mod tests {
#[test]
fn broker_rejects_runtime_mismatch() {
let broker = BackendResourceBroker::default();
let runtime_a = RuntimeId::new("runtime-a").unwrap();
let runtime_a = "runtime-a";
let handle = broker.issue_profile_source_archive_handle(
"workspace-test",
Some(&runtime_a),
Some(runtime_a),
None,
archive(),
);
let err = broker
.fetch_profile_source_archive(request(
handle,
&RuntimeId::new("runtime-b").unwrap(),
None,
))
.fetch_profile_source_archive(request(handle, "runtime-b", None))
.unwrap_err();
assert!(matches!(err, BackendResourceError::Unauthorized { .. }));
}
@@ -270,12 +266,12 @@ mod tests {
#[test]
fn broker_rejects_worker_mismatch() {
let broker = BackendResourceBroker::default();
let runtime_id = RuntimeId::new("runtime-test").unwrap();
let runtime_id = "runtime-test";
let worker_a = WorkerId::new(1);
let worker_b = WorkerId::new(2);
let handle = broker.issue_profile_source_archive_handle(
"workspace-test",
Some(&runtime_id),
Some(runtime_id),
Some(&worker_a),
archive(),
);
@@ -288,10 +284,10 @@ mod tests {
#[test]
fn broker_rejects_expiry_extension_from_request_handle() {
let broker = BackendResourceBroker::default();
let runtime_id = RuntimeId::new("runtime-test").unwrap();
let runtime_id = "runtime-test";
let handle = broker.issue_profile_source_archive_handle(
"workspace-test",
Some(&runtime_id),
Some(runtime_id),
None,
archive(),
);
@@ -314,10 +310,10 @@ mod tests {
#[test]
fn broker_rejects_policy_tampered_request_handle() {
let broker = BackendResourceBroker::default();
let runtime_id = RuntimeId::new("runtime-test").unwrap();
let runtime_id = "runtime-test";
let mut handle = broker.issue_profile_source_archive_handle(
"workspace-test",
Some(&runtime_id),
Some(runtime_id),
None,
archive(),
);
@@ -331,11 +327,11 @@ mod tests {
#[test]
fn broker_uses_stored_max_bytes_when_request_handle_is_tampered() {
let broker = BackendResourceBroker::default();
let runtime_id = RuntimeId::new("runtime-test").unwrap();
let runtime_id = "runtime-test";
let archive = archive_with_len((DEFAULT_PROFILE_SOURCE_ARCHIVE_MAX_BYTES + 1) as usize);
let mut handle = broker.issue_profile_source_archive_handle(
"workspace-test",
Some(&runtime_id),
Some(runtime_id),
None,
archive,
);
+4 -4
View File
@@ -6003,10 +6003,10 @@ mod tests {
let api = test_api(workspace.path()).await;
let broker = api.resource_broker.clone();
let archive = test_profile_archive();
let runtime_id = worker_runtime::identity::RuntimeId::new("runtime-test").unwrap();
let runtime_id = "runtime-test";
let handle = broker.issue_profile_source_archive_handle(
"workspace-test",
Some(&runtime_id),
Some(runtime_id),
None,
archive,
);
@@ -6022,7 +6022,7 @@ mod tests {
let response = client
.fetch_resource(worker_runtime::resource::BackendResourceFetchRequest {
audit_correlation_id: handle.audit_correlation_id.clone(),
runtime_id: runtime_id.as_str().to_string(),
runtime_id: runtime_id.to_string(),
worker_id: None,
handle: handle.clone(),
})
@@ -6035,7 +6035,7 @@ mod tests {
let error = client
.fetch_resource(worker_runtime::resource::BackendResourceFetchRequest {
audit_correlation_id: tampered.audit_correlation_id.clone(),
runtime_id: runtime_id.as_str().to_string(),
runtime_id: runtime_id.to_string(),
worker_id: None,
handle: tampered,
})