protocol: identify workspace subscription runtimes

This commit is contained in:
2026-08-01 19:11:41 +09:00
parent 9308f93de7
commit 42c69f9f6c
3 changed files with 14 additions and 0 deletions
+8
View File
@@ -520,6 +520,10 @@ pub enum SubscriptionWorkerState {
#[cfg_attr(feature = "typescript", derive(ts_rs::TS))] #[cfg_attr(feature = "typescript", derive(ts_rs::TS))]
pub struct SubscriptionWorker { pub struct SubscriptionWorker {
pub worker_id: SubscriptionWorkerId, 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<String>,
/// Producer-owned monotonic revision for this Worker subject. /// Producer-owned monotonic revision for this Worker subject.
pub subject_revision: u64, pub subject_revision: u64,
pub state: SubscriptionWorkerState, pub state: SubscriptionWorkerState,
@@ -536,6 +540,9 @@ pub struct SubscriptionWorker {
impl SubscriptionWorker { impl SubscriptionWorker {
pub fn validate(&self) -> Result<(), SubscriptionValidationError> { pub fn validate(&self) -> Result<(), SubscriptionValidationError> {
self.worker_id.validate()?; 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 { if let Some(working_directory_id) = &self.working_directory_id {
working_directory_id.validate()?; working_directory_id.validate()?;
} }
@@ -742,6 +749,7 @@ mod tests {
fn worker(value: &str) -> SubscriptionWorker { fn worker(value: &str) -> SubscriptionWorker {
SubscriptionWorker { SubscriptionWorker {
worker_id: worker_id(value), worker_id: worker_id(value),
runtime_id: None,
subject_revision: 0, subject_revision: 0,
state: SubscriptionWorkerState::Idle, state: SubscriptionWorkerState::Idle,
workspace_id: Some("workspace-1".to_string()), workspace_id: Some("workspace-1".to_string()),
+1
View File
@@ -2117,6 +2117,7 @@ impl RuntimeState {
}; };
Ok(SubscriptionWorker { Ok(SubscriptionWorker {
worker_id, worker_id,
runtime_id: None,
subject_revision: self subject_revision: self
.worker_subject_revisions .worker_subject_revisions
.get(&worker.worker_id) .get(&worker.worker_id)
@@ -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 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, 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. * Producer-owned monotonic revision for this Worker subject.
*/ */