Skip to content

Commit 54ab030

Browse files
committed
fix(mxc): keep sandbox Ready after a successful one-shot agent exec
monitor_exec demoted Ready->Error on exit 0 (reason ExecCompleted), so the positive demo (write hello.txt + exit) landed in Error phase. Keep Ready=True (reason AgentCompleted) on success; only non-zero exits go to ExecFailed. Tighten the positive lifecycle test to assert the terminal condition stays Ready=True/AgentCompleted. Verified live via gateway mock round-trip: phase now Provisioning->Ready with no demotion.
1 parent a0070cf commit 54ab030

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

‎crates/openshell-driver-mxc/src/driver.rs‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,21 +555,25 @@ async fn monitor_exec(
555555
match child.wait().await {
556556
Ok(status) if status.success() => {
557557
info!(sandbox = %sandbox.name, "MXC agent exec completed successfully");
558+
// A successful one-shot agent (exit 0) must NOT demote the sandbox to
559+
// Error. The isolation session is still alive until stop/deprovision,
560+
// and the demo's positive proof is "Ready + in-policy file written".
561+
// Keep Ready=True so derive_phase leaves the public phase at Ready.
558562
let done = make_sandbox_with_condition(
559563
&sandbox,
560564
&DriverCondition {
561565
r#type: "Ready".into(),
562-
status: "False".into(),
563-
reason: "ExecCompleted".into(),
564-
message: "Agent exec finished with exit code 0".into(),
566+
status: "True".into(),
567+
reason: "AgentCompleted".into(),
568+
message: "Agent exec finished successfully (exit code 0)".into(),
565569
last_transition_time: String::new(),
566570
},
567571
false,
568572
);
569573
let mut reg = registry.lock().await;
570574
if let Some(entry) = reg.get_mut(&sandbox_id) {
571575
entry.sandbox = done.clone();
572-
entry.phase_state = PhaseState::Stopped;
576+
entry.phase_state = PhaseState::Running;
573577
}
574578
drop(reg);
575579
let _ = watch_tx.send(sandbox_event(done));
@@ -773,6 +777,18 @@ mod lifecycle_tests {
773777
tokio::time::sleep(Duration::from_millis(100)).await;
774778
}
775779
assert!(found, "hello.txt should appear in the granted share folder");
780+
781+
// A successful one-shot agent (exit 0) must STAY Ready, not demote to
782+
// Error. Assert the terminal condition is Ready=True/AgentCompleted so the
783+
// positive demo shows a green Ready phase, not a red Error.
784+
let completed = wait_for(&backend, "sb-pos", |s| {
785+
ready_condition(s).is_some_and(|c| c.status == "True" && c.reason == "AgentCompleted")
786+
})
787+
.await;
788+
assert!(
789+
completed.is_some(),
790+
"sandbox should remain Ready=True (AgentCompleted) after a successful exec, never demote to Error"
791+
);
776792
}
777793

778794
#[tokio::test]

0 commit comments

Comments
 (0)