Skip to content

refactor: trim transitive dependencies for library consumers - #3778

Merged
dgageot merged 2 commits into
docker:mainfrom
dgageot:refactor/trim-transitive-deps
Jul 22, 2026
Merged

refactor: trim transitive dependencies for library consumers#3778
dgageot merged 2 commits into
docker:mainfrom
dgageot:refactor/trim-transitive-deps

Conversation

@dgageot

@dgageot dgageot commented Jul 21, 2026

Copy link
Copy Markdown
Member

Downstream Go projects importing cagent packages (pkg/session, pkg/agent, pkg/model/provider, pkg/model/provider/anthropic) were pulling heavy transitive dependencies they didn't need — the full OCI registry stack and the entire Google Cloud auth stack — simply because those packages imported pkg/remote and pkg/model/provider/anthropic unconditionally.

The first commit moves the Docker Desktop proxy HTTP transport from pkg/remote into a new leaf package pkg/desktop/transport. The new transport.New constructor carries no OCI registry baggage; remote.NewTransport is kept as a deprecated forwarder so existing callers keep compiling without changes. Internal packages (pkg/httpclient, pkg/modelsdev, pkg/gateway, pkg/remote) are updated to import the new location. The second commit moves Vertex AI support out of pkg/model/provider/anthropic into pkg/model/provider/anthropic/vertex, wired through a new anthropic.NewClientFromFactory extension point. Config validation still runs before GCP credential discovery, credentials are still resolved eagerly, and the default providers registry retains full Vertex support through the vertexai provider — YAML configs are unaffected. Direct callers of the removed anthropic.NewVertexClient get a compile-time error rather than a silent behavior change.

Package Before After
pkg/model/provider 31 modules 24 modules
pkg/model/provider/anthropic 57 modules 35 modules

task build, task test, and task lint all pass. The pkg/teamloader example tests require a local Docker Model Runner and fail identically on main — pre-existing, unrelated.

dgageot added 2 commits July 21, 2026 22:32
…ansport

pkg/modelsdev, pkg/gateway and pkg/httpclient only needed
remote.NewTransport, but importing pkg/remote drags the whole OCI
registry stack (go-containerregistry, docker/cli, credential helpers)
into every consumer of pkg/model/provider, pkg/session and pkg/agent.

Move the transport (and its proxy fallback logic) to
pkg/desktop/transport, which only depends on pkg/desktop and
pkg/memoize. remote.NewTransport is kept as a deprecated forwarder so
existing integrations keep compiling and behaving identically.

pkg/model/provider now pulls 24 external modules instead of 31.
pkg/model/provider/anthropic unconditionally imported
anthropic-sdk-go/vertex and golang.org/x/oauth2/google, pulling the
whole Google Cloud auth stack (cloud.google.com/go/auth,
google.golang.org/api, grpc, protobuf, ...) into every consumer of the
plain Anthropic provider.

Move NewVertexClient to pkg/model/provider/anthropic/vertex.NewClient,
built on the new anthropic.NewClientFromFactory wiring point. Config
validation still runs before GCP credential discovery, and the default
providers registry keeps full Vertex support through the vertexai
provider, so existing YAML configs behave identically. Direct callers
of anthropic.NewVertexClient get a compile-time error pointing at the
new package rather than a silent behavior change.

pkg/model/provider/anthropic now pulls 35 external modules instead
of 57.
@dgageot
dgageot requested a review from a team as a code owner July 21, 2026 20:49

@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: 🟡 NEEDS ATTENTION

if req.GetBody != nil {
body, bodyErr := req.GetBody()
if bodyErr != nil {
return nil, err

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.

[medium] Wrong error returned when GetBody fails — proxy error masks body-reconstruction failure

When the proxy is unavailable and RoundTrip falls back to a direct retry, it calls req.GetBody() to reconstruct the request body. If GetBody() itself returns an error (bodyErr), the code discards that error and returns the original proxy socket error (err) instead:

body, bodyErr := req.GetBody()
if bodyErr != nil {
    return nil, err   // bodyErr is silently dropped
}

The caller receives a misleading "proxy unavailable" or "dial unix …" error when the real failure is body reconstruction. Although GetBody closures rarely fail in practice (they typically wrap an already-buffered body), the error contract is still broken — if they do fail the wrong error is surfaced, making the root cause invisible.

Suggested change
return nil, err
return nil, bodyErr
Confidence Score
🟢 strong 100/100

@aheritier aheritier added area/deps Dependency updates and version bumps area/gateway Gateway, proxy, and routing area/providers/anthropic For features/issues/fixes related to the usage of Anthropic models kind/refactor PR refactors code without behavior change labels Jul 21, 2026
@dgageot
dgageot merged commit be90024 into docker:main Jul 22, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/deps Dependency updates and version bumps area/gateway Gateway, proxy, and routing area/providers/anthropic For features/issues/fixes related to the usage of Anthropic models kind/refactor PR refactors code without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants