Skip to content

fix: lazy provider creation for goose acp (#7026)#7066

Open
codefromthecrypt wants to merge 1 commit intomainfrom
acp-lazy-provider
Open

fix: lazy provider creation for goose acp (#7026)#7066
codefromthecrypt wants to merge 1 commit intomainfrom
acp-lazy-provider

Conversation

@codefromthecrypt
Copy link
Collaborator

@codefromthecrypt codefromthecrypt commented Feb 7, 2026

Summary

Before, goose acp crashes on startup when there is not yet Goose configuration.

This PR makes provider creation lazy until an ACP session needs it.

This also adds missing ACP authMethods is added to the initialize response so ACP clients can prompt for setup.

Type of Change

  • Bug fix

AI Assistance

  • This PR was created or reviewed with AI assistance

Testing

  • New test_initialize_without_provider test verifies configuration isn't required to initialize ACP.

  • ACP registry validation against local build:

cargo build --release -p goose-cli

# Check out the registry PR that adds goose
cd ../registry
gh pr checkout 23
rm -rf .sandbox /tmp/empty-goose-home && mkdir -p /tmp/empty-goose-home

# Place binary and dummy archive so the verifier skips the download
mkdir -p .sandbox/binary/goose/extracted
cp ../goose-2/target/release/goose .sandbox/binary/goose/extracted/goose
touch .sandbox/binary/goose/goose-aarch64-apple-darwin.tar.bz2

# Run the same auth check the registry CI runs, pointing to an empty directory
GOOSE_PATH_ROOT=/tmp/empty-goose-home uv run --python 3.12 .github/workflows/verify_agents.py --agent goose --auth-check

Example output:

$ ± |add-goose-agent ✓| → GOOSE_PATH_ROOT=/tmp/empty-goose-home uv run --python 3.12 .github/workflows/verify_agents.py --agent goose --auth-check                     
Platform: darwin-aarch64
Registry: /Users/codefromthecrypt/oss/registry
Sandbox:  /Users/codefromthecrypt/oss/registry/.sandbox

Found 10 agents

Verifying 1 agent(s): goose

[1/1] goose (binary)
  Testing binary...
    → Auth check: /Users/codefromthecrypt/oss/registry/.sandbox/binary/goose/extracted/goose acp...
    ✓ Success: Auth OK: goose-provider(agent)
    Sandbox: /Users/codefromthecrypt/oss/registry/.sandbox/binary/goose

==================================================
Summary
==================================================
  Passed:  1
  Failed:  0
  Skipped: 0

All tests passed!

Sandboxes available at: /Users/codefromthecrypt/oss/registry/.sandbox

Related Issues

Fixes #7026
Unblocks agentclientprotocol/registry#23

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes ACP startup behavior by moving provider instantiation behind a lazy ProviderConstructor, and updates ACP initialization to advertise supported auth methods so registry validation can succeed.

Changes:

  • Make provider creation lazy by passing a ProviderConstructor into GooseAcpAgent and only constructing a provider when a session needs it.
  • Add authMethods to the ACP initialize response.
  • Update goose-acp test fixtures and add a new test covering initialize without an available provider.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/goose/src/providers/provider_registry.rs Exposes ProviderConstructor publicly for cross-crate use.
crates/goose-acp/src/server.rs Refactors agent construction to accept a provider factory; adds authMethods; introduces lazy provider setup via ensure_provider.
crates/goose-acp/src/server_factory.rs Updates HTTP/WS server factory to build GooseAcpAgent using ProviderConstructor.
crates/goose-acp/tests/fixtures/mod.rs Refactors in-process test server wiring to return a ready-to-use transport and adds initialize_agent helper.
crates/goose-acp/tests/fixtures/server.rs Adapts tests to the updated in-process server spawn API.
crates/goose-acp/tests/server_test.rs Adds test_initialize_without_provider and updates imports for new helpers/types.

Comment on lines 43 to 49
let provider_name = global_config
.get_goose_provider()
.map_err(|e| anyhow::anyhow!("No provider configured: {}", e))?;

let provider_factory: ProviderConstructor = Arc::new(move |model_config| {
let provider_name = provider_name.clone();
Box::pin(async move { goose::providers::create(&provider_name, model_config).await })
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

AcpServer::create_agent() still fails fast on missing GOOSE_MODEL/GOOSE_PROVIDER, which prevents the HTTP/WebSocket ACP server from even starting in environments without a config file. If the intent is truly lazy provider/model resolution, consider moving these lookups into the ProviderConstructor (or into GooseAcpAgent::ensure_provider) so transport startup + initialize can succeed and only session creation fails with a helpful error.

Suggested change
let provider_name = global_config
.get_goose_provider()
.map_err(|e| anyhow::anyhow!("No provider configured: {}", e))?;
let provider_factory: ProviderConstructor = Arc::new(move |model_config| {
let provider_name = provider_name.clone();
Box::pin(async move { goose::providers::create(&provider_name, model_config).await })
let provider_factory: ProviderConstructor = Arc::new(move |model_config| {
Box::pin(async move {
let global_config = Config::global();
let provider_name = global_config
.get_goose_provider()
.map_err(|e| anyhow::anyhow!("No provider configured: {}", e))?;
goose::providers::create(&provider_name, model_config).await
})

Copilot uses AI. Check for mistakes.
@codefromthecrypt codefromthecrypt marked this pull request as draft February 7, 2026 03:38
goose acp crashes on startup without provider config because it eagerly
creates a provider at construction time. Make provider creation lazy via
ProviderConstructor and add authMethods to the initialize response.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
@codefromthecrypt codefromthecrypt marked this pull request as ready for review February 7, 2026 09:38
Copilot AI review requested due to automatic review settings February 7, 2026 09:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Comment on lines +36 to +43
let provider_name = config.get_goose_provider().ok();

let provider_factory: ProviderConstructor = Arc::new(move |model_config| {
let provider_name = provider_name.clone();
Box::pin(async move {
let pn = provider_name.ok_or_else(|| anyhow::anyhow!("No provider configured"))?;
goose::providers::create(&pn, model_config).await
})
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

provider_name is captured as an Option at agent creation time, so if the user configures a provider after initialize (e.g., runs goose configure while the ACP process stays running), the provider factory will still keep returning "No provider configured"; consider resolving get_goose_provider() inside the factory on each invocation (or re-reading the config file) so sessions can succeed without requiring a restart.

Suggested change
let provider_name = config.get_goose_provider().ok();
let provider_factory: ProviderConstructor = Arc::new(move |model_config| {
let provider_name = provider_name.clone();
Box::pin(async move {
let pn = provider_name.ok_or_else(|| anyhow::anyhow!("No provider configured"))?;
goose::providers::create(&pn, model_config).await
})
let provider_factory: ProviderConstructor = Arc::new({
let config_path = config_path.clone();
move |model_config| {
let config_path = config_path.clone();
Box::pin(async move {
let config = goose::config::Config::new(&config_path, "goose")?;
let provider_name = config
.get_goose_provider()
.ok_or_else(|| anyhow::anyhow!("No provider configured"))?;
goose::providers::create(&provider_name, model_config).await
})
}

Copilot uses AI. Check for mistakes.
Comment on lines +396 to +401
// ensure_provider reads the model from config lazily, so tests need a
// config.yaml even though the factory ignores the model_config value.
let config_path = data_root.join("config.yaml");
if !config_path.exists() {
fs::write(&config_path, "GOOSE_MODEL: gpt-5-nano\n").unwrap();
}
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

This test helper hardcodes "config.yaml" instead of using goose::config::base::CONFIG_YAML_NAME, which can silently break tests if the config filename constant ever changes; prefer referencing the constant for consistency.

Copilot uses AI. Check for mistakes.
Comment on lines +719 to +729
async fn ensure_provider(&self, session: &Session) -> Result<()> {
let provider = match self.agent.provider().await {
Ok(p) => p,
Err(_) => {
// TODO: when session/set_model lands, use the client-provided
// modelId instead of the default read from config.
let config_path = self.config_dir.join(CONFIG_YAML_NAME);
let config = Config::new(&config_path, "goose")?;
let model_config = goose::model::ModelConfig::new(&config.get_goose_model()?)?;
(self.provider_factory)(model_config).await?
}
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

ensure_provider can race under concurrent session creation: two tasks can both observe Agent::provider() as unset and invoke provider_factory, potentially creating multiple providers unnecessarily; consider guarding initialization with a shared async lock/OnceCell so provider creation happens at most once per process.

Copilot uses AI. Check for mistakes.
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.

goose acp: fails ACP registry CI — missing authMethods and crashes without provider config

1 participant