Skip to content

fix(nacos-starter): auto-configurations should be opt-in (matchIfMissing=false) and fix A2A server-addr override - #1709

Merged
oss-maintainer merged 4 commits into
agentscope-ai:mainfrom
Buktal:fix/nacos-starter-auto-config-opt-in
Jun 25, 2026
Merged

oss-maintainer merged 4 commits into
agentscope-ai:mainfrom
Buktal:fix/nacos-starter-auto-config-opt-in

Conversation

@Buktal

@Buktal Buktal commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

AgentScope-Java Version
2.0.0-RC2

Description

Two bugs in agentscope-nacos-spring-boot-starter cause startup crashes and silent server-addr override.

  1. matchIfMissing=true on @ConditionalOnProperty in AgentscopeNacosPromptAutoConfiguration and AgentscopeA2aNacosAutoConfiguration (and its nested discovery/registry beans) causes both auto-configurations to activate even when the user has not configured the feature. The Javadoc states these are opt-in features requiring enabled=true, but the implementation behaves as opt-out. Changed matchIfMissing to false.

  2. AgentscopeA2aNacosAutoConfiguration.a2aService() calls a2aNacosProperties.getNacosProperties() when merging A2A-specific config on top of the base config. getNacosProperties() fills in 127.0.0.1:8848 as a default, which then overwrites the user-configured agentscope.nacos.server-addr via putAll. Fixed by using getExplicitNacosProperties() instead — BaseNacosProperties documents this method as the correct choice for overlay/merge scenarios.

To test: existing tests shouldNotCreateBeansWhenDisabled and shouldNotCreateNacosBeansWhenDisabled cover the matchIfMissing fix. The server-addr fix can be verified by running shouldNotOverwriteGlobalServerAddrWhenPromptNotSet in AgentscopeNacosPromptAutoConfigurationTest.

Fixes #1707

…tNacosProperties for A2A merge

- AgentscopeNacosPromptAutoConfiguration and AgentscopeA2aNacosAutoConfiguration
  both used matchIfMissing=true, causing them to activate even when the user had
  not configured the feature, resulting in a startup crash when the Nacos AI gRPC
  port (9848) was unreachable.
- AgentscopeA2aNacosAutoConfiguration.a2aService() called getNacosProperties() on
  the A2A properties (which fills in the 127.0.0.1:8848 default) and then did a
  putAll on top of the base config, silently overwriting agentscope.nacos.server-addr.
  Fixed by using getExplicitNacosProperties() for the override, as BaseNacosProperties
  documents this method for exactly this overlay/merge use case.

Fixes agentscope-ai#1707
@Buktal
Buktal requested a review from a team June 11, 2026 08:25
@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/ext/spring-boot Spring Boot starters labels Jun 11, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 AI Review

This PR fixes two genuine bugs in agentscope-nacos-spring-boot-starter: (1) matchIfMissing=true incorrectly made opt-in auto-configurations activate by default, and (2) getNacosProperties() injected default serverAddr=127.0.0.1:8848 which silently overwrote user-configured base properties during merge. Both fixes are semantically correct and well-motivated. However, the PR does not update the existing tests in AgentscopeA2aNacosAutoConfigurationTest — at least 10 out of 14 tests rely on the old matchIfMissing=true behavior and will fail because they never set agentscope.a2a.nacos.enabled=true. These tests must be updated before merge.

name = "enabled",
havingValue = "true",
matchIfMissing = true)
matchIfMissing = false)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[critical] Changing matchIfMissing to false is correct for the production code, but at least 10 existing tests in AgentscopeA2aNacosAutoConfigurationTest will break because they never set agentscope.a2a.nacos.enabled=true. Tests like shouldCreateDefaultBeansWhenEnabled, shouldCreateNacosAgentCardResolverBean, shouldCreateNacosAgentRegistryBean, shouldNotCreateNacosAgentCardResolverWhenDiscoveryDisabled, shouldNotCreateNacosAgentRegistryWhenRegistryDisabled, shouldBindNacosProperties, shouldCreateWithCustomAgentCardResolver, shouldCreateWithCustomAgentRegistry, shouldCreateBeansWithRegistryProperties, shouldCreateBeansWithDiscoveryProperties, and shouldCloseNacosServiceOnShutdown all rely on the old matchIfMissing=true behavior.

All positive test cases must be updated to add agentscope.a2a.nacos.enabled=true. Additionally, tests that expect AgentCardResolver or AgentRegistry beans must also set agentscope.a2a.nacos.discovery.enabled=true and/or agentscope.a2a.nacos.registry.enabled=true respectively, since those bean-level conditions also changed to matchIfMissing=false.

Example fix for shouldCreateDefaultBeansWhenEnabled:

.withPropertyValues(
    "agentscope.a2a.nacos.enabled=true",
    "agentscope.a2a.nacos.discovery.enabled=true",
    "agentscope.a2a.nacos.registry.enabled=true",
    "agentscope.a2a.nacos.server-addr=127.0.0.1:8848",
    "agentscope.a2a.nacos.namespace=public")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ Verified as addressed in 6b26a9c: All positive test cases have been updated to include 'agentscope.a2a.nacos.enabled=true' (13 occurrences across all tests). The bot's second claim about bean-level @ConditionalOnProperty conditions changing to matchIfMissing=false is factually incorrect — the bean-level annotations for nacosAgentCardResolver() (line 115) and nacosAgentRegistry() (line 131) still have matchIfMissing=true, confirmed by both the source file and the PR diff. Therefore no additional discovery.enabled/registry.enabled properties are needed in tests that expect those beans.

throws NacosException {
Properties nacosClientProperties = nacosProperties.getNacosProperties();
nacosClientProperties.putAll(a2aNacosProperties.getNacosProperties());
nacosClientProperties.putAll(a2aNacosProperties.getExplicitNacosProperties());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[praise] Good fix. Using getExplicitNacosProperties() instead of getNacosProperties() is the correct approach for the overlay/merge pattern — it avoids injecting default serverAddr=127.0.0.1:8848 which would silently overwrite the user-configured agentscope.nacos.server-addr via putAll. This is now consistent with AgentscopeNacosPromptAutoConfiguration (line 68) which already uses getExplicitNacosProperties().

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ Verified as addressed in f833302: Code at line 86 correctly uses getExplicitNacosProperties() as praised.

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 AI Review

This PR fixes two genuine bugs in agentscope-nacos-spring-boot-starter: (1) matchIfMissing=true incorrectly made opt-in auto-configurations activate by default, and (2) getNacosProperties() injected default serverAddr=127.0.0.1:8848 which silently overwrote user-configured base properties during merge. Both fixes are semantically correct and well-motivated. However, the PR does not update the existing tests in AgentscopeA2aNacosAutoConfigurationTest — at least 10 out of 14 tests rely on the old matchIfMissing=true behavior and will fail because they never set agentscope.a2a.nacos.enabled=true. These tests must be updated before merge.

name = "enabled",
havingValue = "true",
matchIfMissing = true)
matchIfMissing = false)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[critical] Changing matchIfMissing to false is correct for the production code, but at least 10 existing tests in AgentscopeA2aNacosAutoConfigurationTest will break because they never set agentscope.a2a.nacos.enabled=true. Tests like shouldCreateDefaultBeansWhenEnabled, shouldCreateNacosAgentCardResolverBean, shouldCreateNacosAgentRegistryBean, shouldNotCreateNacosAgentCardResolverWhenDiscoveryDisabled, shouldNotCreateNacosAgentRegistryWhenRegistryDisabled, shouldBindNacosProperties, shouldCreateWithCustomAgentCardResolver, shouldCreateWithCustomAgentRegistry, shouldCreateBeansWithRegistryProperties, shouldCreateBeansWithDiscoveryProperties, and shouldCloseNacosServiceOnShutdown all rely on the old matchIfMissing=true behavior.

All positive test cases must be updated to add agentscope.a2a.nacos.enabled=true. Additionally, tests that expect AgentCardResolver or AgentRegistry beans must also set agentscope.a2a.nacos.discovery.enabled=true and/or agentscope.a2a.nacos.registry.enabled=true respectively, since those bean-level conditions also changed to matchIfMissing=false.

Example fix for shouldCreateDefaultBeansWhenEnabled:

.withPropertyValues(
    "agentscope.a2a.nacos.enabled=true",
    "agentscope.a2a.nacos.discovery.enabled=true",
    "agentscope.a2a.nacos.registry.enabled=true",
    "agentscope.a2a.nacos.server-addr=127.0.0.1:8848",
    "agentscope.a2a.nacos.namespace=public")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ Verified as addressed in 6b26a9c: Identical comment to the other thread. All positive test cases now set 'agentscope.a2a.nacos.enabled=true'. The bot's claim that bean-level conditions changed to matchIfMissing=false is incorrect — nacosAgentCardResolver() and nacosAgentRegistry() still have matchIfMissing=true (lines 115, 131). The actionable part of the concern is fully addressed; the non-actionable part was based on a false premise.

throws NacosException {
Properties nacosClientProperties = nacosProperties.getNacosProperties();
nacosClientProperties.putAll(a2aNacosProperties.getNacosProperties());
nacosClientProperties.putAll(a2aNacosProperties.getExplicitNacosProperties());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[praise] Good fix. Using getExplicitNacosProperties() instead of getNacosProperties() is the correct approach for the overlay/merge pattern — it avoids injecting default serverAddr=127.0.0.1:8848 which would silently overwrite the user-configured agentscope.nacos.server-addr via putAll. This is now consistent with AgentscopeNacosPromptAutoConfiguration (line 68) which already uses getExplicitNacosProperties().

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ Verified as addressed in f833302: Code at line 86 correctly uses getExplicitNacosProperties() as praised.

Buktal and others added 3 commits June 16, 2026 11:55
matchIfMissing changed to false requires explicit opt-in; update tests
to pass agentscope.a2a.nacos.enabled=true where AutoConfiguration
activation is expected.
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

All previously raised review comments have been addressed.

@oss-maintainer
oss-maintainer merged commit d262871 into agentscope-ai:main Jun 25, 2026
5 checks passed
wzl521 pushed a commit to wzl521/agentscope-java that referenced this pull request Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ext/spring-boot Spring Boot starters bug Something isn't working

Projects

None yet

3 participants