Skip to content

fix: skip self-referential package dependency edges in workspace graph#230

Merged
branchseer merged 1 commit intomainfrom
fix/package-self-dependency-cycle
Mar 12, 2026
Merged

fix: skip self-referential package dependency edges in workspace graph#230
branchseer merged 1 commit intomainfrom
fix/package-self-dependency-cycle

Conversation

@branchseer
Copy link
Member

@branchseer branchseer commented Mar 12, 2026

What

When a package listed itself as a workspace dependency (e.g. "rolldown": "workspace:*" inside rolldown's own package.json), running any task in that package would fail with:

Cycle dependency detected: rolldown#build-binding:release -> rolldown#build-binding:release

Why

The workspace package graph is built by reading each package.json and adding a directed edge for every workspace dependency that resolves to another package in the monorepo. There was no guard against the case where a package names itself — the edge A → A was added unconditionally, producing a self-loop.

That self-loop is a cycle by definition, so the task planner's acyclicity check correctly rejected it — but the error was misleading because the "cycle" was entirely artificial and had nothing to do with the task definitions.

Fix

Skip any edge where the source and destination package are the same. A package depending on itself carries no ordering information, so dropping it is safe and matches how tools like pnpm handle this in practice.

Includes a new plan snapshot test with a fixture that reproduces the scenario.

A package that lists itself as a workspace dependency (e.g. rolldown
depending on rolldown for self-testing) caused a self-loop edge in the
package dependency graph. This loop propagated to the task execution
graph, triggering a false "cycle dependency detected" error when
planning any task in that package.

Fix by silently skipping self-loop edges when building the package
graph. Adds a plan snapshot test covering this scenario.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@branchseer branchseer marked this pull request as ready for review March 12, 2026 06:35
@branchseer branchseer merged commit 7e28617 into main Mar 12, 2026
7 checks passed
@branchseer branchseer deleted the fix/package-self-dependency-cycle branch March 12, 2026 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants