Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions crates/bashkit/fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 65 additions & 3 deletions crates/bashkit/tests/integration/ts_tenant_stress_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand All @@ -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:?}");
Expand Down Expand Up @@ -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
);
}
4 changes: 2 additions & 2 deletions examples/hyperlight/host/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions knowledge/runtimes/zapcode-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion supply-chain/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
12 changes: 6 additions & 6 deletions supply-chain/imports.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
Loading