diff --git a/Cargo.lock b/Cargo.lock index 60ebca454..6aa958eb8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1232,7 +1232,7 @@ version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "faf9468729b8cbcea668e36183cb69d317348c2e08e994829fb56ebfdfbaac34" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -1699,7 +1699,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d045de693cb712d0b22c6a64be5b953f67b3ce00ab5ad3dd5d8b441886ab8e1a" dependencies = [ "quote", - "syn 3.0.9", + "syn 2.0.119", ] [[package]] @@ -2107,7 +2107,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -5576,15 +5576,15 @@ dependencies = [ [[package]] name = "rustix" -version = "1.1.4" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" dependencies = [ "bitflags 2.13.2", "errno", "libc", "linux-raw-sys", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -5642,7 +5642,7 @@ dependencies = [ "security-framework", "security-framework-sys", "webpki-root-certs", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -5973,9 +5973,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7523beb55eece201a2356bee0bbca0d1ab466c14c07703b2e0ee6d42cb0c2c" +checksum = "9c187e0a369471c550af028cba56d4f4fa2a489ad28151ae95a4d340a2a8b782" dependencies = [ "serde_core", ] @@ -6521,7 +6521,7 @@ dependencies = [ "getrandom 0.4.3", "once_cell", "rustix", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -6717,9 +6717,9 @@ dependencies = [ [[package]] name = "toml" -version = "1.2.0+spec-1.1.0" +version = "1.2.1+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5ffcdf8f50436dbbfd675c1fe1b8e0854f42b7defea8584bdebe1aee900e561" +checksum = "d5755c51863cdac711f1956baf8eb9588e060755f7d3c4c979e70ea1e1f32cd7" dependencies = [ "indexmap", "serde_core", @@ -6732,9 +6732,9 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "1.1.2+spec-1.1.0" +version = "1.1.3+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b86d767906c6c42421dcba507eb9d203e779497710a47782a224bb871653053" +checksum = "173f25c883cd2176a2d8212155638c0a60d484a9d84546d270866f40f56b6e49" dependencies = [ "serde_core", ] @@ -7671,7 +7671,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] diff --git a/crates/bashkit/fuzz/Cargo.lock b/crates/bashkit/fuzz/Cargo.lock index 6b70a67be..3c0ef0c9b 100644 --- a/crates/bashkit/fuzz/Cargo.lock +++ b/crates/bashkit/fuzz/Cargo.lock @@ -951,7 +951,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -2616,15 +2616,15 @@ dependencies = [ [[package]] name = "rustix" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" dependencies = [ "bitflags 2.13.1", "errno", "libc", "linux-raw-sys", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -3523,7 +3523,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] diff --git a/crates/bashkit/tests/integration/ts_tenant_stress_tests.rs b/crates/bashkit/tests/integration/ts_tenant_stress_tests.rs index b1934ea9d..d021549ec 100644 --- a/crates/bashkit/tests/integration/ts_tenant_stress_tests.rs +++ b/crates/bashkit/tests/integration/ts_tenant_stress_tests.rs @@ -18,6 +18,17 @@ use std::time::Duration; /// headroom in `tenant` so the soak never fails on that cap instead. const MAX_ROUNDS: usize = 1000; +/// Allocation budget large enough that `max_duration` is what stops a runaway +/// loop. ZapCode charges one allocation per VM stack push and never decrements +/// the counter (`zapcode_vendor/sandbox.rs`, `track_allocation`), so +/// `max_allocations` is really a per-run budget of pushes: a `while (true) {}` +/// spends about one per iteration and a release build burns the 1,000,000 +/// default in a few milliseconds, while a debug build reaches a 300 ms +/// `max_duration` first. That made the release-mode nightly soak fail on a +/// tenant whose debug-mode PR run was green. This is ~100x the pushes a 300 ms +/// loop can make, so the clock binds in either profile. +const SPIN_ALLOCATIONS: usize = 1_000_000_000; + fn rounds() -> usize { std::env::var("BASHKIT_STRESS_ROUNDS") .ok() @@ -89,8 +100,9 @@ fn script(load: Load) -> &'static str { } async fn run(load: Load) { - // Only the runaway loop should end on time; the rest must end on their - // own limit (memory, stack) or finish, even in a slow debug build. + // The runaway loop ends on one of its own resource limits; the rest must + // end on their own limit (memory, stack) or finish, even in a slow debug + // build. let max_ms = if matches!(load, Load::Spin) { 300 } else { @@ -112,7 +124,19 @@ async fn run(load: Load) { ); } Load::Spin => { - assert_eq!(r.exit_code, 124, "{load:?} stderr: {}", r.stderr); + // `tenant` keeps the default `max_allocations`, so this loop + // races the push budget against its 300 ms `max_duration` and + // which one binds depends on how fast the build is: release + // burns the 1,000,000 default in milliseconds, debug reaches the + // clock first. Both are correct bounded termination, so neither + // is asserted here; the two tests at the end of this file pin + // each limit on its own, with a budget chosen so it cannot race. + assert_ne!(r.exit_code, 0, "{load:?} stdout: {}", r.stdout); + assert!( + r.stderr.contains("timed out") || r.stderr.contains("allocation limit exceeded"), + "{load:?} stderr: {}", + r.stderr + ); } Load::Recurse => { assert_ne!(r.exit_code, 0, "{load:?}"); @@ -255,3 +279,41 @@ async fn ts_host_call_loops_stop_at_the_wall_clock_limit() { "ran {elapsed:?} past a 500 ms limit" ); } + +/// A pure runaway loop, with no host calls to carry the deadline check, stops +/// on `max_duration` once its allocation budget is not what binds (TM-TS-027). +#[tokio::test] +async fn ts_runaway_loop_stops_on_the_wall_clock() { + let mut bash = Bash::builder() + .typescript_with_limits( + TypeScriptLimits::default() + .max_memory(16 * 1024 * 1024) + .max_duration(Duration::from_millis(300)) + .max_allocations(SPIN_ALLOCATIONS), + ) + .build(); + let r = exec_ts(&mut bash, script(Load::Spin)).await; + assert_eq!(r.exit_code, 124, "stderr: {}", r.stderr); + assert!(r.stderr.contains("timed out"), "stderr: {}", r.stderr); +} + +/// The allocation budget bounds the same loop on its own, well before a +/// generous `max_duration`, because the push counter never decreases. +#[tokio::test] +async fn ts_runaway_loop_stops_on_the_allocation_budget() { + let mut bash = Bash::builder() + .typescript_with_limits( + TypeScriptLimits::default() + .max_memory(16 * 1024 * 1024) + .max_duration(Duration::from_secs(60)) + .max_allocations(50_000), + ) + .build(); + let r = exec_ts(&mut bash, script(Load::Spin)).await; + assert_eq!(r.exit_code, 1, "stderr: {}", r.stderr); + assert!( + r.stderr.contains("allocation limit exceeded"), + "stderr: {}", + r.stderr + ); +} diff --git a/examples/hyperlight/host/Cargo.lock b/examples/hyperlight/host/Cargo.lock index 3db19814a..ed941f3ee 100644 --- a/examples/hyperlight/host/Cargo.lock +++ b/examples/hyperlight/host/Cargo.lock @@ -667,9 +667,9 @@ checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" [[package]] name = "rustix" -version = "1.1.4" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" dependencies = [ "bitflags", "errno", diff --git a/knowledge/runtimes/zapcode-runtime.md b/knowledge/runtimes/zapcode-runtime.md index 2f9edff8d..dc6099d94 100644 --- a/knowledge/runtimes/zapcode-runtime.md +++ b/knowledge/runtimes/zapcode-runtime.md @@ -66,6 +66,13 @@ Configurable via `TypeScriptLimits`: | Max stack depth | 512 | `.max_stack_depth(n)` | Prevent stack overflow | | Max allocations | 1,000,000 | `.max_allocations(n)` | Bound VM allocation count | +`max_allocations` counts VM stack pushes and array/object creations, and the +counter never decreases within a run (`zapcode_vendor/sandbox.rs`, +`track_allocation`), so it is a per-run budget of operations rather than a live +heap bound - that is `max_memory`. A `while (true) {}` spends about one per +iteration, so the 1M default stops a runaway loop after about 1M iterations +regardless of how little heap it holds. + Every VM entry charges source bytes, a fixed 4096 work units, and the microseconds each synchronous VM step ran to the request-scoped `ExecutionBudget`. Suspend/resume cycles and external/VFS callbacks retain the @@ -250,6 +257,16 @@ must hit only its own limit. It runs 3 rounds on every PR; heap, so a held 8 MiB string costs about 3x that during the call and counts against `max_memory`. +Decision (2026-11-11): the spin tenant asserts only that it stopped on one of +its own limits, because `max_allocations` and `max_duration` race and the +winner depends on build speed. A release build burns the 1M push budget in a +few milliseconds; a debug build reaches a 300 ms `max_duration` first. Pinning +exit 124 there passed every debug PR run and failed the release nightly soak. +Each limit is instead pinned on its own by +`ts_runaway_loop_stops_on_the_wall_clock` (budget raised so the clock binds) +and `ts_runaway_loop_stops_on_the_allocation_budget` (budget lowered so it +binds), both deterministic in either profile. + Nightly (`nightly.yml`): an ASan pass over the ts unit, threat-model, security and stress tests (`--features typescript`, filters `typescript threat_ts ts_tenant_stress zapcode`), and a `ts-stress-soak` job at 300 rounds in diff --git a/supply-chain/config.toml b/supply-chain/config.toml index 525a6d122..2eb905d8d 100644 --- a/supply-chain/config.toml +++ b/supply-chain/config.toml @@ -1934,7 +1934,7 @@ version = "0.3.0" criteria = "safe-to-deploy" [[exemptions.rustix]] -version = "1.1.4" +version = "1.1.6" criteria = "safe-to-deploy" [[exemptions.rustls]] diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index c2c57197a..3ae387734 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -105,8 +105,8 @@ user-login = "cfallin" user-name = "Chris Fallin" [[publisher.serde_spanned]] -version = "1.1.2" -when = "2026-10-08" +version = "1.1.3" +when = "2026-11-06" user-id = 6743 user-login = "epage" user-name = "Ed Page" @@ -119,15 +119,15 @@ user-login = "Darksonn" user-name = "Alice Ryhl" [[publisher.toml]] -version = "1.2.0+spec-1.1.0" -when = "2026-11-04" +version = "1.2.1+spec-1.1.0" +when = "2026-11-06" user-id = 6743 user-login = "epage" user-name = "Ed Page" [[publisher.toml_datetime]] -version = "1.1.2+spec-1.1.0" -when = "2026-10-08" +version = "1.1.3+spec-1.1.0" +when = "2026-11-06" user-id = 6743 user-login = "epage" user-name = "Ed Page"