Repository navigation
refactor(project): share one xpkg client constructor; clamp build concurrency to 1 - #478
Conversation
Add project.NewXpkgClient and use it from project build, project run, render op and render xr instead of four inline copies. BuildWithMaxConcurrency now clamps 0 to 1. Before, 0 made an unbuffered semaphore and render xr and render op hung with --max-concurrency=0. The max() in project build and run is no longer needed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Jonathan Ogilvie <jonathan.ogilvie@sumologic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Jonathan Ogilvie <jonathan.ogilvie@sumologic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 57 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
adamwg
left a comment
There was a problem hiding this comment.
The fact that we need both a Client and a Resolver in so many places makes me wonder whether we should have an abstraction that does both. E.g., we could have a Client in internal/xpkg that extends the upstream xpkg.Client with Resolve (since the Resolver uses an xpkg.Client underneath anyway).
That said, this is an improvement as-is and we can consider further refactors later if you prefer.
Add an internal/xpkg Client interface that extends the upstream xpkg.Client with Resolve. NewClient and project.NewXpkgClient now return it, so callers carry one value instead of a client plus a Resolver. The dependency manager drops WithResolver and resolves through its client; ResolveConfigurationFunctions takes the Client. Resolution rules and error messages are unchanged. Suggested by adamwg in review of #478. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Jonathan Ogilvie <jonathan.ogilvie@sumologic.com>
Description of your changes
Summary
Adds
project.NewXpkgClientand uses it inproject build,project run,render op,render xr,dependency add,dependency update-cacheandcomposition generate. These commands used to build the xpkg client and resolver inline, or inrender xr's case through a private helper.BuildWithMaxConcurrencynow treats 0 as 1. Before this change,render xrandrender ophung with--max-concurrency=0whenever the project had embedded functions.Why
dependency.DefaultCacheDir(), the remote fetcher and optional ImageConfigs. Putting that in one place keeps them consistent.project buildandproject runclampedmax(1, MaxConcurrency)themselves, butrender xrandrender oppassed the flag through unchanged. With 0 the builder's semaphore channel is unbuffered, so every embedded function build blocks forever, which hangs whenever the project had embedded functions. Clamping inside the option fixes this for every caller.What changed
internal/project/xpkg.gowithNewXpkgClient(cacheDir, opts...), which returns the client and a resolver backed by it.project buildandproject runcall it with the project's ImageConfigs and drop their localmax(1, ...).render opcalls it with the project's ImageConfigs.render xrdropsnewClientAndResolverand calls the helper in its place: with the project's ImageConfigs for projects, and with none for Configurations, as before.dependency add,dependency update-cacheandcomposition generatecall it with the project's ImageConfigs, replacing their inline client and resolver construction.BuildWithMaxConcurrency(0)now means 1.Everything else stays the same: registries, ImageConfigs, cache dirs and credentials match main for every command. Error wrapping changes only in
project build,project run,dependency add,dependency update-cacheandcomposition generate: a client construction failure is now wrapped as "cannot create xpkg client", asrender opandrender xralready did.Testing
TestBuilderZeroConcurrencybuilds a project withBuildWithMaxConcurrency(0)and fails if the build doesn't finish within 30s. Without the clamp it times out; with the clamp it passes in about 1s../nix.sh run .#testand./nix.sh run .#lintpass.Related
project simulateis a further caller.I have:
./nix.sh flake checkto ensure this PR is ready for review. (./nix.sh run .#testand./nix.sh run .#lintpass.)Linked a PR or a docs tracking issue to document this change.(no docs change)Addedbackport release-x.ylabels to auto-backport this PR.Need help with this checklist? See the cheat sheet.
🤖 Generated with Claude Code