Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

- **Added** `vp run --continue` (also accepted as `--no-bail`) keeps running tasks after a task fails, instead of killing the running tasks and starting no new ones. Tasks that succeed are cached. Tasks that depend on a failed task don't run, and the run still exits with a non-zero status once the other tasks finish. `--continue` also applies to `vp run` commands in the scripts of the tasks it runs, and a `vp run --continue` in a task's script applies to the tasks that it runs. `continue: true` in the `run` block of the workspace root's `vite.config.*` turns it on for every `vp run` in the workspace ([#898](https://github.com/voidzero-dev/vite-task/pull/898)).
- **Fixed** On Windows, tasks with automatic file-access tracking can now run Git Bash's `sh` and other MSYS2 or Cygwin programs, which aborted with `fatal error - MapViewOfFileEx 'shared.5'(…) Win32 error 487` ([#830](https://github.com/voidzero-dev/vite-task/issues/830), [#952](https://github.com/voidzero-dev/vite-task/pull/952)).
- **Fixed** On Linux, cached tasks no longer fail to spawn child processes in restricted sandboxes, for example rootless bubblewrap that denies the `seccomp` syscall. When the `seccomp` filter for file-access tracking cannot be installed, the process runs untracked instead and the run is reported as not cached. The not-cached message now reads "automatic file tracking couldn't record everything this task did", which fits both this case and a full tracking channel ([#700](https://github.com/voidzero-dev/vite-task/issues/700), [#701](https://github.com/voidzero-dev/vite-task/pull/701)).
- **Fixed** `vp run <task>` in a package that doesn't define the task now reports `Task "<task>" not found` when another package's `vite.config.*` fails to load, instead of failing with that package's error. Showing the tasks to choose from loads every package's config, so the task selector or task list is skipped then ([#987](https://github.com/voidzero-dev/vite-task/pull/987)).
Expand Down
11 changes: 11 additions & 0 deletions crates/vt/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ pub struct RunFlags {
#[clap(default_value = "false", long)]
pub ignore_depends_on: bool,

/// Keep running other tasks after a task fails.
///
/// Tasks that depend on a failed task don't run, and the run still exits
/// with a non-zero code. `continue: true` in the workspace root config
/// turns it on for every run.
// `--no-bail` is pnpm's name for the same behavior.
#[clap(default_value = "false", long = "continue", alias = "no-bail")]
pub continue_on_failure: bool,

/// Show full detailed summary after execution. A cache miss checks every
/// input, so the summary lists every change. Twice (`-vv`), it also lists
/// everything each cached run depends on, and its outputs.
Expand Down Expand Up @@ -357,6 +366,7 @@ impl ResolvedRunCommand {
let include_explicit_deps = !self.flags.ignore_depends_on;
let concurrency_limit = self.flags.concurrency_limit.map(|n| n.max(1));
let parallel = self.flags.parallel;
let continue_on_failure = self.flags.continue_on_failure;
// Read before `into_package_query` consumes the args.
let fail_if_no_match = self.flags.package_query.fail_if_no_match;

Expand All @@ -376,6 +386,7 @@ impl ResolvedRunCommand {
remote_cache_mode: self.flags.remote_cache.map(Into::into),
concurrency_limit,
parallel,
continue_on_failure,
fail_if_no_match,
},
},
Expand Down
6 changes: 4 additions & 2 deletions crates/vt/src/session/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,10 @@ impl Report {
///
/// `file_check` says how many changed files a cache miss lists.
///
/// Cancelling `fast_fail_token` kills the process. `cancel_token` must be a
/// child of `fast_fail_token` that Ctrl-C also cancels: cancelling it stops
/// Cancelling `fast_fail_token` kills the process. This function cancels it
/// too when forwarding the process's output fails, so it must belong to this
/// spawn alone (a child of the run's fast-fail token). `cancel_token` must be
/// cancelled when the run fast-fails and on Ctrl-C: cancelling it stops
/// remote cache lookups and prevents caching. A cached run's upload to the
/// remote cache runs in the background, and the caller waits for it with
/// [`ExecutionCache::wait_for_uploads`].
Expand Down
109 changes: 74 additions & 35 deletions crates/vt/src/session/execute/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ struct ExecutionContext<'a> {
run_kind: RunKind,
/// How many changed files a cache miss lists.
file_check: FileCheck,
/// Token cancelled when a task fails. Kills in-flight child processes
/// (via `start_kill` in spawn.rs).
/// Token cancelled when a task fails in a graph without `--continue`.
/// Kills in-flight child processes (via `start_kill` in spawn.rs).
///
/// One token serves every nested graph, and graphs with `--continue`
/// obey it too. That matches cancelling each graph on its own because a
/// nested `--continue` can't be turned off: a graph without it has no
/// ancestor with it, so its failure would cancel every graph up to the
/// root anyway.
fast_fail_token: CancellationToken,
/// Token cancelled by Ctrl-C, and by fast-fail as a child of
/// `fast_fail_token`. Prevents scheduling new tasks and caching results,
Expand All @@ -89,21 +95,27 @@ impl ExecutionContext<'_> {
/// `concurrency_limit` permits. Each recursive `Expanded` graph creates its own
/// semaphore, so nested graphs have independent concurrency limits.
///
/// Fast-fail: if any task fails, `execute_leaf` cancels the `fast_fail_token`
/// (killing in-flight child processes). Ctrl-C cancels the `cancel_token`.
/// Fast-fail: if a node fails, this cancels the `fast_fail_token` (killing
/// in-flight child processes). Ctrl-C cancels the `cancel_token`.
/// Either cancellation causes this method to close the semaphore, drain
/// remaining futures, and return.
///
/// `path` is where `graph` is: empty for the root graph, and the path of
/// the item it expands for a nested one.
///
/// If the graph has `continue_on_failure` (`--continue`), a failure cancels
/// nothing. A failed node doesn't release its dependents, so they never
/// start, and every other node still runs.
///
/// Returns whether any node in the graph failed.
#[tracing::instrument(
level = "debug",
skip_all,
fields(tasks = graph.graph.node_count(), concurrency_limit = graph.concurrency_limit)
)]
async fn execute_expanded_graph(&self, graph: &ExecutionGraph, path: &LeafPath) {
async fn execute_expanded_graph(&self, graph: &ExecutionGraph, path: &LeafPath) -> bool {
if graph.graph.node_count() == 0 {
return;
return false;
}

let semaphore =
Expand All @@ -126,13 +138,28 @@ impl ExecutionContext<'_> {
}

// Process completions and schedule newly ready dependents.
// On failure, `execute_leaf` cancels the token — we detect it here, close
// the semaphore (so pending acquires fail immediately), and drain.
while let Some(completed_ix) = futures.next().await {
// On failure without `--continue`, cancel the token here rather than in
// `execute_leaf`, so a nested `--continue` graph that failed also stops
// this one. Then close the semaphore (so pending acquires fail
// immediately) and drain.
let mut any_failed = false;
while let Some((completed_ix, failed)) = futures.next().await {
any_failed |= failed;
if failed && !graph.continue_on_failure {
self.fast_fail_token.cancel();
}
if self.cancelled() {
semaphore.close();
while futures.next().await.is_some() {}
return;
while let Some((_, failed)) = futures.next().await {
any_failed |= failed;
}
return any_failed;
}

// A failed node doesn't release its dependents, so their counts
// never reach zero.
if failed {
continue;
}

// Find dependents of the completed node (nodes that depend on it).
Expand All @@ -146,75 +173,86 @@ impl ExecutionContext<'_> {
}
}
}
any_failed
}

/// Create a future that acquires a semaphore permit, then executes a graph node.
///
/// On failure, `execute_node` cancels the `fast_fail_token` — the caller
/// detects this after the future completes. On semaphore closure or prior
/// cancellation, the node is skipped.
/// The future resolves to the node and whether it failed; the caller then
/// decides whether the failure cancels the run. On semaphore closure or
/// prior cancellation, the node is skipped and doesn't count as failed.
fn spawn_node<'a>(
&'a self,
graph: &'a ExecutionGraph,
path: &'a LeafPath,
node_ix: ExecutionNodeIndex,
semaphore: &Arc<Semaphore>,
) -> LocalBoxFuture<'a, ExecutionNodeIndex> {
) -> LocalBoxFuture<'a, (ExecutionNodeIndex, bool)> {
let sem = semaphore.clone();
async move {
let start = Instant::now();
if let Ok(_permit) = sem.acquire_owned().await
let failed = if let Ok(_permit) = sem.acquire_owned().await
&& !self.cancelled()
{
tracing::debug!(
task = %graph.graph[node_ix].task_display,
waited = ?start.elapsed(),
"acquired a concurrency permit"
);
self.execute_node(graph, path, node_ix).await;
}
node_ix
self.execute_node(graph, path, node_ix).await
} else {
false
};
(node_ix, failed)
}
.boxed_local()
}

/// Execute a single node's items sequentially.
/// Execute a single node's items sequentially, returning whether one failed.
///
/// A node may have multiple items (from `&&`-split commands). Items are executed
/// in order; if any item fails, `execute_leaf` cancels the `fast_fail_token`
/// and remaining items are skipped (preserving `&&` semantics).
/// in order; if any item fails, remaining items are skipped (preserving `&&`
/// semantics). An `Expanded` item fails if any node in its nested graph fails.
async fn execute_node(
&self,
graph: &ExecutionGraph,
path: &LeafPath,
node_ix: ExecutionNodeIndex,
) {
) -> bool {
let task_execution = &graph.graph[node_ix];

for (item_index, item) in task_execution.items.iter().enumerate() {
if self.cancelled() {
return;
return false;
}
let item_path: Vec<_> = path.iter().copied().chain([(node_ix, item_index)]).collect();
match &item.kind {
let failed = match &item.kind {
ExecutionItemKind::Leaf(leaf_kind) => {
self.execute_leaf(&item_path, &item.execution_item_display, leaf_kind)
.boxed_local()
.await;
.await
}
ExecutionItemKind::Expanded(nested_graph) => {
self.execute_expanded_graph(nested_graph, &item_path).boxed_local().await;
self.execute_expanded_graph(nested_graph, &item_path).boxed_local().await
}
};
if failed {
return true;
}
}
false
}

/// Execute a single leaf item (in-process command or spawned process).
///
/// Creates a [`LeafExecutionReporter`](crate::session::reporter::LeafExecutionReporter)
/// from the graph reporter and delegates to the appropriate execution
/// method. On failure (non-zero exit or infrastructure error), cancels the
/// `fast_fail_token`.
/// method. Returns whether the leaf failed (non-zero exit or infrastructure
/// error); the graph decides whether that cancels the run.
///
/// A spawn gets a child of the `fast_fail_token`: fast-fail still kills
/// it, and when the spawn cancels the token to kill its own process (after
/// failing to forward its output), other tasks keep running.
#[tracing::instrument(
level = "debug",
skip_all,
Expand All @@ -225,7 +263,7 @@ impl ExecutionContext<'_> {
path: &LeafPath,
item_display: &ExecutionItemDisplay,
leaf_kind: &LeafExecutionKind,
) {
) -> bool {
let start = Instant::now();
// Borrow the reporter briefly to create the leaf reporter, then drop
// the RefCell guard before any `.await` point.
Expand Down Expand Up @@ -263,7 +301,7 @@ impl ExecutionContext<'_> {
self.program_name,
self.run_kind,
self.file_check,
self.fast_fail_token.clone(),
self.fast_fail_token.child_token(),
self.cancel_token.clone(),
)
.await;
Expand All @@ -277,9 +315,7 @@ impl ExecutionContext<'_> {
}
};
tracing::debug!(failed, elapsed = ?start.elapsed(), "finished the task item");
if failed {
self.fast_fail_token.cancel();
}
failed
}
}

Expand Down Expand Up @@ -343,7 +379,10 @@ impl Session<'_> {
};

// Execute the graph with fast-fail: if any task fails, remaining tasks
// are skipped. Leaf-level errors are reported through the reporter.
// are skipped. In graphs with `--continue`, only the failed tasks'
// dependents are. Leaf-level errors are reported through the reporter,
// which also decides the exit status, so whether a task failed isn't
// needed here.
execution_context.execute_expanded_graph(&execution_graph, &[]).await;

// Nested graphs share the cache, so this waits for their uploads too.
Expand Down
1 change: 1 addition & 0 deletions crates/vt/src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ impl<'a> Session<'a> {
remote_cache_mode: run_command.flags.remote_cache.map(Into::into),
concurrency_limit: None,
parallel: false,
continue_on_failure: run_command.flags.continue_on_failure,
// The selector path runs whatever the user picked interactively;
// there is no `--filter` in play, so strict-mode does not apply.
fail_if_no_match: false,
Expand Down
2 changes: 1 addition & 1 deletion crates/vt/src/session/reporter/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ mod tests {
fn a_failed_lookup_prints_no_plan() {
let mut graph = petgraph::graph::DiGraph::default();
let node = graph.add_node(spawn_task("build"));
let graph = ExecutionGraph::try_from_graph(graph, 1).unwrap();
let graph = ExecutionGraph::try_from_graph(graph, 1, false).unwrap();
let builder = JsonReporterBuilder::new(
&graph,
&test_path(),
Expand Down
18 changes: 18 additions & 0 deletions crates/vt_bin/src/vtt/broken_stdout.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// broken-stdout -- `<command>` \[`<args>`...\]
///
/// Spawns `<command>` with its stdout connected to a pipe whose read end is
/// already closed, so every write to it fails (`EPIPE` on Unix,
/// `ERROR_NO_DATA` on Windows), then exits with the child's exit code.
pub fn run(args: &[String]) -> Result<(), Box<dyn std::error::Error>> {
let Some(("--", cmd_args)) = args.split_first().map(|(sep, rest)| (sep.as_str(), rest)) else {
return Err("Usage: vtt broken-stdout -- <command> [args...]".into());
};
let Some((program, program_args)) = cmd_args.split_first() else {
return Err("Usage: vtt broken-stdout -- <command> [args...]".into());
};

let (reader, writer) = std::io::pipe()?;
drop(reader);
let status = std::process::Command::new(program).args(program_args).stdout(writer).status()?;
std::process::exit(status.code().unwrap_or(1));
}
4 changes: 3 additions & 1 deletion crates/vt_bin/src/vtt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#![expect(clippy::print_stdout, reason = "CLI tool output")]

mod barrier;
mod broken_stdout;
mod check_tty;
mod cp;
mod exit;
Expand Down Expand Up @@ -41,13 +42,14 @@ fn main() {
if args.len() < 2 {
eprintln!("Usage: vtt <subcommand> [args...]");
eprintln!(
"Subcommands: barrier, check-tty, cp, exit, exit-on-ctrlc, fs, grep-file, hold-reads, list-dir, mkdir, pipe-stdin, pipe-stdout, print, print-color, print-cwd, print-env, print-file, read-link, read-stdin, replace-file-content, rm, small_dev_shm, stalled-remote-cache, stat-file, stat-many, symlink, touch-file, write-file"
"Subcommands: barrier, broken-stdout, check-tty, cp, exit, exit-on-ctrlc, fs, grep-file, hold-reads, list-dir, mkdir, pipe-stdin, pipe-stdout, print, print-color, print-cwd, print-env, print-file, read-link, read-stdin, replace-file-content, rm, small_dev_shm, stalled-remote-cache, stat-file, stat-many, symlink, touch-file, write-file"
);
std::process::exit(1);
}

let result: Result<(), Box<dyn std::error::Error>> = match args[1].as_str() {
"barrier" => barrier::run(&args[2..]),
"broken-stdout" => broken_stdout::run(&args[2..]),
"check-tty" => {
check_tty::run();
Ok(())
Expand Down
19 changes: 19 additions & 0 deletions crates/vt_bin/tests/e2e_snapshots/fixtures/ctrl_c/snapshots.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@ steps = [
] },
]

[[e2e]]
name = "ctrl_c_prevents_future_tasks_with___continue"
comment = """
`--continue` doesn't stop Ctrl+C from cancelling the run: a exits 0 after Ctrl+C, and with `--continue` no task's exit cancels anything, so only Ctrl+C keeps b, which depends on a, from starting.
"""
steps = [
{ argv = [
"vt",
"run",
"-r",
"--continue",
"--no-cache",
"dev",
], interactions = [
{ "expect-milestone" = "ready" },
{ "write-key" = "ctrl-c" },
] },
]

[[e2e]]
name = "ctrl_c_prevents_caching"
comment = """
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ctrl_c_prevents_future_tasks_with___continue

`--continue` doesn't stop Ctrl+C from cancelling the run: a exits 0 after Ctrl+C, and with `--continue` no task's exit cancels anything, so only Ctrl+C keeps b, which depends on a, from starting.

## `vt run -r --continue --no-cache dev`

**→ expect-milestone:** `ready`

```
~/packages/a$ vtt exit-on-ctrlc ⊘ cache disabled
```

**← write-key:** `ctrl-c`

```
~/packages/a$ vtt exit-on-ctrlc ⊘ cache disabled
ctrl-c received
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "pkg-c"
}
Loading