diff --git a/CHANGELOG.md b/CHANGELOG.md index d9d39790c..0799719c6 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)). - **Changed** When automatic file-access tracking cannot record everything a task did, the "Not cached" summary line now includes the specific reason (for example, that the tracking channel ran out of capacity or that installing the seccomp filter failed for a given executable) ([#1054](https://github.com/voidzero-dev/vite-task/pull/1054), [#1056](https://github.com/voidzero-dev/vite-task/pull/1056)). - **Changed** Invalid remote cache endpoint URLs in `cache.remote.url` or `VP_REMOTE_CACHE_URL` (such as missing schemes, non-`http`/`https` schemes, or missing hosts) now fail upfront during configuration and planning instead of warning per task during execution, and `vp run --help` now documents `VP_REMOTE_CACHE`, `VP_REMOTE_CACHE_URL`, and `VP_REMOTE_CACHE_HEADER_` ([#1048](https://github.com/voidzero-dev/vite-task/pull/1048)). - **Changed** Removed `NEXT_*`, `VERCEL`, `VERCEL_*`, `USE_OUTPUT_FOR_EDGE_FUNCTIONS`, `NOW_BUILDER`, `VC_MICROFRONTENDS_CONFIG_FILE_NAME`, `GITHUB_*`, `ACTIONS_ID_TOKEN_REQUEST_URL`, `DOCKER_*`, `BUILDKIT_*`, `COMPOSE_*`, and `*_TOKEN` from the default untracked environment variables passed to cached tasks. Tasks that need any of these variables should declare them explicitly in `cache.env` or `cache.untrackedEnv` ([#1044](https://github.com/voidzero-dev/vite-task/pull/1044)). 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