agentscope-java icon indicating copy to clipboard operation
agentscope-java copied to clipboard

[Bug]: agentscope-nacos-spring-boot-starter auto-configurations activate by default due to matchIfMissing=true, causing startup failure when Nacos AI Service is unavailable

Open Buktal opened this issue 5 months ago • 0 comments

Describe the bug

agentscope-nacos-spring-boot-starter contains two auto-configuration classes — AgentscopeNacosPromptAutoConfiguration and AgentscopeA2aNacosAutoConfiguration — both annotated with @ConditionalOnProperty(..., matchIfMissing = true). This means both configurations activate automatically when the property is absent, causing a startup crash if the Nacos AI gRPC port (9848) is unreachable, even when the user never intends to use these features.

Additionally, AgentscopeA2aNacosAutoConfiguration calls a2aNacosProperties.getNacosProperties() (which applies the default 127.0.0.1:8848) when merging A2A-specific Nacos properties on top of the base configuration. This silently overwrites any agentscope.nacos.server-addr the user has configured, forcing the client to connect to localhost instead of the intended Nacos server.

Root cause summary:

  1. matchIfMissing = true (opt-out instead of opt-in) — Both auto-configurations activate by default when the user adds the starter to the classpath, regardless of whether the feature is configured. The intended behavior described in the Javadoc is opt-in (enabled=true required).

    Affected locations:

    • AgentscopeNacosPromptAutoConfiguration.java:57
    • AgentscopeA2aNacosAutoConfiguration.java:57
    • AgentscopeA2aNacosAutoConfiguration.java:115 (nested @ConditionalOnProperty for discovery)
    • AgentscopeA2aNacosAutoConfiguration.java:131 (nested @ConditionalOnProperty for registry)
  2. getNacosProperties() used instead of getExplicitNacosProperties() for A2A merge — BaseNacosProperties provides two methods specifically for different use cases: getNacosProperties() fills in defaults and is meant for final client construction; getExplicitNacosProperties() omits defaults and is meant for overlay/merge scenarios. AgentscopeA2aNacosAutoConfiguration uses the wrong one when merging A2A overrides, causing the default 127.0.0.1:8848 to overwrite a user-configured base address.

    Affected location:

    • AgentscopeA2aNacosAutoConfiguration.java:84

To Reproduce

  1. Add agentscope-nacos-spring-boot-starter to your project dependencies.
  2. Configure agentscope.nacos.server-addr to a non-localhost Nacos server (e.g. kb-nacos:8848).
  3. Do not configure agentscope.nacos.prompt.enabled or agentscope.a2a.nacos.enabled.
  4. Start the application.

Expected behavior

  • The application starts successfully.
  • Prompt and A2A auto-configurations remain inactive until explicitly enabled with enabled: true.
  • When enabled, the A2A Nacos client connects to the address configured under agentscope.nacos.server-addr, not 127.0.0.1:8848.

Error messages

UNAVAILABLE: io exception
  Caused by: java.net.ConnectException: Connection refused: getsockopt: /127.0.0.1:9848
  at com.alibaba.nacos.client.ai.NacosAiService.<init>(NacosAiService.java:122)
  at io.agentscope.spring.boot.nacos.AgentscopeNacosPromptAutoConfiguration.agentscopePromptAiService(...)
  at io.agentscope.spring.boot.nacos.AgentscopeA2aNacosAutoConfiguration.a2aService(...)

Proposed fix

Issue 1 — change matchIfMissing from true to false on all four @ConditionalOnProperty annotations listed above.

Issue 2 — in AgentscopeA2aNacosAutoConfiguration.java:84, replace:

// before
nacosClientProperties.putAll(a2aNacosProperties.getNacosProperties());

// after
nacosClientProperties.putAll(a2aNacosProperties.getExplicitNacosProperties());

getExplicitNacosProperties() already documents this exact use case: "This is useful for overlay/merge scenarios where default values should not overwrite a parent configuration."

Workaround (until fixed)

Explicitly disable the unused features in application.yaml:

agentscope:
  nacos:
    prompt:
      enabled: false
  a2a:
    nacos:
      enabled: false

Environment

  • AgentScope-Java Version: 2.0.0-RC2
  • Java Version: 21
  • OS: Windows

Buktal avatar Jun 11 '26 08:06 Buktal