fix: commands respect selected environment
Backend: AgentRegistryService gains findByApplicationAndEnvironment() and environment-aware addGroupCommandWithReplies() overload. AgentCommandController and ApplicationConfigController accept optional environment query parameter. When set, commands only target agents in that environment. Backward compatible — null means all environments. Frontend: All command mutations (config update, route control, traced processors, tap config, route recording) now pass selectedEnv to the backend via query parameter. Prevents cross-environment command leakage — e.g., updating config for prod no longer pushes to dev agents. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -214,6 +214,16 @@ public class AgentRegistryService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all agents belonging to the given application and environment.
|
||||
*/
|
||||
public List<AgentInfo> findByApplicationAndEnvironment(String application, String environment) {
|
||||
return agents.values().stream()
|
||||
.filter(a -> application.equals(a.applicationId()))
|
||||
.filter(a -> environment.equals(a.environmentId()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a command to an agent's pending queue.
|
||||
* Notifies the event listener if one is set.
|
||||
@@ -336,8 +346,21 @@ public class AgentRegistryService {
|
||||
*/
|
||||
public Map<String, CompletableFuture<CommandReply>> addGroupCommandWithReplies(
|
||||
String group, CommandType type, String payload) {
|
||||
return addGroupCommandWithReplies(group, null, type, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a command to all LIVE agents in a group, optionally filtered by environment.
|
||||
* When environment is null, targets all agents for the application.
|
||||
* Returns a map of agentId -> CompletableFuture<CommandReply>.
|
||||
*/
|
||||
public Map<String, CompletableFuture<CommandReply>> addGroupCommandWithReplies(
|
||||
String group, String environment, CommandType type, String payload) {
|
||||
Map<String, CompletableFuture<CommandReply>> results = new LinkedHashMap<>();
|
||||
List<AgentInfo> liveAgents = findByApplication(group).stream()
|
||||
List<AgentInfo> candidates = environment != null
|
||||
? findByApplicationAndEnvironment(group, environment)
|
||||
: findByApplication(group);
|
||||
List<AgentInfo> liveAgents = candidates.stream()
|
||||
.filter(a -> a.state() == AgentState.LIVE)
|
||||
.toList();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user