From 0163cdf0f198fdbedbfe3ef89365668ed6dea4f0 Mon Sep 17 00:00:00 2001 From: Viktor Ringnes Date: Thu, 26 Nov 2026 11:31:14 +0100 Subject: [PATCH 1/2] fix(run): don't fast fail on task exits after ctrl+c --- crates/vt/src/session/execute/scheduler.rs | 2 +- crates/vt_bin/src/vtt/exit_on_ctrlc.rs | 11 ++++-- crates/vt_bin/src/vtt/main.rs | 2 +- .../ctrl_c_parallel_cleanup/package.json | 4 +++ .../packages/a/package.json | 6 ++++ .../packages/b/package.json | 6 ++++ .../pnpm-workspace.yaml | 2 ++ .../ctrl_c_parallel_cleanup/snapshots.toml | 19 ++++++++++ ...rl_c_lets_parallel_tasks_finish_cleanup.md | 35 +++++++++++++++++++ .../ctrl_c_parallel_cleanup/vite-task.json | 1 + docs/cancellation.md | 1 + 11 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/package.json create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/packages/a/package.json create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/packages/b/package.json create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/pnpm-workspace.yaml create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/snapshots.toml create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/snapshots/ctrl_c_lets_parallel_tasks_finish_cleanup.md create mode 100644 crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/vite-task.json diff --git a/crates/vt/src/session/execute/scheduler.rs b/crates/vt/src/session/execute/scheduler.rs index 3d0dc524d..883a150b5 100644 --- a/crates/vt/src/session/execute/scheduler.rs +++ b/crates/vt/src/session/execute/scheduler.rs @@ -271,7 +271,7 @@ impl ExecutionContext<'_> { } }; tracing::debug!(failed, elapsed = ?start.elapsed(), "finished the task item"); - if failed { + if failed && !self.cancel_token.is_cancelled() { self.fast_fail_token.cancel(); } } diff --git a/crates/vt_bin/src/vtt/exit_on_ctrlc.rs b/crates/vt_bin/src/vtt/exit_on_ctrlc.rs index 81c3afdc2..29122a6b6 100644 --- a/crates/vt_bin/src/vtt/exit_on_ctrlc.rs +++ b/crates/vt_bin/src/vtt/exit_on_ctrlc.rs @@ -4,7 +4,10 @@ use std::sync::Arc; /// /// Sets up a Ctrl+C handler, emits a "ready" milestone, then waits. /// When Ctrl+C is received, prints "ctrl-c received" and exits. -pub fn run() -> Result<(), Box> { +pub fn run(args: &[String]) -> Result<(), Box> { + let cleanup_ms: u64 = args.first().map(|s| s.parse()).transpose()?.unwrap_or(0); + let exit_code: i32 = args.get(1).map(|s| s.parse()).transpose()?.unwrap_or(0); + // On Windows, an ancestor process (e.g. cargo, the test harness) may have // been created with CREATE_NEW_PROCESS_GROUP, which implicitly calls // SetConsoleCtrlHandler(NULL, TRUE) and sets CONSOLE_IGNORE_CTRL_C in the @@ -40,5 +43,9 @@ pub fn run() -> Result<(), Box> { ctrlc_once_lock.wait(); println!("ctrl-c received"); - Ok(()) + if cleanup_ms > 0 { + std::thread::sleep(std::time::Duration::from_millis(cleanup_ms)); + println!("cleanup done"); + } + std::process::exit(exit_code); } diff --git a/crates/vt_bin/src/vtt/main.rs b/crates/vt_bin/src/vtt/main.rs index 652835535..cecd3cf6b 100644 --- a/crates/vt_bin/src/vtt/main.rs +++ b/crates/vt_bin/src/vtt/main.rs @@ -54,7 +54,7 @@ fn main() { } "cp" => cp::run(&args[2..]), "exit" => exit::run(&args[2..]), - "exit-on-ctrlc" => exit_on_ctrlc::run(), + "exit-on-ctrlc" => exit_on_ctrlc::run(&args[2..]), "fs" => fs::run(&args[2..]), "grep-file" => { grep_file::run(&args[2..]); diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/package.json b/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/package.json new file mode 100644 index 000000000..350bb81c1 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/package.json @@ -0,0 +1,4 @@ +{ + "name": "ctrl-c-parallel-cleanup-test", + "private": true +} diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/packages/a/package.json b/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/packages/a/package.json new file mode 100644 index 000000000..540534d65 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/packages/a/package.json @@ -0,0 +1,6 @@ +{ + "name": "@ctrl-c-parallel-cleanup/a", + "scripts": { + "dev": "vtt exit-on-ctrlc 0 130" + } +} diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/packages/b/package.json b/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/packages/b/package.json new file mode 100644 index 000000000..73847a34a --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/packages/b/package.json @@ -0,0 +1,6 @@ +{ + "name": "@ctrl-c-parallel-cleanup/b", + "scripts": { + "dev": "vtt exit-on-ctrlc 1000" + } +} diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/pnpm-workspace.yaml b/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/pnpm-workspace.yaml new file mode 100644 index 000000000..924b55f42 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - packages/* diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/snapshots.toml b/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/snapshots.toml new file mode 100644 index 000000000..d819b075e --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/snapshots.toml @@ -0,0 +1,19 @@ +[[e2e]] +name = "ctrl_c_lets_parallel_tasks_finish_cleanup" +comment = """ +Ctrl+C with two parallel tasks: a exits 130 immediately, b takes a second to clean up. b shouldn't get killed when a exits. +""" +steps = [ + { argv = [ + "vt", + "run", + "-r", + "--parallel", + "--no-cache", + "dev", + ], interactions = [ + { "expect-milestone" = "ready" }, + { "expect-milestone" = "ready" }, + { "write-key" = "ctrl-c" }, + ] }, +] diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/snapshots/ctrl_c_lets_parallel_tasks_finish_cleanup.md b/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/snapshots/ctrl_c_lets_parallel_tasks_finish_cleanup.md new file mode 100644 index 000000000..8a40a25e5 --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/snapshots/ctrl_c_lets_parallel_tasks_finish_cleanup.md @@ -0,0 +1,35 @@ +# ctrl_c_lets_parallel_tasks_finish_cleanup + +Ctrl+C with two parallel tasks: a exits 130 immediately, b takes a second to clean up. b shouldn't get killed when a exits. + +## `vt run -r --parallel --no-cache dev` + +**Exit code:** 130 + +**→ expect-milestone:** `ready` + +``` +~/packages/a$ vtt exit-on-ctrlc 0 130 ⊘ cache disabled +~/packages/b$ vtt exit-on-ctrlc 1000 ⊘ cache disabled +``` + +**→ expect-milestone:** `ready` + +``` +~/packages/a$ vtt exit-on-ctrlc 0 130 ⊘ cache disabled +~/packages/b$ vtt exit-on-ctrlc 1000 ⊘ cache disabled +``` + +**← write-key:** `ctrl-c` + +``` +~/packages/a$ vtt exit-on-ctrlc 0 130 ⊘ cache disabled +~/packages/b$ vtt exit-on-ctrlc 1000 ⊘ cache disabled +ctrl-c received +ctrl-c received + +cleanup done + +--- +vt run: 1/2 successful. (Run `vt run --last-details` for full details) +``` diff --git a/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/vite-task.json b/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/vite-task.json new file mode 100644 index 000000000..d0fd62ced --- /dev/null +++ b/crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c_parallel_cleanup/vite-task.json @@ -0,0 +1 @@ +{ "cache": true } diff --git a/docs/cancellation.md b/docs/cancellation.md index ca2ec3dc3..af6e8e036 100644 --- a/docs/cancellation.md +++ b/docs/cancellation.md @@ -9,6 +9,7 @@ When the user presses Ctrl-C: 1. The OS delivers SIGINT (Unix) or CTRL_C_EVENT (Windows) directly to all processes in the terminal's foreground process group — both the runner and child tasks. This is standard OS behavior, not something `vp run` implements. 2. No new tasks are scheduled after the signal. 3. Results of in-flight tasks are **not cached**, even if a task handles the signal gracefully and exits 0. The output may be incomplete, so caching it would risk false cache hits on subsequent runs. +4. Tasks that exit non zero after Ctrl+C don't trigger [fast-fail](#fast-fail), so other tasks can finish shutting down. ## Fast-fail From d9a8784e0a11a15f31a298742e7c267b3467e0aa Mon Sep 17 00:00:00 2001 From: Viktor Ringnes Date: Thu, 26 Nov 2026 11:36:23 +0100 Subject: [PATCH 2/2] docs(changelog): add entry for ctrl+c fast fail fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad334a2d7..f0db78635 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Changelog +- **Fixed** After Ctrl+C, a task exiting with a non-zero code (like 130) no longer makes `vp run` kill the other tasks while they're still shutting down ([#1024](https://github.com/voidzero-dev/vite-task/pull/1024)). - **Fixed** Remote cache operations now cap concurrent uploads to 4 per endpoint, use pooled HTTP/1.1 connections instead of multiplexing all reads and uploads over one HTTP/2 connection, retry transient `5xx`/`429`/`408` and network failures with jittered backoff, and back off briefly during sustained endpoint outages, preventing `503` upload bursts and Windows connection-reset drops ([#1016](https://github.com/voidzero-dev/vite-task/pull/1016)). - **Fixed** Tasks that list `node_modules`, the workspace root, or `node_modules/.vite` no longer miss the cache when pnpm's `node_modules/.pnpm-workspace-state-*.json`, Vite's `node_modules/.vite-temp`, the workspace root's `.git`, or the task cache directory appear or disappear. Direct accesses to `node_modules/.vite-temp` and `.DS_Store` are now skipped as well, so they are neither tracked as inputs nor archived as outputs ([#1014](https://github.com/voidzero-dev/vite-task/pull/1014)). - **Fixed** When a command handler sets a working directory for a command it generates, `vp run` now runs that command in the selected directory and includes the directory in its cache fingerprint ([#1005](https://github.com/voidzero-dev/vite-task/pull/1005)).