fix: commands respect selected environment
All checks were successful
CI / cleanup-branch (push) Has been skipped
CI / build (push) Successful in 1m19s
CI / docker (push) Successful in 1m4s
CI / deploy-feature (push) Has been skipped
CI / deploy (push) Successful in 40s

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:
hsiegeln
2026-04-09 16:28:09 +02:00
parent 69dcce2a8f
commit 1971c70638
10 changed files with 101 additions and 48 deletions

View File

@@ -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&lt;CommandReply&gt;.
*/
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();