Repository navigation
feat: rework cycle detection with edge-captured routing - #5916
Merged
baszalmstra merged 2 commits intoApr 17, 2026
Merged
Conversation
…e_guard Replaces the per-task chain-based cycle detector with an engine-wide active-edge multigraph. Each in-flight ctx.compute(&dep) installs an edge that captures the notify target visible from the caller's branch-local guard stack at edge creation time. Cycle detection BFSes forward from target; on close, every edge-captured target on the ring is notified. A user ComputeCtx::with_cycle_guard scope catches cycles whose detected path contains its own key; unhandled cycles flow up via each task's synthetic fallback and surface at ComputeEngine::compute as Err(ComputeError::Cycle(path)) carrying the full ring. No more panic on unguarded cycles. Parallel combinators (compute2/compute_join/...) give each sub-ctx a fresh branch-local guard stack chained to the parent's, so user scopes opened inside one branch cannot leak into siblings. The ActiveEdges graph is a multigraph so parallel branches awaiting the same dep each keep an independent record. Docs: new internal walkthrough in cycle/mod.rs with ASCII diagrams, crate-level # Cycles section in lib.rs, and runnable doctests on every ComputeCtx public method.
baszalmstra
commented
Apr 17, 2026
| //! This makes `ctx.compute(..)` safe to embed inside cancellable | ||
| //! `tokio::select!` branches without starving other subscribers. | ||
| //! | ||
| //! # Cycles |
Contributor
Author
There was a problem hiding this comment.
Explanation of how this is supposed to work from a user perspective.
hunger
approved these changes
Apr 17, 2026
hunger
left a comment
Contributor
There was a problem hiding this comment.
We need to get this into use to shake out the bugs. I could not spot an obvious problems and the described approach should in theory work.
baszalmstra
merged commit Apr 17, 2026
ef5e7af
into
prefix-dev:feature/lockfile-v7
38 of 39 checks passed
baszalmstra
added a commit
that referenced
this pull request
May 1, 2026
baszalmstra
added a commit
that referenced
this pull request
May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The compute engine previously panicked whenever it detected a dependency cycle that wasn't anticipated by the task chain. That made cycles a correctness-critical concern for every caller instead of a recoverable condition, and it made it impossible for higher-level resolvers (which legitimately want to react to cycles, e.g. to emit a good error or pick an alternate path) to handle them without aborting the whole engine.
This PR turns cycles into a first-class, recoverable outcome:
Err(ComputeError::Cycle(path))atComputeEngine::compute, carrying the full ring so callers can produce actionable error messages.ComputeCtx::with_cycle_guard. Only cycles whose path actually passes through that scope's key are caught; unrelated cycles keep propagating, so a guard can't accidentally swallow a cycle it has no business handling.compute2,compute_join, ...) now behave predictably when cycles cross branches. Previously the chain-based detector couldn't distinguish sibling branches, which meant cycle notifications could be misrouted or a guard in one branch could influence another. Guards are now branch-local.The Demand API commit exists to support this: the new detector needs to carry small pieces of metadata on keys without leaking generic parameters through the engine's type-erased core, and Demand is the minimal surface for that.
Net effect for callers:
Example
How Has This Been Tested?
pixi_compute_engineintegration tests.tests/integration/cycle.rscovering guarded and unguarded cycles, cycles across parallel branches, and the "only catch cycles that include my key" guard semantics.tests/integration/demand.rsfor the Demand API.ComputeCtxpublic method.AI Disclosure
Tools: Claude Code
Checklist: