Skip to content

Commit 182770d

Browse files
committed
feat(cli): add sandbox create --timeout
Signed-off-by: Eric Curtin <[email protected]>
1 parent 576d08f commit 182770d

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ struct Cli {
505505
}
506506

507507
#[derive(Subcommand, Debug)]
508+
// `Sandbox` embeds `SandboxCommands`, which is intentionally large.
509+
#[allow(clippy::large_enum_variant)]
508510
enum Commands {
509511
// ===================================================================
510512
// SANDBOX COMMANDS
@@ -1579,6 +1581,11 @@ enum SandboxCommands {
15791581
)]
15801582
restart_policy: String,
15811583

1584+
/// Seconds to wait without provisioning progress before giving up
1585+
/// (default: 300, or `OPENSHELL_PROVISION_TIMEOUT`).
1586+
#[arg(long, value_name = "SECONDS")]
1587+
timeout: Option<std::num::NonZeroU32>,
1588+
15821589
/// Auto-create missing providers from local credentials.
15831590
///
15841591
/// Without this flag, an interactive prompt asks per-provider;
@@ -3416,6 +3423,7 @@ async fn run_async() -> Result<()> {
34163423
no_tty,
34173424
detach,
34183425
restart_policy,
3426+
timeout,
34193427
auto_providers,
34203428
no_auto_providers,
34213429
labels,
@@ -3511,6 +3519,7 @@ async fn run_async() -> Result<()> {
35113519
detach,
35123520
suppress_credential_warnings: no_credential_warnings,
35133521
restart_policy: &restart_policy,
3522+
provision_timeout_secs: timeout.map(std::num::NonZeroU32::get),
35143523
},
35153524
&cli.workspace,
35163525
&tls,
@@ -6373,6 +6382,20 @@ mod tests {
63736382
}
63746383
}
63756384

6385+
#[test]
6386+
fn sandbox_create_timeout_parses() {
6387+
let cli =
6388+
Cli::try_parse_from(["openshell", "sandbox", "create", "--timeout", "900"]).unwrap();
6389+
match cli.command {
6390+
Some(Commands::Sandbox {
6391+
command: Some(SandboxCommands::Create { timeout, .. }),
6392+
..
6393+
}) => assert_eq!(timeout, std::num::NonZeroU32::new(900)),
6394+
other => panic!("expected SandboxCommands::Create, got: {other:?}"),
6395+
}
6396+
assert!(Cli::try_parse_from(["openshell", "sandbox", "create", "--timeout", "0"]).is_err());
6397+
}
6398+
63766399
#[test]
63776400
fn sandbox_create_restart_policy_rejects_unknown_value() {
63786401
assert!(

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ pub struct SandboxCreateConfig<'a> {
458458
pub detach: bool,
459459
pub suppress_credential_warnings: bool,
460460
pub restart_policy: &'a str,
461+
pub provision_timeout_secs: Option<u32>,
461462
}
462463

463464
impl Default for SandboxCreateConfig<'_> {
@@ -489,6 +490,7 @@ impl Default for SandboxCreateConfig<'_> {
489490
detach: false,
490491
suppress_credential_warnings: false,
491492
restart_policy: "never",
493+
provision_timeout_secs: None,
492494
}
493495
}
494496
}
@@ -528,6 +530,7 @@ pub async fn sandbox_create(
528530
detach,
529531
suppress_credential_warnings,
530532
restart_policy,
533+
provision_timeout_secs,
531534
} = config;
532535

533536
if editor.is_some() && !command.is_empty() {
@@ -841,9 +844,13 @@ pub async fn sandbox_create(
841844
let mut last_error_reason = String::new();
842845
let mut last_condition_message = provisioning_blocker_message(sandbox.status.as_ref());
843846
let provision_timeout = Duration::from_secs(
844-
std::env::var("OPENSHELL_PROVISION_TIMEOUT")
845-
.ok()
846-
.and_then(|v| v.parse().ok())
847+
provision_timeout_secs
848+
.map(u64::from)
849+
.or_else(|| {
850+
std::env::var("OPENSHELL_PROVISION_TIMEOUT")
851+
.ok()
852+
.and_then(|v| v.parse().ok())
853+
})
847854
.unwrap_or(300),
848855
);
849856
let mut provisioning_idle_deadline = Instant::now() + provision_timeout;

‎docs/how-it-works/sandboxes/overview.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ Management operations remain available while startup is blocked. After repair,
11691169
the supervisor completes startup without recreating the sandbox. Starting a
11701170
stopped sandbox repeats configuration admission before launching its workload.
11711171
1172-
Image preparation and initial supervisor startup have an absolute deadline of 1800 seconds by default, independently of the CLI wait timeout. Operators can set `image_preparation_timeout_seconds` in `[openshell.gateway]` to any value from 1 through 86400. Each new create or explicit start stores its deadline. Progress events, configuration edits, and gateway or driver restarts cannot extend it. Changing the gateway setting affects new attempts only.
1172+
Image preparation and initial supervisor startup have an absolute deadline of 1800 seconds by default, independently of the CLI wait timeout. `sandbox create --timeout <seconds>` sets how long the CLI waits without provisioning progress (300 seconds by default); it does not change the gateway deadline. Operators can set `image_preparation_timeout_seconds` in `[openshell.gateway]` to any value from 1 through 86400. Each new create or explicit start stores its deadline. Progress events, configuration edits, and gateway or driver restarts cannot extend it. Changing the gateway setting affects new attempts only.
11731173
11741174
The first authenticated configuration report from the current supervisor ends preparation and starts a separate admission repair window (300 seconds by default). A slow image download therefore does not consume time reserved for fixing policy. During admission, an effective policy, settings, provider, profile, or attachment change resets the window from its stored change time. The first failed configuration load for that change grants another full window. Repeated failures, duplicate reports, and reconnects do not extend it; reaching `Ready` clears it.
11751175

0 commit comments

Comments
 (0)