Skip to content

Commit 1c7ffa1

Browse files
committed
fix(cli): detect a sessionless topology before opening a session
The previous commit explained the topology after a relay RPC was rejected, but 'sandbox create' still spawned ssh first, so the failure surfaced through the subprocess as 'ssh exited with status 255' and the explanatory message was buried in wrapped stderr. Publish a SupervisorSession=False/NotApplicable condition in the public sandbox status when the driver reports SupervisorSessionModel::None, and have the CLI check it before attempting a session. When set, the CLI skips the connect/exec path entirely and prints the explanation directly: the sandbox is running, sessions are unavailable for this topology, egress is unaffected, and how to set a workload entrypoint when a command was supplied. The error-marker detection from the prior commit stays as the backstop for relay RPCs issued directly against an existing sandbox, where there is no create-time status to pre-check. Signed-off-by: Russell Bryant <rbryant@redhat.com>
1 parent 26e5a1a commit 1c7ffa1

2 files changed

Lines changed: 133 additions & 1 deletion

File tree

  • crates

‎crates/openshell-cli/src/run.rs‎

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,22 @@ fn validate_memory_quantity(value: &str) -> Result<String> {
333333
Ok(value.to_string())
334334
}
335335

336+
/// True when the gateway reports that this sandbox's topology never opens a
337+
/// supervisor session, so relay-backed operations cannot work.
338+
///
339+
/// Checked before attempting a session rather than after: the failure would
340+
/// otherwise surface through the `ssh` subprocess as `exit status 255`, which
341+
/// tells the reader nothing.
342+
fn sandbox_has_no_supervisor_session(sandbox: &Sandbox) -> bool {
343+
sandbox.status.as_ref().is_some_and(|status| {
344+
status.conditions.iter().any(|condition| {
345+
condition.r#type == "SupervisorSession"
346+
&& condition.status.eq_ignore_ascii_case("false")
347+
&& condition.reason == "NotApplicable"
348+
})
349+
})
350+
}
351+
336352
/// True when an error is the gateway rejecting a relay-backed operation because
337353
/// the sandbox's topology has no in-sandbox supervisor.
338354
fn is_no_supervisor_session_error(err: &miette::Report) -> bool {
@@ -1009,6 +1025,32 @@ pub async fn sandbox_create(
10091025
return Ok(());
10101026
}
10111027

1028+
// Skip the session entirely when the topology cannot serve one.
1029+
// Attempting it would spawn ssh, fail inside the subprocess, and
1030+
// surface as an opaque exit status.
1031+
if sandbox_has_no_supervisor_session(&last_sandbox) {
1032+
let had_command = !command.is_empty();
1033+
if !persist {
1034+
let names = [sandbox_name.clone()];
1035+
if let Err(err) = sandbox_delete(
1036+
&effective_server,
1037+
&names,
1038+
false,
1039+
workspace,
1040+
&effective_tls,
1041+
gateway_name,
1042+
)
1043+
.await
1044+
{
1045+
eprintln!("Failed to delete sandbox {sandbox_name}: {err}");
1046+
}
1047+
}
1048+
report_no_supervisor_session(&sandbox_name, had_command, persist);
1049+
return Err(miette::miette!(
1050+
"sandbox '{sandbox_name}' cannot open interactive sessions"
1051+
));
1052+
}
1053+
10121054
if command.is_empty() {
10131055
let connect_result = if persist {
10141056
sandbox_connect(&effective_server, &sandbox_name, &effective_tls, workspace)
@@ -7730,7 +7772,46 @@ mod tests {
77307772
assert!(sandbox_should_persist(true, None));
77317773
}
77327774

7733-
use crate::run::is_no_supervisor_session_error;
7775+
use crate::run::{is_no_supervisor_session_error, sandbox_has_no_supervisor_session};
7776+
7777+
#[test]
7778+
fn detects_the_sessionless_condition_on_a_sandbox() {
7779+
use openshell_core::proto::{Sandbox, SandboxCondition, SandboxStatus};
7780+
7781+
let sessionless = Sandbox {
7782+
status: Some(SandboxStatus {
7783+
conditions: vec![SandboxCondition {
7784+
r#type: "SupervisorSession".to_string(),
7785+
status: "False".to_string(),
7786+
reason: "NotApplicable".to_string(),
7787+
message: openshell_core::error::no_supervisor_session_message(),
7788+
last_transition_time: String::new(),
7789+
}],
7790+
..Default::default()
7791+
}),
7792+
..Default::default()
7793+
};
7794+
assert!(sandbox_has_no_supervisor_session(&sessionless));
7795+
7796+
// A supervisor that is merely not connected yet must not be mistaken
7797+
// for a topology that will never have one.
7798+
let still_settling = Sandbox {
7799+
status: Some(SandboxStatus {
7800+
conditions: vec![SandboxCondition {
7801+
r#type: "Ready".to_string(),
7802+
status: "False".to_string(),
7803+
reason: "SupervisorNotConnected".to_string(),
7804+
message: "Backend ready; waiting for supervisor session".to_string(),
7805+
last_transition_time: String::new(),
7806+
}],
7807+
..Default::default()
7808+
}),
7809+
..Default::default()
7810+
};
7811+
assert!(!sandbox_has_no_supervisor_session(&still_settling));
7812+
7813+
assert!(!sandbox_has_no_supervisor_session(&Sandbox::default()));
7814+
}
77347815

77357816
#[test]
77367817
fn detects_the_no_supervisor_session_rejection() {

‎crates/openshell-server/src/compute/mod.rs‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3750,6 +3750,7 @@ struct ComposedPhase {
37503750
phase: SandboxPhase,
37513751
session_connected: bool,
37523752
backend_ready_without_session: bool,
3753+
sessionless: bool,
37533754
}
37543755

37553756
impl ComposedPhase {
@@ -3775,6 +3776,7 @@ impl ComposedPhase {
37753776
backend_ready_without_session: backend_phase == SandboxPhase::Ready
37763777
&& !session_connected
37773778
&& !sessionless,
3779+
sessionless,
37783780
}
37793781
}
37803782

@@ -3785,6 +3787,9 @@ impl ComposedPhase {
37853787
spec: Option<&SandboxSpec>,
37863788
) {
37873789
rewrite_user_facing_conditions(status, spec);
3790+
if self.sessionless {
3791+
ensure_no_supervisor_session_status(status, sandbox_name);
3792+
}
37883793
if self.backend_ready_without_session {
37893794
ensure_supervisor_not_connected_status(status, sandbox_name);
37903795
} else if self.session_connected && self.phase == SandboxPhase::Ready {
@@ -3821,6 +3826,52 @@ fn ensure_supervisor_not_ready_status(status: &mut Option<SandboxStatus>, sandbo
38213826
);
38223827
}
38233828

3829+
/// Condition type advertising whether a sandbox can serve relay-backed
3830+
/// operations.
3831+
///
3832+
/// Carried in the public status so clients can tell that SSH, `exec`, port
3833+
/// forwarding, and file transfer are unavailable *before* attempting one,
3834+
/// rather than discovering it from a failed connection. Using a condition
3835+
/// avoids adding a field to the public `Sandbox` message.
3836+
pub const SUPERVISOR_SESSION_CONDITION: &str = "SupervisorSession";
3837+
3838+
fn upsert_condition(
3839+
status: &mut Option<SandboxStatus>,
3840+
sandbox_name: &str,
3841+
condition: SandboxCondition,
3842+
) {
3843+
let status = status.get_or_insert_with(|| SandboxStatus {
3844+
sandbox_name: sandbox_name.to_string(),
3845+
..Default::default()
3846+
});
3847+
3848+
let condition_type = condition.r#type.clone();
3849+
if let Some(existing) = status
3850+
.conditions
3851+
.iter_mut()
3852+
.find(|existing| existing.r#type == condition_type)
3853+
{
3854+
*existing = condition;
3855+
} else {
3856+
status.conditions.push(condition);
3857+
}
3858+
}
3859+
3860+
/// Record that this sandbox's topology never opens a supervisor session.
3861+
fn ensure_no_supervisor_session_status(status: &mut Option<SandboxStatus>, sandbox_name: &str) {
3862+
upsert_condition(
3863+
status,
3864+
sandbox_name,
3865+
SandboxCondition {
3866+
r#type: SUPERVISOR_SESSION_CONDITION.to_string(),
3867+
status: "False".to_string(),
3868+
reason: "NotApplicable".to_string(),
3869+
message: openshell_core::error::no_supervisor_session_message(),
3870+
last_transition_time: String::new(),
3871+
},
3872+
);
3873+
}
3874+
38243875
fn upsert_ready_condition(
38253876
status: &mut Option<SandboxStatus>,
38263877
sandbox_name: &str,

0 commit comments

Comments
 (0)