Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
> **Purpose:** Living document tracking all changes, decisions, and reasoning during implementation. Updated as work progresses for easy reference and review.


---

## 🔎 fix(llm): dynamicAgentConfig context boundary — guardrails failed open on every turn that did not re-inject them (2026-08-09)

**Repo:** EDDI (`fix/dynamic-agent-context-boundary`)

Systematic sweep of the Context serialization boundary: for every context the system injects, what type does it hold (a) on the injecting turn, (b) after a store reload, (c) after crash recovery, (d) on another node? Nine context keys; eight are strings, lists or maps and survive unchanged. **`dynamicAgentConfig` is the only typed POJO the system injects — and it is the one that gates the tools that deploy real agents to production.**

1. **`resolveDynamicAgentConfig` failed open in two independent ways.** `MemberTurnExecutor` injects the group's guardrails on every member turn, and deliberately injects an explicitly *disabled* config when the group configured none — its comment says exactly why: a member turn that finds no config falls back to the STANDALONE default, which is fully permissive (creation, recruitment and delegation all on). The resolver defeated that defense twice: it read the **current step only**, so any turn that re-enters without a fresh injection (HITL tool-approval resume, crash recovery, the group follow-up path) saw nothing; and it required a live `DynamicAgentConfig` instance, but `ConversationMemoryStore`/`PostgresConversationMemoryStore` rebuild a stored context as `new Context(type, map)` — so after **any** reload the value is a `Map` and the `instanceof` failed even when the key was present. Both paths landed on the permissive default. Fixed: earlier steps are consulted as a fallback (the shape `ContextualToolsProvider#resolveGroupIds` and `resolveDelegationDepth` already use for exactly the resume case — this was the only sibling that did not), and the map form is coerced back whole-object via Jackson rather than field-by-field, so a guardrail added later cannot silently read back as its permissive Java default.
2. **Unresolvable guardrails on a group turn now fail CLOSED.** A conversation that demonstrably belongs to a group but whose config cannot be resolved returns a disabled config instead of the permissive default — the discipline `GroupTaskToolsProvider` and `ArtifactToolsProvider` already state. The group probe requires a context entry that actually *carries a value*, not merely a key: "the key exists" is too weak a claim to strip a standalone agent of tools its designer explicitly whitelisted.
3. **`GroupLifecycleOps.followUp` never injected the guardrails at all.** It injects `groupTranscript`/`groupId`/`groupConversationId` but not `dynamicAgentConfig`, so the defense `MemberTurnExecutor` documents was bypassed on the entire follow-up path — no crash or resume needed. Now injected identically.
4. **Two disagreeing defaults, and a Javadoc that was not true.** `ToolAssemblyContext`'s compact constructor normalizes a null config to a *disabled* one; `DynamicAgentToolsProvider` used a *permissive* one — and `contribute()` ignored `ctx.dynamicAgentConfig()` entirely and re-resolved from memory, despite `AgentOrchestrator#toolAssemblyContext` documenting that the value is resolved once "so two providers resolving it independently could [not] disagree". The provider now consumes the resolved value.
5. **Withheld group tools are logged.** `GroupTaskToolsProvider`/`ArtifactToolsProvider` returned an empty contribution silently. Withholding is correct for a forged or finished discussion id — but it is also what happens if the discussion runs on another node, and that failure looked like "the model just lost its tools" with nothing to diagnose from.

**Verified, not changed:** the node-affinity invariant `LiveDiscussionRegistry` rests on. Re-checked against the implementation rather than the note: `NatsConversationCoordinator.publishAndExecute` publishes only `conversationId.getBytes()` as an ordering marker and then runs the callable through `runtime.submitCallable` **locally**; no JetStream consumer deserializes or executes callables, and the payload could not carry one. A member turn cannot be routed off-node.

Suites: 377 across DynamicAgentToolsProvider / AgentOrchestrator / GroupLifecycleOps / MemberTurnExecutor, all green, +7 new (`DynamicAgentConfigContextBoundaryTest`, one nest per observation point a–d).

---

## 🔎 fix(groups): pre-merge deep review — facilitator HITL bypass, CALL_VOTE guards, metric cardinality, template honesty (2026-08-08)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ public GroupConversation followUpWithMember(String groupConversationId, String t
context.put("groupTranscript", new Context(Context.ContextType.object, followUpTranscript));
context.put("groupId", new Context(Context.ContextType.string, gc.getGroupId()));
context.put("groupConversationId", new Context(Context.ContextType.string, gc.getId()));
// Same injection, and for the same reason, as MemberTurnExecutor: a member
// turn that finds no dynamicAgentConfig falls back to the STANDALONE
// default, which is fully permissive. This path omitted it, so a follow-up
// question to a member of a group that never opted into dynamic agents
// handed that member creation/recruitment/delegation tools. An absent
// group config means "not opted in" — send an explicitly disabled one.
var dynamicAgentConfig = gc.getDynamicAgentConfig() != null
? gc.getDynamicAgentConfig()
: new AgentGroupConfiguration.DynamicAgentConfig();
context.put("dynamicAgentConfig", new Context(Context.ContextType.object, dynamicAgentConfig));
inputData.setContext(context);

CompletableFuture<String> responseFuture = new CompletableFuture<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
String callerConversationId = ctx.memory() != null ? ctx.memory().getConversationId() : null;
var live = liveDiscussionRegistry.getForMember(groupConversationId, callerConversationId);
if (live.isEmpty()) {
// See GroupTaskToolsProvider: withholding is correct, but silent
// withholding makes an off-node discussion indistinguishable from a forged
// id when the tools simply vanish mid-discussion.
LOGGER.debugf("Withholding artifact tools for agent='%s': conversation '%s' is not a member of a discussion "
+ "'%s' running on this node", ctx.agentId(), callerConversationId, groupConversationId);
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
return ToolContribution.empty();
}
AgentGroupConfiguration groupConfiguration = resolveGroup(live.get().getGroupId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import ai.labs.eddi.modules.llm.tools.spi.ToolAssemblyContext;
import ai.labs.eddi.modules.llm.tools.spi.ToolContribution;
import ai.labs.eddi.modules.llm.tools.spi.ToolSourceProvider;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import org.jboss.logging.Logger;

import java.util.ArrayList;
Expand Down Expand Up @@ -117,7 +120,12 @@ public ToolContribution contribute(ToolAssemblyContext ctx) {
return ToolContribution.empty();
}
List<Object> tools = new ArrayList<>();
addDynamicAgentTools(tools, ctx.builtInToolsWhitelist(), ctx.memory(), ctx.groupConversationId());
// The turn's already-resolved guardrails, not a second independent resolve.
// AgentOrchestrator#toolAssemblyContext documents that dynamicAgentConfig is
// resolved once "so two providers resolving it independently could [not]
// disagree" — but this provider re-resolved from memory and ignored the
// context, so the inconsistency the Javadoc warns about was in the code.
addDynamicAgentTools(tools, ctx.builtInToolsWhitelist(), ctx.memory(), ctx.groupConversationId(), ctx.dynamicAgentConfig());
if (tools.isEmpty()) {
return ToolContribution.empty();
}
Expand All @@ -141,6 +149,17 @@ void addDynamicAgentTools(List<Object> tools, List<String> whitelist, IConversat
}

void addDynamicAgentTools(List<Object> tools, List<String> whitelist, IConversationMemory memory, String groupConversationId) {
addDynamicAgentTools(tools, whitelist, memory, groupConversationId, null);
}

/**
* @param resolvedConfig
* the turn's guardrails as resolved once by the assembly context, or
* {@code null} to resolve them here (the direct-call entry points
* that have no assembly context)
*/
void addDynamicAgentTools(List<Object> tools, List<String> whitelist, IConversationMemory memory, String groupConversationId,
DynamicAgentConfig resolvedConfig) {
if (whitelist == null || whitelist.isEmpty()) {
return;
}
Expand All @@ -154,7 +173,7 @@ void addDynamicAgentTools(List<Object> tools, List<String> whitelist, IConversat
Set<String> sharedRetainedIds = ConcurrentHashMap.newKeySet();
String parentAgentId = memory.getAgentId();
String userId = memory.getUserId();
DynamicAgentConfig dynamicConfig = resolveDynamicAgentConfig(memory);
DynamicAgentConfig dynamicConfig = resolvedConfig != null ? resolvedConfig : resolveDynamicAgentConfig(memory);

boolean anyDynamicToolAdded = false;
if (whitelist.contains("create_sub_agent") && agentSetupService != null && conversationService != null) {
Expand Down Expand Up @@ -230,39 +249,190 @@ void addDynamicAgentTools(List<Object> tools, List<String> whitelist, IConversat
}
}

/** Context key carrying the group's dynamic-agent guardrails. */
static final String CONTEXT_DYNAMIC_AGENT_CONFIG = "context:dynamicAgentConfig";

/** Context key proving the conversation belongs to a group discussion. */
private static final String CONTEXT_GROUP_CONVERSATION_ID = "context:groupConversationId";

/**
* Tolerant reader for the guardrails, which arrive as a live POJO on the turn
* that injects them and as a plain {@code Map} on every turn read back from the
* store. Configured to ignore unknown properties so an older stored document
* cannot make the whole read fail — a failed read here means "no guardrails",
* which is the outcome this class exists to prevent.
*/
private static final ObjectMapper CONFIG_MAPPER = JsonMapper.builder()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.build();

/**
* Resolves the DynamicAgentConfig for the current conversation. If the agent is
* participating in a group discussion, the group's {@link DynamicAgentConfig}
* is passed via context variable {@code dynamicAgentConfig} by
* {@code GroupConversationService}. If no group config is present (standalone
* agent), a permissive default is used.
* Resolves the {@link DynamicAgentConfig} governing this turn.
* <p>
* <b>Why this is more than one {@code instanceof}.</b> The guardrails reach a
* member turn as a context variable that {@code MemberTurnExecutor} injects —
* deliberately, and with an explicitly <em>disabled</em> config when the group
* configured none, precisely so a group can never inherit the permissive
* standalone default. This method used to defeat that in two independent ways,
* both landing on {@link #createDefaultDynamicConfig()}:
* <ol>
* <li>It read the CURRENT step only. Any turn that re-enters a member
* conversation without a fresh injection — an HITL tool-approval resume, crash
* recovery, the group follow-up path — has no such context on its current
* step.</li>
* <li>It required a live {@link DynamicAgentConfig} instance. Conversation
* memory rebuilds a stored context as {@code new Context(type, map)}, so after
* any reload the value is a {@code Map} and the {@code instanceof} fails even
* when the key IS present.</li>
* </ol>
* Both are fixed here: earlier steps are consulted as a fallback (the same
* shape as {@code ContextualToolsProvider#resolveGroupIds} and
* {@link #resolveDelegationDepth}, which already do this for exactly the resume
* case), and a {@code Map} is coerced back into the config.
* <p>
* The remaining case — a conversation that demonstrably belongs to a group but
* whose guardrails cannot be resolved at all — now fails CLOSED. Substituting
* the permissive default there would hand roster-mutating, agent-deploying
* tools to a member of a discussion whose operator never opted in, which is the
* discipline every sibling provider in this package already applies.
*
* @param memory
* the conversation memory to check for group context
* @return the resolved DynamicAgentConfig — group-level if available,
* permissive default otherwise
* @return the group's guardrails; a disabled config when the turn is part of a
* group but they cannot be resolved; the permissive standalone default
* only for a conversation with no group context at all
*/
static DynamicAgentConfig resolveDynamicAgentConfig(IConversationMemory memory) {
// Check if GroupConversationService injected a DynamicAgentConfig via context
DynamicAgentConfig resolved = readDynamicAgentConfig(memory);
if (resolved != null) {
LOGGER.debugf("[DYNAMIC] Using group-level DynamicAgentConfig for agent='%s'", sanitize(memory.getAgentId()));
return resolved;
}

if (hasGroupContext(memory)) {
LOGGER.warnf("[DYNAMIC] Conversation of agent='%s' carries group context but no resolvable dynamicAgentConfig — "
+ "withholding dynamic-agent capabilities rather than falling back to the permissive standalone default",
sanitize(memory.getAgentId()));
return new DynamicAgentConfig();
}

// Genuinely standalone agent — the permissive default it was written for.
return createDefaultDynamicConfig();
}

/**
* The injected guardrails from the current step, else the most recent earlier
* step that carries them, else {@code null}.
*/
private static DynamicAgentConfig readDynamicAgentConfig(IConversationMemory memory) {
var currentStep = memory.getCurrentStep();
if (currentStep != null) {
var contextData = currentStep.getLatestData("context:dynamicAgentConfig");
if (contextData != null) {
Object value = contextData.getResult();
if (value instanceof Context ctx && ctx.getValue() instanceof DynamicAgentConfig groupConfig) {
LOGGER.debugf("[DYNAMIC] Using group-level DynamicAgentConfig for agent='%s'", sanitize(memory.getAgentId()));
return groupConfig;
DynamicAgentConfig fromCurrent = asDynamicAgentConfig(currentStep.getLatestData(CONTEXT_DYNAMIC_AGENT_CONFIG));
if (fromCurrent != null) {
return fromCurrent;
}
}

var allSteps = memory.getAllSteps();
if (allSteps != null) {
List<IData<Object>> priorEntries = allSteps.getAllLatestData(CONTEXT_DYNAMIC_AGENT_CONFIG);
if (priorEntries != null) {
for (IData<Object> entry : priorEntries) {
DynamicAgentConfig fromPrior = asDynamicAgentConfig(entry);
if (fromPrior != null) {
return fromPrior;
}
}
}
}
// Fallback: standalone agent — use permissive defaults
return createDefaultDynamicConfig();
return null;
}

/**
* Unwraps a {@code context:*} entry into guardrails, accepting both the live
* POJO and the map form read back from the store. Mirrors
* {@code AttachmentContextExtractor#asAttachment}, the existing precedent for
* this dual read.
*/
private static DynamicAgentConfig asDynamicAgentConfig(IData<?> data) {
if (data == null || !(data.getResult() instanceof Context ctx)) {
return null;
}
Object value = ctx.getValue();
if (value instanceof DynamicAgentConfig config) {
return config;
}
if (!(value instanceof Map<?, ?> map) || map.isEmpty()) {
return null;
}
try {
// Whole-object conversion, not field-by-field: a guardrail added to
// DynamicAgentConfig later must not silently read back as its permissive
// Java default just because nobody remembered to map it here.
return CONFIG_MAPPER.convertValue(map, DynamicAgentConfig.class);
} catch (IllegalArgumentException e) {
LOGGER.warnf("[DYNAMIC] Stored dynamicAgentConfig context could not be read back (%s) — treating it as unresolvable",
e.getMessage());
return null;
}
}

/**
* Whether this conversation demonstrably belongs to a group discussion — what
* tells "standalone agent, use the permissive default" apart from "group member
* whose guardrails went missing".
* <p>
* A group-conversation id that actually carries a value is required, not merely
* an entry under the key. "The key exists" is too weak a claim to disable an
* agent's configured tools on: a blank or unreadable entry proves nothing, and
* treating it as proof would let any malformed step data silently strip a
* standalone agent of capabilities its designer explicitly whitelisted.
*/
private static boolean hasGroupContext(IConversationMemory memory) {
var currentStep = memory.getCurrentStep();
if (currentStep != null && (carriesValue(currentStep.getLatestData(CONTEXT_GROUP_CONVERSATION_ID))
|| carriesValue(currentStep.getLatestData(CONTEXT_DYNAMIC_AGENT_CONFIG)))) {
return true;
}
var allSteps = memory.getAllSteps();
if (allSteps == null) {
return false;
}
return anyCarriesValue(allSteps.getAllLatestData(CONTEXT_GROUP_CONVERSATION_ID))
|| anyCarriesValue(allSteps.getAllLatestData(CONTEXT_DYNAMIC_AGENT_CONFIG));
}

/** True when the entry is a {@link Context} holding a non-blank value. */
private static boolean carriesValue(IData<?> data) {
if (data == null || !(data.getResult() instanceof Context ctx) || ctx.getValue() == null) {
return false;
}
return !(ctx.getValue() instanceof String s) || !s.isBlank();
}

private static boolean anyCarriesValue(List<IData<Object>> entries) {
if (entries == null) {
return false;
}
for (IData<Object> entry : entries) {
if (carriesValue(entry)) {
return true;
}
}
return false;
}

/**
* Creates a default DynamicAgentConfig for agents without explicit group
* config. Used when individual agents have dynamic agent tools in their
* whitelist.
* <p>
* Permissive by design, and safe ONLY for a genuinely standalone conversation:
* the tools it governs are still gated by the agent's own
* {@code enableBuiltInTools} switch and built-in tool whitelist, so reaching
* this default means an agent designer explicitly asked for these tools outside
* any group. {@link #resolveDynamicAgentConfig} must never return it for a turn
* that belongs to a group.
*/
static DynamicAgentConfig createDefaultDynamicConfig() {
var config = new DynamicAgentConfig();
Expand Down
Loading
Loading