From bd47d064b59a16453912b16f21bf7e8caac2f1f1 Mon Sep 17 00:00:00 2001 From: Hare Date: Fri, 18 Sep 2026 01:12:38 +0900 Subject: [PATCH] fix: apply rustfmt to restore transaction changes --- crates/client/src/backend_runtime.rs | 4 +- crates/client/src/lib.rs | 8 +- crates/worker-runtime/src/http_server.rs | 2 +- crates/worker-runtime/src/runtime.rs | 86 +++++++++++---------- crates/worker-runtime/src/worker_backend.rs | 33 ++++---- crates/workspace-server/src/hosts.rs | 16 ++-- 6 files changed, 73 insertions(+), 76 deletions(-) diff --git a/crates/client/src/backend_runtime.rs b/crates/client/src/backend_runtime.rs index be87e70d4..6809c6409 100644 --- a/crates/client/src/backend_runtime.rs +++ b/crates/client/src/backend_runtime.rs @@ -17,9 +17,9 @@ pub use workspace_api::{ WorkerLaunchProfileCandidate as BackendWorkerLaunchProfileCandidate, WorkerLaunchRuntimeOption as BackendWorkerLaunchRuntimeOption, WorkerOperationState as BackendWorkerOperationState, - WorkerRestoreState as BackendWorkerRestoreState, WorkerRestoreResponse as BackendWorkerRestoreResponse, - WorkerRestoreResult as BackendWorkerRestoreResult, WorkerSummary as BackendWorkerSummary, + WorkerRestoreResult as BackendWorkerRestoreResult, + WorkerRestoreState as BackendWorkerRestoreState, WorkerSummary as BackendWorkerSummary, WorkerWorkspaceSummary as BackendWorkerWorkspaceSummary, WorkingDirectoryCreateRequest as BackendWorkingDirectoryCreateRequest, WorkingDirectoryCreateResponse as BackendWorkingDirectoryCreateResponse, diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index 005b126f1..1bb4b8d74 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -27,10 +27,10 @@ pub use backend_runtime::{ BackendWorkerCapabilitySummary, BackendWorkerImplementationSummary, BackendWorkerLaunchOptions, BackendWorkerLaunchProfileCandidate, BackendWorkerLaunchRuntimeOption, BackendWorkerLaunchTarget, BackendWorkerOperationState, BackendWorkerRestoreResponse, - BackendWorkerRestoreResult, BackendWorkerRestoreState, BackendWorkerSummary, BackendWorkerWorkspaceSummary, - BackendWorkingDirectorySummary, connect_backend_runtime, create_backend_worker, - get_backend_worker_launch_options, list_backend_stopped_workers, list_backend_workers, - restore_backend_worker, + BackendWorkerRestoreResult, BackendWorkerRestoreState, BackendWorkerSummary, + BackendWorkerWorkspaceSummary, BackendWorkingDirectorySummary, connect_backend_runtime, + create_backend_worker, get_backend_worker_launch_options, list_backend_stopped_workers, + list_backend_workers, restore_backend_worker, }; pub use backend_workspace::{ BackendWorkspace, BackendWorkspaceCatalogTarget, BackendWorkspaceClientError, diff --git a/crates/worker-runtime/src/http_server.rs b/crates/worker-runtime/src/http_server.rs index d5dc7e296..fadffb45c 100644 --- a/crates/worker-runtime/src/http_server.rs +++ b/crates/worker-runtime/src/http_server.rs @@ -60,7 +60,6 @@ use protocol::subscription::{ SubscriptionTerminationCode, }; use serde::{Deserialize, Serialize}; -use workspace_api::WorkerRestoreState; use std::collections::HashMap; use std::fmt; use std::net::SocketAddr; @@ -75,6 +74,7 @@ use workdir::{ WorkdirTransportError, WorkdirTransportErrorCode, }, }; +use workspace_api::WorkerRestoreState; const DEFAULT_RUNTIME_HTTP_PORT: u16 = 38800; pub const RUNTIME_HTTP_PROTOCOL_MIN_VERSION: u32 = 1; diff --git a/crates/worker-runtime/src/runtime.rs b/crates/worker-runtime/src/runtime.rs index 5c2078a63..b00ecde8a 100644 --- a/crates/worker-runtime/src/runtime.rs +++ b/crates/worker-runtime/src/runtime.rs @@ -1449,7 +1449,8 @@ impl Runtime { /// converges on its already-installed execution rather than spawning another /// controller. pub fn restore_worker(&self, worker_ref: &WorkerRef) -> Result { - self.restore_worker_operation(worker_ref)?.into_legacy_result() + self.restore_worker_operation(worker_ref)? + .into_legacy_result() } pub fn restore_worker_operation( @@ -1567,45 +1568,47 @@ impl Runtime { ); match commit { Ok(worker) => Ok(RuntimeWorkerRestoreResult::accepted(worker)), - Err(error) => match self.cleanup_failed_restore(&backend, worker_ref, &handle) { - Ok(()) => { - tracing::warn!( - worker_id = %worker_ref.worker_id, - error = %error, - "Worker restore commit failed and was rolled back" - ); - Ok(RuntimeWorkerRestoreResult::failed( - WorkerRestoreState::RolledBack, - "worker_restore_commit_rolled_back", - "Worker restore commit failed and cleanup completed", - )) - } - Err(cleanup_error) => { - tracing::error!( - worker_id = %worker_ref.worker_id, - error = %error, - cleanup_error = %cleanup_error, - "Worker restore requires reconciliation after commit and cleanup failures" - ); - if let Err(retain_error) = self.retain_restore_execution_evidence( - worker_ref, - handle, - worker_state, - working_directory, - ) { + Err(error) => { + match self.cleanup_failed_restore(&backend, worker_ref, &handle) { + Ok(()) => { + tracing::warn!( + worker_id = %worker_ref.worker_id, + error = %error, + "Worker restore commit failed and was rolled back" + ); + Ok(RuntimeWorkerRestoreResult::failed( + WorkerRestoreState::RolledBack, + "worker_restore_commit_rolled_back", + "Worker restore commit failed and cleanup completed", + )) + } + Err(cleanup_error) => { tracing::error!( worker_id = %worker_ref.worker_id, - error = %retain_error, - "failed to persist restore execution evidence; in-process reconciliation remains required" + error = %error, + cleanup_error = %cleanup_error, + "Worker restore requires reconciliation after commit and cleanup failures" ); + if let Err(retain_error) = self.retain_restore_execution_evidence( + worker_ref, + handle, + worker_state, + working_directory, + ) { + tracing::error!( + worker_id = %worker_ref.worker_id, + error = %retain_error, + "failed to persist restore execution evidence; in-process reconciliation remains required" + ); + } + Ok(RuntimeWorkerRestoreResult::failed( + WorkerRestoreState::ReconciliationRequired, + "worker_restore_reconciliation_required", + "Worker restore result is uncertain; reread or retry the Worker restore", + )) } - Ok(RuntimeWorkerRestoreResult::failed( - WorkerRestoreState::ReconciliationRequired, - "worker_restore_reconciliation_required", - "Worker restore result is uncertain; reread or retry the Worker restore", - )) } - }, + } } } WorkerExecutionSpawnResult::Rejected(_result) => { @@ -1617,8 +1620,7 @@ impl Runtime { } WorkerExecutionSpawnResult::RolledBack(_result) => { #[cfg(feature = "fs-store")] - self.lock()? - .record_restore_failure(worker_ref, _result)?; + self.lock()?.record_restore_failure(worker_ref, _result)?; Ok(RuntimeWorkerRestoreResult::failed( WorkerRestoreState::RolledBack, "worker_restore_rolled_back", @@ -7466,12 +7468,14 @@ mod tests { .unwrap(); runtime.stop_worker(&created.worker_ref, None).unwrap(); let before = runtime.worker_detail(&created.worker_ref).unwrap(); - backend.preflight_restore_result.lock().unwrap().replace( - WorkerExecutionResult::rejected( + backend + .preflight_restore_result + .lock() + .unwrap() + .replace(WorkerExecutionResult::rejected( WorkerExecutionOperation::Restore, "profile is no longer permitted", - ), - ); + )); let result = runtime .restore_worker_operation(&created.worker_ref) diff --git a/crates/worker-runtime/src/worker_backend.rs b/crates/worker-runtime/src/worker_backend.rs index a4c941aa4..ccb564b3b 100644 --- a/crates/worker-runtime/src/worker_backend.rs +++ b/crates/worker-runtime/src/worker_backend.rs @@ -1826,21 +1826,13 @@ where .lock() .unwrap_or_else(|poisoned| poisoned.into_inner()); if workers.contains_key(&worker_ref) { - let existing_worker_state = workers.get(&worker_ref).and_then(|worker| { - worker - .worker_state - .read() - .ok() - .map(|state| state.clone()) - }); + let existing_worker_state = workers + .get(&worker_ref) + .and_then(|worker| worker.worker_state.read().ok().map(|state| state.clone())); let existing_handle = WorkerExecutionHandle::new(worker_ref.clone(), self.backend_id()); drop(workers); - let cleanup = self.cleanup_unconnected_controller( - &handle, - &shutdown, - &tasks, - &worker_state, - ); + let cleanup = + self.cleanup_unconnected_controller(&handle, &shutdown, &tasks, &worker_state); let result = WorkerExecutionResult::busy( operation, match &cleanup { @@ -2170,12 +2162,15 @@ where drop(workers); if let Some(previous) = request.previous_working_directory.as_ref() { - let materializer = self.working_directory_materializer.as_ref().ok_or_else(|| { - WorkerExecutionResult::rejected( - WorkerExecutionOperation::Restore, - "Persisted Worker Workdir binding cannot be restored by this Runtime", - ) - })?; + let materializer = self + .working_directory_materializer + .as_ref() + .ok_or_else(|| { + WorkerExecutionResult::rejected( + WorkerExecutionOperation::Restore, + "Persisted Worker Workdir binding cannot be restored by this Runtime", + ) + })?; let current = materializer .working_directory_status(&previous.summary.working_directory_id) .map_err(|message| { diff --git a/crates/workspace-server/src/hosts.rs b/crates/workspace-server/src/hosts.rs index 2386c9548..1e71e2ab2 100644 --- a/crates/workspace-server/src/hosts.rs +++ b/crates/workspace-server/src/hosts.rs @@ -52,10 +52,10 @@ use worker_runtime::http_server::{ RuntimeHttpWorkerCompletionsResponse, RuntimeHttpWorkerDeleteResponse, RuntimeHttpWorkerInputResponse, RuntimeHttpWorkerLifecycleRequest, RuntimeHttpWorkerLifecycleResponse, RuntimeHttpWorkerResponse, - RuntimeHttpWorkerRestoreResponse, - RuntimeHttpWorkerWorkspaceApiRequest, RuntimeHttpWorkersResponse, - RuntimeHttpWorkingDirectoriesResponse, RuntimeHttpWorkingDirectoryResponse, - RuntimeHttpWorkspacePromptProjectionRequest, RuntimeHttpWorkspacePromptProjectionResponse, + RuntimeHttpWorkerRestoreResponse, RuntimeHttpWorkerWorkspaceApiRequest, + RuntimeHttpWorkersResponse, RuntimeHttpWorkingDirectoriesResponse, + RuntimeHttpWorkingDirectoryResponse, RuntimeHttpWorkspacePromptProjectionRequest, + RuntimeHttpWorkspacePromptProjectionResponse, }; use worker_runtime::identity::{ RuntimeWorkerRef, WorkerId as EmbeddedWorkerId, WorkerRef as EmbeddedWorkerRef, @@ -2350,11 +2350,9 @@ impl WorkspaceWorkerRuntime for EmbeddedWorkerRuntime { match self.runtime.restore_worker_operation(&worker_ref) { Ok(result) => { let diagnostics = match (result.reason_code, result.message) { - (Some(code), Some(message)) => vec![diagnostic( - code, - DiagnosticSeverity::Warning, - message, - )], + (Some(code), Some(message)) => { + vec![diagnostic(code, DiagnosticSeverity::Warning, message)] + } _ => Vec::new(), }; WorkerRestoreResult {