diff --git a/crates/protocol/src/subscription.rs b/crates/protocol/src/subscription.rs index b2d9352e..03459387 100644 --- a/crates/protocol/src/subscription.rs +++ b/crates/protocol/src/subscription.rs @@ -520,6 +520,10 @@ pub enum SubscriptionWorkerState { #[cfg_attr(feature = "typescript", derive(ts_rs::TS))] pub struct SubscriptionWorker { pub worker_id: SubscriptionWorkerId, + /// Set by the Workspace Server when projecting a Runtime-owned Worker to clients. + /// Runtime producers leave this unset because the connection identifies the Runtime. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub runtime_id: Option, /// Producer-owned monotonic revision for this Worker subject. pub subject_revision: u64, pub state: SubscriptionWorkerState, @@ -536,6 +540,9 @@ pub struct SubscriptionWorker { impl SubscriptionWorker { pub fn validate(&self) -> Result<(), SubscriptionValidationError> { self.worker_id.validate()?; + if let Some(runtime_id) = &self.runtime_id { + validate_identifier("runtime_id", runtime_id, MAX_RESOURCE_ID_BYTES)?; + } if let Some(working_directory_id) = &self.working_directory_id { working_directory_id.validate()?; } @@ -742,6 +749,7 @@ mod tests { fn worker(value: &str) -> SubscriptionWorker { SubscriptionWorker { worker_id: worker_id(value), + runtime_id: None, subject_revision: 0, state: SubscriptionWorkerState::Idle, workspace_id: Some("workspace-1".to_string()), diff --git a/crates/worker-runtime/src/runtime.rs b/crates/worker-runtime/src/runtime.rs index 9c90fd29..ac91e8b4 100644 --- a/crates/worker-runtime/src/runtime.rs +++ b/crates/worker-runtime/src/runtime.rs @@ -2117,6 +2117,7 @@ impl RuntimeState { }; Ok(SubscriptionWorker { worker_id, + runtime_id: None, subject_revision: self .worker_subject_revisions .get(&worker.worker_id) diff --git a/web/workspace/src/lib/generated/protocol.ts b/web/workspace/src/lib/generated/protocol.ts index c34e3cb1..ea5637d5 100644 --- a/web/workspace/src/lib/generated/protocol.ts +++ b/web/workspace/src/lib/generated/protocol.ts @@ -114,6 +114,11 @@ export type SubscriptionWorkerState = "idle" | "running" | "paused" | "stopped" export type EventSubscriptionSelector = { "topic": "runtime_workers" } | { "topic": "worker_lifecycle", worker_ids: SubscriptionWorkerIds, } | { "topic": "worker_protocol", worker_id: SubscriptionWorkerId, } | { "topic": "workspace_workers" } | { "topic": "workspace_workdirs" }; export type SubscriptionWorker = { worker_id: SubscriptionWorkerId, +/** + * Set by the Workspace Server when projecting a Runtime-owned Worker to clients. + * Runtime producers leave this unset because the connection identifies the Runtime. + */ +runtime_id?: string | null, /** * Producer-owned monotonic revision for this Worker subject. */