MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / apply_sandbox_update_locked

Method apply_sandbox_update_locked

crates/openshell-server/src/compute/mod.rs:1122–1282  ·  view source on GitHub ↗
(
        &self,
        incoming: DriverSandbox,
        existing_record: Option<ObjectRecord>,
    )

Source from the content-addressed store, hash-verified

1120 }
1121
1122 async fn apply_sandbox_update_locked(
1123 &self,
1124 incoming: DriverSandbox,
1125 existing_record: Option<ObjectRecord>,
1126 ) -> Result<(), String> {
1127 let existing = existing_record
1128 .as_ref()
1129 .map(decode_sandbox_record)
1130 .transpose()?;
1131
1132 // If no existing record, create initial sandbox (first watch event for this sandbox)
1133 if existing.is_none() {
1134 use crate::persistence::WriteCondition;
1135 let now_ms = openshell_core::time::now_ms();
1136
1137 let session_connected = self.supervisor_sessions.has_session(&incoming.id);
1138 let mut phase = derive_phase(incoming.status.as_ref());
1139 let sandbox_name = incoming.name.clone();
1140
1141 let supervisor_promoted = session_connected
1142 && matches!(phase, SandboxPhase::Provisioning | SandboxPhase::Unknown);
1143 if supervisor_promoted {
1144 phase = SandboxPhase::Ready;
1145 }
1146
1147 let mut status = incoming
1148 .status
1149 .as_ref()
1150 .map(|s| public_status_from_driver(s, phase, 0));
1151 rewrite_user_facing_conditions(&mut status, None);
1152 if supervisor_promoted {
1153 ensure_supervisor_ready_status(&mut status, &sandbox_name);
1154 }
1155 let mut sandbox = Sandbox {
1156 metadata: Some(openshell_core::proto::datamodel::v1::ObjectMeta {
1157 id: incoming.id.clone(),
1158 name: sandbox_name,
1159 created_at_ms: now_ms,
1160 labels: std::collections::HashMap::new(),
1161 resource_version: 0,
1162 }),
1163 spec: None,
1164 status,
1165 };
1166 sandbox.set_phase(phase as i32);
1167
1168 self.store
1169 .put_if(
1170 Sandbox::object_type(),
1171 &incoming.id,
1172 sandbox.object_name(),
1173 &sandbox.encode_to_vec(),
1174 None,
1175 WriteCondition::MustCreate,
1176 )
1177 .await
1178 .map_err(|e| match e {
1179 crate::persistence::PersistenceError::Conflict {

Callers 3

apply_sandbox_updateMethod · 0.80
prune_missing_sandboxMethod · 0.80

Calls 15

now_msFunction · 0.85
derive_phaseFunction · 0.85
has_sessionMethod · 0.80
set_phaseMethod · 0.80
object_nameMethod · 0.80
update_from_sandboxMethod · 0.80
notifyMethod · 0.80
object_idMethod · 0.80

Tested by

no test coverage detected