Skip to content

refactor(adk): make the foreground handoff API usable outside the module - #1233

Merged
hi-pender merged 1 commit into
alpha/10from
refactor/adk-foreground-candidate-api
Sep 1, 2026
Merged

refactor(adk): make the foreground handoff API usable outside the module#1233
hi-pender merged 1 commit into
alpha/10from
refactor/adk-foreground-candidate-api

Conversation

@hi-pender

Copy link
Copy Markdown
Contributor

Why

Two related problems on the public surface around foreground/background handoff.

1. ShouldAutoBackground cannot be used outside this module.

Its parameter type is foreground.CandidateInfo, defined in adk/internal/foreground. Packages under adk/ may import it, so CI stayed green — but an external caller gets:

use of internal package github.com/cloudwego/eino/adk/internal/foreground not allowed

There is no workaround: Go does not infer function-literal parameter types from assignment context, and a defined type is not identical to a structurally equal struct literal, so no assignable closure can be written. The field was unusable for every user of the framework. It appeared on five public configs (backgroundtask/local.Config, backgroundtask/tool.ManagedToolConfig, middlewares/subagent, middlewares/filesystem, prebuilt/deep). The Config docs also referenced foreground.DefaultTimeoutMs, equally unreachable.

2. LocalBackgroundConfig.AlwaysForeground names the wrong thing.

Its only effect is selecting what the tool's timeout argument bounds — the caller's foreground wait, or the command's own execution limit passed to filesystem.ExecuteRequest.Timeout. "Always foreground" named a derived consequence rather than the thing being configured, and hid the cost: the mode disables the Manager's foreground timer, so context cancellation becomes the only bound on a backend that ignores Timeout.

Worth noting because it is easy to assume otherwise: a nil ShouldAutoBackground is not equivalent to this mode. On timer expiry it calls cancel() and returns a *backgroundtask.ForegroundTimeoutError rather than staying attached.

What

  • Add backgroundtask.ForegroundCandidate (alias for the internal type) and backgroundtask.DefaultForegroundTimeoutMs. Same pattern as callbacks.RunInfo and schema.GobSerializer. foreground.Policy and ProjectionDetached stay internal — they are wiring, not user API.
  • Point all five ShouldAutoBackground fields at the public name, and the internal construction sites too, so no file carries two names for one type.
  • Rename AlwaysForegroundBackendOwnsCommandTimeout, with the doc comment restructured to state the timeout ownership, the cost, and the never-auto-backgrounded implication separately.
  • Rename the description variants to BackendTimeoutManagedExecuteToolDesc / ...Chinese.
  • Rename the internal helper to backendOwnsTimeoutForRun so it no longer collides with the struct field it reads.

No behavior change. Breaking change to API that has only shipped in v0.10.0-alpha.*.

Verification

  • go build ./...
  • go test -race ./... — full suite passes
  • golangci-lint run ./adk/... — 0 issues
  • gofmt -s -l ./adk — clean
  • Confirmed from a separate module (replace to this tree) that both renamed APIs are now reachable: constructing the callback, reading every ForegroundCandidate field, and referencing DefaultForegroundTimeoutMs and BackendOwnsCommandTimeout all compile and run.

🤖 Generated with Claude Code

Two related fixes to the public surface around foreground/background handoff.

ShouldAutoBackground was unusable outside this module. Its parameter type,
foreground.CandidateInfo, lives in adk/internal/foreground: packages under
adk/ can import it, so the build stayed green, but an external caller cannot.
There is also no workaround — Go does not infer function-literal parameter
types from assignment context, and a defined type is not identical to a
structurally equal struct literal, so no assignable closure can be written.
The field was dead weight for every user of the framework.

Expose backgroundtask.ForegroundCandidate as an alias for the internal type,
plus backgroundtask.DefaultForegroundTimeoutMs, which the Config docs already
referenced through an unreachable symbol. This follows the existing pattern in
callbacks.RunInfo and schema.GobSerializer. foreground.Policy and
ProjectionDetached stay internal: they are wiring, not user API.

Rename LocalBackgroundConfig.AlwaysForeground to BackendOwnsCommandTimeout.
The option's only effect is selecting what the tool's timeout argument bounds:
the caller's foreground wait, or the command's own execution limit passed to
filesystem.ExecuteRequest.Timeout. "Always foreground" named a derived
consequence rather than the thing being configured, and hid the cost — the
mode disables the Manager's foreground timer, leaving context cancellation as
the only bound on a backend that ignores Timeout. Note that a nil
ShouldAutoBackground is not equivalent: on timer expiry it terminates the run
with a *backgroundtask.ForegroundTimeoutError rather than staying attached.

The tool description variants are renamed to match
(BackendTimeoutManagedExecuteToolDesc), and the internal helper becomes
backendOwnsTimeoutForRun so it no longer collides with the struct field.

Breaking change to unreleased API; no behavior change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Comment thread adk/middlewares/filesystem/bash_run.go
@hi-pender
hi-pender merged commit 3174841 into alpha/10 Sep 1, 2026
14 checks passed
@hi-pender
hi-pender deleted the refactor/adk-foreground-candidate-api branch September 1, 2026 03:08
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (alpha/10@a4bcb2d). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             alpha/10    #1233   +/-   ##
===========================================
  Coverage            ?   81.92%           
===========================================
  Files               ?      219           
  Lines               ?    37230           
  Branches            ?        0           
===========================================
  Hits                ?    30501           
  Misses              ?     4527           
  Partials            ?     2202           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants