Skip to content

refactor(compose): move the dependency graph to internal/depgraph - #14410

Merged
glours merged 1 commit into
docker:mainfrom
ndeloof:internal-depgraph
Nov 5, 2026
Merged

glours merged 1 commit into
docker:mainfrom
ndeloof:internal-depgraph

Conversation

@ndeloof

@ndeloof ndeloof commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does, in one sentence

Moves the service dependency graph and its ordered traversal (dependencies.go) out of pkg/compose into a standalone internal/depgraph package.

Context

Graph, Vertex, InDependencyOrder, InReverseDependencyOrder and friends only depend on the compose-go project model and on pkg/api errors, yet they live inside the pkg/compose monolith next to the engine code, which makes them look entangled with it. The only thing they borrowed from the rest of the package was the small bounded-errgroup helper, which now lives in internal/concurrency (#14422).

What the PR brings

  • A self-contained internal/depgraph package (no Backend, no engine dependency) that reconcile, down, stop, restart and the classic build reference qualified (depgraph.InDependencyOrder, …). Behaviour is unchanged; the tests moved with the code, with identical assertions.
  • The one coupling is already resolved by internal/concurrency: the traversal calls concurrency.NewErrgroup, so no copy of the helper is needed. The "limit + 1" passed to it (one slot is held by the goroutine reading the node channel) is kept as is and now documented in a comment.
  • The traversal options are now an exported depgraph.Option type, and the classic build, which used to set the unexported maxConcurrency field from a closure, uses a new depgraph.WithMaxConcurrency(n) option instead.
  • Exported symbols removed from pkg/compose (and therefore from the /v5 API surface; none is used anywhere else in this repository): ServiceStatus, ServiceStopped, ServiceStarted, Graph, Vertex, NewGraph, NewVertex, InDependencyOrder, InReverseDependencyOrder, WithRootNodesAndDown, and the methods of Graph and Vertex (AddVertex, AddEdge, Leaves, Roots, UpdateStatus, FilterChildren, FilterParents, HasCycles, GetParents, GetChildren).
  • reconcile.go is touched only for identifier qualification, to keep conflicts with the open reconcile PRs minimal.

Why this is the right next brick

Part of the #14396 series. It is a pure leaf of the dependency tree (nothing flows back from internal/depgraph into pkg/compose) and is independent of the other extractions, so it can land in any order.

Part of #14396

🤖 Generated with Claude Code

@ndeloof
ndeloof requested review from a team as code owners October 28, 2026 07:14

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

This is a clean package-extraction refactoring. The graph traversal logic, concurrency model, and semantics are faithfully preserved in internal/depgraph. All callers updated correctly.

Lower-confidence findings (not posted inline)

  • [low] internal/depgraph/depgraph.go:162 — limitedErrgroup +1 convention undocumented (confidence: unverified low, not scored)
    The visit() function passes t.maxConcurrency + 1 to limitedErrgroup, which forwards it straight to SetLimit. The +1 accounts for the coordinator goroutine. This split convention is not documented; a future direct caller of limitedErrgroup(ctx, 1) would unintentionally starve all workers. Consider adding a comment to limitedErrgroup noting the caller must include the coordinator slot in the argument.
  • [low] internal/depgraph/depgraph.go:119 — WithRootNodesAndDown doc comment ambiguous phrasing (confidence: unverified low, not scored)
    The comment says "services depending on them" which can be read two ways. The implementation correctly returns transitive dependents (services that depend ON the roots). Clarifying to "services that depend on them (their transitive dependents)" would remove the ambiguity.

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>

@glours glours left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@glours
glours merged commit d2582e9 into docker:main Nov 5, 2026
61 checks passed
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.

3 participants