From 41453b3ff20ddf3b46edbd0db5a37fdd5f723c3d Mon Sep 17 00:00:00 2001 From: Dimitri Kennedy <344842+roodboi@users.noreply.github.com> Date: Thu, 26 Nov 2026 15:32:09 -0500 Subject: [PATCH 1/3] fix(runtime-core): give the owner lease test polling slack (HACK-2741) --- .../graph/foreground/dependency_refresh.rs | 28 +++++++++---------- .../tla/native-command-lease/COVERAGE.md | 9 ++++-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/packages/runtime-core/src/provider/graph/foreground/dependency_refresh.rs b/packages/runtime-core/src/provider/graph/foreground/dependency_refresh.rs index 9f67fdece..fd0d28498 100644 --- a/packages/runtime-core/src/provider/graph/foreground/dependency_refresh.rs +++ b/packages/runtime-core/src/provider/graph/foreground/dependency_refresh.rs @@ -410,7 +410,7 @@ mod automatic_tests { mod owner_lease_tests { use super::*; use crate::provider::engine::command_lease_tests::{ - PAST_ACQUISITION, PROJECT_STOP_REFUSAL, hold_lease, hold_lease_as_project_stop, + PROJECT_STOP_REFUSAL, assert_waited_then_acquired, hold_lease, hold_lease_as_project_stop, running_pool, }; use std::cell::Cell; @@ -448,9 +448,9 @@ mod owner_lease_tests { } /// HACK-2729: the requesting side's selection, before anything is sent to the - /// owner, outlasts a project stop (scaled: 600 ms against a 700 ms bound), and a - /// stop past its bound is refused with the raw, uncaused `provider_busy` naming - /// the stop. That is the refusal the CLI reports as "nothing ran". + /// owner, outlasts a project stop, and a stop past its bound is refused with + /// the raw, uncaused `provider_busy` naming the stop. That is the refusal the + /// CLI reports as "nothing ran". #[test] fn the_requested_selection_waits_out_a_project_stop_and_refuses_one_past_its_bound() { let (_home, candidate) = running_pool(); @@ -458,21 +458,21 @@ mod owner_lease_tests { let hold = Duration::from_millis(600); let (_release, holder) = hold_lease_as_project_stop(&candidate, hold); let started = Instant::now(); - let after = requested_selection(&candidate, &run, started + Duration::from_millis(700)) + // The backoff caps at 50 ms and is not scaled with the hold. Allow ten + // poll intervals for the holder to run, unlock and be observed on CI. + let deadline = started + hold + Duration::from_millis(500); + let after = requested_selection(&candidate, &run, deadline) .err() .unwrap(); - assert!(started.elapsed() >= hold - Duration::from_millis(50)); - assert_eq!(after.code, PAST_ACQUISITION, "{}", after.message); + assert_waited_then_acquired(started, hold, &after); holder.join().unwrap(); let (release, holder) = hold_lease_as_project_stop(&candidate, Duration::from_secs(30)); - let refused = requested_selection( - &candidate, - &run, - Instant::now() + Duration::from_millis(300), - ) - .err() - .unwrap(); + let deadline = Instant::now() + Duration::from_millis(300); + let refused = requested_selection(&candidate, &run, deadline) + .err() + .unwrap(); + assert!(Instant::now() >= deadline); assert_eq!(refused.code, "provider_busy"); assert_eq!(refused.message, PROJECT_STOP_REFUSAL); assert!(refused.cause_code.is_none()); diff --git a/tests/models/tla/native-command-lease/COVERAGE.md b/tests/models/tla/native-command-lease/COVERAGE.md index bb3471fed..b94813361 100644 --- a/tests/models/tla/native-command-lease/COVERAGE.md +++ b/tests/models/tla/native-command-lease/COVERAGE.md @@ -132,9 +132,12 @@ Tests: at the owner bound with the exact project-stop message and waited out by `connect_command_request`; a stop past the bound is refused with the raw, uncaused `provider_busy`. -- `dependency_refresh.rs` `owner_lease_tests`: the same for the refresh's - `requested_selection`, and the owner's selection refusal mapped to - `graph_dependency_refresh_lease_busy` while other codes are kept. +- `dependency_refresh.rs` `owner_lease_tests`: the refresh's `requested_selection` + waits out a 600 ms stop with 500 ms of slack for scheduling, unlock, and + polling at up to 50 ms per interval (HACK-2741). A stop held past the + deadline yields the exact raw `provider_busy` with no cause. The owner's + selection refusal maps to `graph_dependency_refresh_lease_busy`, and other + codes are kept. - `tests/native-command-lease.test.ts`, `tests/native-project-exec.test.ts`, `tests/native-project-dependency-refresh.test.ts`: the progress line (once across the refresh and the exec), the refusal for `hack exec` and `hack From 3cd1589316ce6a79e076aa4ff95b26c2a8b31650 Mon Sep 17 00:00:00 2001 From: Dimitri Kennedy <344842+roodboi@users.noreply.github.com> Date: Thu, 26 Nov 2026 18:53:02 -0500 Subject: [PATCH 2/3] fix(runtime-core): give authored exec lease tests polling slack (HACK-2751) --- .../provider/engine/command_lease_tests.rs | 29 ++++++++++--------- .../graph/foreground/dependency_refresh.rs | 8 ++--- .../tla/native-command-lease/COVERAGE.md | 17 ++++++----- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/packages/runtime-core/src/provider/engine/command_lease_tests.rs b/packages/runtime-core/src/provider/engine/command_lease_tests.rs index 45e3e5478..6af2d5f2d 100644 --- a/packages/runtime-core/src/provider/engine/command_lease_tests.rs +++ b/packages/runtime-core/src/provider/engine/command_lease_tests.rs @@ -318,6 +318,10 @@ pub(in crate::provider) fn hold_lease_as_project_stop( pub(in crate::provider) const PROJECT_STOP_REFUSAL: &str = "Provider lease acquisition refused; recorded holder: project stop; no operation was admitted."; +/// Scaling down the test's stop leaves the lease backoff capped at 50 ms. Allow +/// ten such intervals for scheduling, unlocking and observing the release. +pub(in crate::provider) const PROJECT_STOP_POLL_SLACK: Duration = Duration::from_millis(500); + /// HACK-2729: the requesting process of `hack exec` (its dependency refresh and the /// exec) waits as long as a start does, which covers another project's stop; the /// owner-side waits, which run on an owner's only loop thread, keep 15 s. @@ -348,10 +352,9 @@ fn the_requesting_side_of_exec_waits_as_long_as_a_start_and_the_owner_side_keeps assert_eq!(command_lease_deadline(now, near, COMMAND_LEASE_WAIT), near); } -/// HACK-2729, scaled 50 times (15 s is 300 ms, 35 s is 700 ms): a project stop holds -/// the lease for 600 ms. At the owner-side bound the wait refuses with the exact -/// project-stop refusal the CLI reads; the requesting side's bound outlasts the -/// stop and acquires right after it, before any check of its own. +/// HACK-2729: the scaled owner-side bound of 300 ms refuses a 600 ms project +/// stop with the exact message the CLI reads. The requester waits out the stop +/// with enough slack for polling and proceeds to the post-acquisition check. #[test] fn a_requested_command_waits_out_a_project_stop_that_the_owner_bound_refuses() { let (_home, candidate) = running_pool(); @@ -369,7 +372,7 @@ fn a_requested_command_waits_out_a_project_stop_that_the_owner_bound_refuses() { let after = Engine::connect_command_request( &candidate, - Instant::now() + Duration::from_millis(700), + started + hold + PROJECT_STOP_POLL_SLACK, &|| Ok(()), ) .err() @@ -401,11 +404,10 @@ fn a_requested_command_refuses_a_stop_past_its_bound_naming_it() { holder.join().unwrap(); } -/// HACK-2739, scaled 50 times (35 s is 700 ms): the requesting process of an -/// authored `hack exec` waits for a free lease before it sends anything to its -/// owner. It outlasts a project stop held for 600 ms, then returns, having -/// released the lease. It opens no engine connection, so unlike -/// `connect_command_request` it reaches no post-acquisition check. +/// HACK-2739: the requesting process of an authored `hack exec` waits for a +/// free lease before it sends anything to its owner. It outlasts a project stop +/// held for 600 ms, releases the lease and returns. The next holder can acquire +/// it immediately. #[test] fn the_authored_exec_request_waits_out_a_project_stop_and_releases_the_lease() { use crate::provider::lifecycle::await_free_command_lease; @@ -413,7 +415,7 @@ fn the_authored_exec_request_waits_out_a_project_stop_and_releases_the_lease() { let hold = Duration::from_millis(600); let (_release, holder) = hold_lease_as_project_stop(&candidate, hold); let started = Instant::now(); - await_free_command_lease(&candidate, started + Duration::from_millis(700)).unwrap(); + await_free_command_lease(&candidate, started + hold + PROJECT_STOP_POLL_SLACK).unwrap(); assert!( started.elapsed() >= hold - Duration::from_millis(50), "returned before the stop released: {:?}", @@ -433,13 +435,14 @@ fn the_authored_exec_request_refuses_a_stop_past_its_bound_naming_it() { let (_home, candidate) = running_pool(); let (release, holder) = hold_lease_as_project_stop(&candidate, Duration::from_secs(30)); let started = Instant::now(); - let refused = await_free_command_lease(&candidate, started + Duration::from_millis(300)) + let deadline = started + Duration::from_millis(300); + let refused = await_free_command_lease(&candidate, deadline) .err() .unwrap(); assert_eq!(refused.code, "provider_busy"); assert_eq!(refused.message, PROJECT_STOP_REFUSAL); assert!(refused.cause_code.is_none()); - assert!(started.elapsed() >= Duration::from_millis(250)); + assert!(Instant::now() >= deadline); assert!(started.elapsed() < Duration::from_secs(5)); release.send(()).unwrap(); holder.join().unwrap(); diff --git a/packages/runtime-core/src/provider/graph/foreground/dependency_refresh.rs b/packages/runtime-core/src/provider/graph/foreground/dependency_refresh.rs index fd0d28498..b285a5f23 100644 --- a/packages/runtime-core/src/provider/graph/foreground/dependency_refresh.rs +++ b/packages/runtime-core/src/provider/graph/foreground/dependency_refresh.rs @@ -410,8 +410,8 @@ mod automatic_tests { mod owner_lease_tests { use super::*; use crate::provider::engine::command_lease_tests::{ - PROJECT_STOP_REFUSAL, assert_waited_then_acquired, hold_lease, hold_lease_as_project_stop, - running_pool, + PROJECT_STOP_POLL_SLACK, PROJECT_STOP_REFUSAL, assert_waited_then_acquired, hold_lease, + hold_lease_as_project_stop, running_pool, }; use std::cell::Cell; @@ -458,9 +458,7 @@ mod owner_lease_tests { let hold = Duration::from_millis(600); let (_release, holder) = hold_lease_as_project_stop(&candidate, hold); let started = Instant::now(); - // The backoff caps at 50 ms and is not scaled with the hold. Allow ten - // poll intervals for the holder to run, unlock and be observed on CI. - let deadline = started + hold + Duration::from_millis(500); + let deadline = started + hold + PROJECT_STOP_POLL_SLACK; let after = requested_selection(&candidate, &run, deadline) .err() .unwrap(); diff --git a/tests/models/tla/native-command-lease/COVERAGE.md b/tests/models/tla/native-command-lease/COVERAGE.md index 65f445c0c..e0209f27a 100644 --- a/tests/models/tla/native-command-lease/COVERAGE.md +++ b/tests/models/tla/native-command-lease/COVERAGE.md @@ -129,9 +129,9 @@ Tests: - `provider/engine/command_lease_tests.rs`: the constants (35 s is the start's bound, the owner keeps 15 s, `command_lease_deadline` caps a far - deadline at each); scaled 50 times, a project stop held 600 ms is refused - at the owner bound with the exact project-stop message and waited out by - `connect_command_request`; a stop past the bound is refused with the raw, + deadline at each). The scaled 300 ms owner wait refuses a 600 ms stop + with the exact project-stop message. `connect_command_request` waits it out + with 500 ms of polling slack. A stop past the deadline yields the raw, uncaused `provider_busy`. - `dependency_refresh.rs` `owner_lease_tests`: the refresh's `requested_selection` waits out a 600 ms stop with 500 ms of slack for scheduling, unlock, and @@ -215,11 +215,12 @@ roles: `requester` is `phase = "refresh"`, `owner` is `phase = "exec"`. Tests: -- `provider/engine/command_lease_tests.rs`, scaled 50 times: the requester's - wait outlasts a project stop held 600 ms and releases the lease; a stop past - its bound is refused with the raw, uncaused `provider_busy` naming the stop; - 100 uncontended waits take well under a second, and on a home with no pool - the wait returns at once and creates no lock file; and the call site, +- `provider/engine/command_lease_tests.rs`: the requester waits out a 600 ms + stop with the same 500 ms of polling slack as the Compose refresh fixture + (HACK-2751), then releases the lease for the next holder. A stop still + holding the lease at the deadline gets the raw, uncaused `provider_busy` + naming the stop. 100 uncontended waits take well under a second, and on a + home with no pool the wait returns at once and creates no lock file. The call site, `native::foreground::exec`, waits out the stop before it contacts the owner (this test fails when the wait is removed). - `native/runtime/exec_tests.rs`: only `provider_busy` maps to From 3895a3650db2d039b815da2cd7a4f9738c781434 Mon Sep 17 00:00:00 2001 From: Dimitri Kennedy <344842+roodboi@users.noreply.github.com> Date: Thu, 26 Nov 2026 20:49:21 -0500 Subject: [PATCH 3/3] test(runtime-core): release the project stop on the requester retry --- .../provider/engine/command_lease_tests.rs | 43 +++++++++++-------- .../tla/native-command-lease/COVERAGE.md | 20 ++++----- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/packages/runtime-core/src/provider/engine/command_lease_tests.rs b/packages/runtime-core/src/provider/engine/command_lease_tests.rs index 91a0b3e66..d8ca31b55 100644 --- a/packages/runtime-core/src/provider/engine/command_lease_tests.rs +++ b/packages/runtime-core/src/provider/engine/command_lease_tests.rs @@ -10,6 +10,7 @@ use super::*; use crate::provider::lifecycle::COMMAND_LEASE_WAIT; use crate::provider::{Profile, state}; +use std::cell::Cell; use std::fs; use std::os::unix::fs::DirBuilderExt; use std::path::PathBuf; @@ -348,36 +349,42 @@ fn the_requesting_side_of_exec_waits_as_long_as_a_start_and_the_owner_side_keeps assert_eq!(command_lease_deadline(now, near, COMMAND_LEASE_WAIT), near); } -/// HACK-2729, scaled (the owner's 15 s is 300 ms): a project stop holds the lease -/// for 600 ms. At the owner-side bound the wait refuses with the exact -/// project-stop refusal the CLI reads; the requesting side's longer bound -/// outlasts the stop and acquires right after it, before any check of its own. +/// HACK-2729: the owner deadline expires while the project stop still holds +/// the lease. The requester retries and acquires after the stop releases it. #[test] fn a_requested_command_waits_out_a_project_stop_that_the_owner_bound_refuses() { let (_home, candidate) = running_pool(); - let hold = Duration::from_millis(600); - let (_release, holder) = hold_lease_as_project_stop(&candidate, hold); + let root = candidate.state_root.join("run/smolvm"); + let held_stop = Cell::new(Some({ + let _stop = state::RecordProjectStop::begin(); + state::Lock::acquire(&root).unwrap() + })); - let started = Instant::now(); - let refused = - Engine::connect_command(&candidate, started + Duration::from_millis(300), &|| Ok(())) - .err() - .unwrap(); + let owner_deadline = Instant::now() + Duration::from_millis(300); + let refused = Engine::connect_command(&candidate, owner_deadline, &|| Ok(())) + .err() + .unwrap(); + assert!(Instant::now() >= owner_deadline); assert_eq!(refused.code, "provider_busy"); assert_eq!(refused.message, PROJECT_STOP_REFUSAL); - assert!(started.elapsed() < hold); - // The backoff caps at 50 ms and is not scaled with the hold. Allow ten poll - // intervals for the holder to run, unlock and be observed on CI (HACK-2741). + // The guard runs before each attempt. Keep the stop through the first + // attempt and release it on retry, regardless of how long CI was paused. + let first_attempt = Cell::new(true); let after = Engine::connect_command_request( &candidate, - started + hold + Duration::from_millis(500), - &|| Ok(()), + Instant::now() + Duration::from_secs(5), + &|| { + if !first_attempt.replace(false) { + drop(held_stop.take()); + } + Ok(()) + }, ) .err() .unwrap(); - assert_waited_then_acquired(started, hold, &after); - holder.join().unwrap(); + assert_eq!(after.code, PAST_ACQUISITION, "{}", after.message); + assert!(held_stop.into_inner().is_none()); } /// HACK-2729: a stop that outlasts the requesting side's bound is still refused diff --git a/tests/models/tla/native-command-lease/COVERAGE.md b/tests/models/tla/native-command-lease/COVERAGE.md index e0209f27a..761b44c65 100644 --- a/tests/models/tla/native-command-lease/COVERAGE.md +++ b/tests/models/tla/native-command-lease/COVERAGE.md @@ -129,9 +129,10 @@ Tests: - `provider/engine/command_lease_tests.rs`: the constants (35 s is the start's bound, the owner keeps 15 s, `command_lease_deadline` caps a far - deadline at each). The scaled 300 ms owner wait refuses a 600 ms stop - with the exact project-stop message. `connect_command_request` waits it out - with 500 ms of polling slack. A stop past the deadline yields the raw, + deadline at each). The scaled 300 ms owner wait refuses a stop that still + holds the lease and returns the exact project-stop message. The test releases + the stop on the requester's first retry and verifies acquisition. A stop + past the requester's deadline yields the raw, uncaused `provider_busy`. - `dependency_refresh.rs` `owner_lease_tests`: the refresh's `requested_selection` waits out a 600 ms stop with 500 ms of slack for scheduling, unlock, and @@ -216,13 +217,12 @@ roles: `requester` is `phase = "refresh"`, `owner` is `phase = "exec"`. Tests: - `provider/engine/command_lease_tests.rs`: the requester waits out a 600 ms - stop with the same 500 ms of polling slack as the Compose refresh fixture - (HACK-2751), then releases the lease for the next holder. A stop still - holding the lease at the deadline gets the raw, uncaused `provider_busy` - naming the stop. 100 uncontended waits take well under a second, and on a - home with no pool the wait returns at once and creates no lock file. The call site, - `native::foreground::exec`, waits out the stop before it contacts the owner - (this test fails when the wait is removed). + stop with 500 ms of polling slack (#1286, HACK-2751), then releases the + lease for the next holder. A stop still holding the lease at the deadline + gets the raw, uncaused `provider_busy` naming the stop. 100 uncontended waits + take well under a second, and on a home with no pool the wait returns at once + and creates no lock file. The call site, `native::foreground::exec`, waits out + the stop before it contacts the owner (this test fails when the wait is removed). - `native/runtime/exec_tests.rs`: only `provider_busy` maps to `graph_authored_exec_lease_busy`, which passes the reply-code filter, and the owner's wait on a real held flock ends in that code.