Skip to content

Commit 6622ea5

Browse files
branchseerclaude
andcommitted
fix(execute): use StableGraph to preserve node indices during removal
DiGraph uses swap-remove which invalidates indices when nodes are removed during iteration. StableGraph preserves indices, fixing panic when executing task graphs with 3+ nodes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1439516 commit 6622ea5

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

  • crates/vite_task/src/session/execute

crates/vite_task/src/session/execute/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub mod spawn;
44
use std::sync::Arc;
55

66
use futures_util::FutureExt;
7-
use petgraph::{algo::toposort, graph::DiGraph};
7+
use petgraph::{algo::toposort, stable_graph::StableGraph};
88
use vite_path::AbsolutePath;
99
use vite_task_plan::{
1010
ExecutionItemKind, ExecutionPlan, LeafExecutionKind, SpawnExecution, TaskExecution,
@@ -46,9 +46,9 @@ impl ExecutionContext<'_> {
4646
) -> Result<(), ExecutionAborted> {
4747
match item_kind {
4848
ExecutionItemKind::Expanded(graph) => {
49-
// clone for reversing edges and removing nodes
50-
let mut graph: DiGraph<&TaskExecution, (), ExecutionIx> =
51-
graph.map(|_, task_execution| task_execution, |_, ()| ());
49+
// Use StableGraph to preserve node indices during removal
50+
let mut graph: StableGraph<&TaskExecution, (), _, ExecutionIx> =
51+
graph.map(|_, task_execution| task_execution, |_, ()| ()).into();
5252

5353
// To be consistent with the package graph in vite_package_manager and the dependency graph definition in Wikipedia
5454
// https://en.wikipedia.org/wiki/Dependency_graph, we construct the graph with edges from dependents to dependencies

0 commit comments

Comments
 (0)