TDD: LLMAgent's ephemeral ToolAgent dispatch derives both D-9 global-safety conditions from one shared signal, bypassing the AND composition #194

Closed
opened 2026-11-26 11:52:14 +00:00 by CoreRasurae · 0 comments
Member

Metadata

  • Commit Message: test(agents): add failing regression for LLMAgent's collapsed D-9 global-safety signal (#195)
  • Branch: tdd/m1-llm-tool-dispatch-shared-unsafe-signal

Background and context

PR #193 (issue #189) corrected ToolAgent._is_global_unsafe to require, at once, both (a) the invocation context carrying _unsafe_mode: true and (b) the ToolAgent's own safe_mode field being false (ADR-2034 D-9, docs/index.md §4.4.8: "rather than treating the agent's own config field and host mode as interchangeable"). That fix is correct for a directly constructed ToolAgent -- the only construction path the Behave suite exercises.

However, the dominant real-world path for invoking a skill is a type: llm agent's tool-call loop, which constructs an ephemeral ToolAgent per call via LLMAgent._build_ephemeral_tool_config/_build_tool_context (src/cleveractors/agents/llm.py). Both of those builders are fed from a single boolean, parent_unsafe, returned by LLMAgent._resolve_parent_unsafe:

def _resolve_parent_unsafe(self, context):
    return (self.config.get("safe_mode", True) is False) or bool(
        context and context.get("_unsafe_mode")
    )

_build_ephemeral_tool_config(tool_name, parent_unsafe) sets the ephemeral agent's own safe_mode = not parent_unsafe, and _build_tool_context(parent_unsafe) sets the ephemeral context's _unsafe_mode = parent_unsafe -- the same parent_unsafe value feeds both. This pattern repeats at all three tool-dispatch call sites in _execute_tool_loop (agents/llm.py ~lines 1221-1230, ~1376-1395, ~1544-1553).

This was behavior-neutral before PR #193, when _is_global_unsafe was itself an OR: OR(parent_unsafe, parent_unsafe) == parent_unsafe == OR(own_safe_mode, host_unsafe), so collapsing the two legs into one shared signal reproduced the intended OR exactly. After PR #193 changed _is_global_unsafe to AND, the same collapse now produces AND(parent_unsafe, parent_unsafe) == parent_unsafe == OR(own_safe_mode, host_unsafe) -- i.e. the ephemeral-ToolAgent path still evaluates to the pre-fix OR semantics, regardless of the corrected AND composition, because both of the AND's operands are forced identical before _is_global_unsafe ever sees them.

Raised and scoped out (correctly, as pre-existing and outside #189's atomic fix) in reviewer hurui200320's PR #193 reviews; tracked here as its own issue per that review's "Scope notes"/"Scope exclusions."

Current behavior

An LLM agent with skills: [...] and its own safe_mode: false -- with no host ever placed in unsafe mode, and no actor context.global.unsafe declaration in effect -- can still execute a safe_mode: false skill's bundled scripts/ resource or read its non-standard-folder resources through the real tool-call loop. _resolve_parent_unsafe returns True from the agent's own safe_mode: false alone, and that single True is handed to both builders, so the ephemeral ToolAgent ends up with safe_mode: false and _unsafe_mode: true in its context simultaneously -- satisfying _is_global_unsafe's AND even though only one real authority (the agent author) ever opted in.

Expected behavior

The ephemeral ToolAgent's own safe_mode must be derived solely from this LLMAgent's own safe_mode config field, and the ephemeral context's _unsafe_mode must be derived solely from whether the invocation context already carries a genuine host-propagated _unsafe_mode: true (§9.4/§10.3) -- the two conditions resolved independently, exactly as docs/index.md §4.4.8 requires ("rather than treating the agent's own config field and host mode as interchangeable"). An LLM agent with only its own safe_mode: false set, on a host never placed in unsafe mode, must have privileged skill operations refused -- matching the behavior a direct ToolAgent construction already exhibits post-#193.

Acceptance criteria

  • A Behave scenario constructs a type: llm agent with safe_mode: false and a loaded safe_mode: false skill, with no host-level unsafe signal anywhere in the invocation context, drives a model-issued tool call that attempts a privileged skill operation (script execution or non-standard-folder read), and asserts the call is refused.
  • The assertion fails today (reproducing the bug) because the ephemeral ToolAgent currently receives _unsafe_mode: true purely from the agent's own safe_mode: false.
  • The scenario is tagged @tdd_issue, @tdd_issue_195, and @tdd_expected_fail, with the failing step using assert/raise AssertionError only.

Supporting information

  • Spec: docs/index.md §4.4.8 ("The double-safety gate", "Global safety").
  • docs/adr/ADR-2034-skill-package-support.md (D-9, corrected 2026-11-25).
  • Code: src/cleveractors/agents/llm.py (_resolve_parent_unsafe, _build_ephemeral_tool_config, _build_tool_context, and their three call sites in _execute_tool_loop).
  • Prior history: issue #115/#116 (introduced the single shared parent_unsafe signal, correct under the then-OR'd D-9; not revisited when D-9 was corrected to AND).
  • Raised during PR #193 review by hurui200320, explicitly scoped out of that PR as a separate, pre-existing architectural question. Tracks the fix via issue #195.

Subtasks

  • Write a Behave scenario in features/llm_agent_tool_loop.feature (or the agent-skills feature covering LLM-agent-driven skill dispatch) proving the bug (#195): agent-only safe_mode: false, no host-level unsafe signal, privileged skill operation is wrongly permitted.
  • Tag the scenario @tdd_issue, @tdd_issue_195, @tdd_expected_fail.
  • Confirm the scenario fails (asserts the bug is present) when run without the tag inversion.
  • Run nox -s unit_tests to confirm the suite passes overall (the new scenario passes via @tdd_expected_fail inversion).
  • Verify coverage >=97% via nox -s coverage_report.
  • Run nox (all default sessions), fix any errors.

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line matches the Commit Message in Metadata exactly.
  • The commit is pushed to the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a PR to develop, reviewed, and merged.
## Metadata - **Commit Message:** test(agents): add failing regression for LLMAgent's collapsed D-9 global-safety signal (#195) - **Branch:** tdd/m1-llm-tool-dispatch-shared-unsafe-signal ## Background and context PR #193 (issue #189) corrected `ToolAgent._is_global_unsafe` to require, at once, both (a) the invocation context carrying `_unsafe_mode: true` and (b) the `ToolAgent`'s own `safe_mode` field being `false` (ADR-2034 D-9, `docs/index.md` §4.4.8: "rather than treating the agent's own config field and host mode as interchangeable"). That fix is correct for a directly constructed `ToolAgent` -- the only construction path the Behave suite exercises. However, the dominant real-world path for invoking a skill is a `type: llm` agent's tool-call loop, which constructs an *ephemeral* `ToolAgent` per call via `LLMAgent._build_ephemeral_tool_config`/`_build_tool_context` (`src/cleveractors/agents/llm.py`). Both of those builders are fed from a single boolean, `parent_unsafe`, returned by `LLMAgent._resolve_parent_unsafe`: ```python def _resolve_parent_unsafe(self, context): return (self.config.get("safe_mode", True) is False) or bool( context and context.get("_unsafe_mode") ) ``` `_build_ephemeral_tool_config(tool_name, parent_unsafe)` sets the ephemeral agent's own `safe_mode = not parent_unsafe`, and `_build_tool_context(parent_unsafe)` sets the ephemeral context's `_unsafe_mode = parent_unsafe` -- the *same* `parent_unsafe` value feeds both. This pattern repeats at all three tool-dispatch call sites in `_execute_tool_loop` (`agents/llm.py` ~lines 1221-1230, ~1376-1395, ~1544-1553). This was behavior-neutral before PR #193, when `_is_global_unsafe` was itself an OR: `OR(parent_unsafe, parent_unsafe) == parent_unsafe == OR(own_safe_mode, host_unsafe)`, so collapsing the two legs into one shared signal reproduced the intended OR exactly. After PR #193 changed `_is_global_unsafe` to AND, the same collapse now produces `AND(parent_unsafe, parent_unsafe) == parent_unsafe == OR(own_safe_mode, host_unsafe)` -- i.e. the ephemeral-ToolAgent path still evaluates to the pre-fix OR semantics, regardless of the corrected AND composition, because both of the AND's operands are forced identical before `_is_global_unsafe` ever sees them. Raised and scoped out (correctly, as pre-existing and outside #189's atomic fix) in reviewer hurui200320's PR #193 reviews; tracked here as its own issue per that review's "Scope notes"/"Scope exclusions." ## Current behavior An LLM agent with `skills: [...]` and its own `safe_mode: false` -- with **no** host ever placed in unsafe mode, and no actor `context.global.unsafe` declaration in effect -- can still execute a `safe_mode: false` skill's bundled `scripts/` resource or read its non-standard-folder resources through the real tool-call loop. `_resolve_parent_unsafe` returns `True` from the agent's own `safe_mode: false` alone, and that single `True` is handed to *both* builders, so the ephemeral `ToolAgent` ends up with `safe_mode: false` **and** `_unsafe_mode: true` in its context simultaneously -- satisfying `_is_global_unsafe`'s AND even though only one real authority (the agent author) ever opted in. ## Expected behavior The ephemeral `ToolAgent`'s own `safe_mode` must be derived solely from this `LLMAgent`'s own `safe_mode` config field, and the ephemeral context's `_unsafe_mode` must be derived solely from whether the *invocation* context already carries a genuine host-propagated `_unsafe_mode: true` (§9.4/§10.3) -- the two conditions resolved independently, exactly as `docs/index.md` §4.4.8 requires ("rather than treating the agent's own config field and host mode as interchangeable"). An LLM agent with only its own `safe_mode: false` set, on a host never placed in unsafe mode, must have privileged skill operations refused -- matching the behavior a direct `ToolAgent` construction already exhibits post-#193. ## Acceptance criteria - [ ] A Behave scenario constructs a `type: llm` agent with `safe_mode: false` and a loaded `safe_mode: false` skill, with no host-level unsafe signal anywhere in the invocation context, drives a model-issued tool call that attempts a privileged skill operation (script execution or non-standard-folder read), and asserts the call is refused. - [ ] The assertion fails today (reproducing the bug) because the ephemeral `ToolAgent` currently receives `_unsafe_mode: true` purely from the agent's own `safe_mode: false`. - [ ] The scenario is tagged `@tdd_issue`, `@tdd_issue_195`, and `@tdd_expected_fail`, with the failing step using `assert`/`raise AssertionError` only. ## Supporting information - Spec: `docs/index.md` §4.4.8 ("The double-safety gate", "Global safety"). - `docs/adr/ADR-2034-skill-package-support.md` (D-9, corrected 2026-11-25). - Code: `src/cleveractors/agents/llm.py` (`_resolve_parent_unsafe`, `_build_ephemeral_tool_config`, `_build_tool_context`, and their three call sites in `_execute_tool_loop`). - Prior history: issue #115/#116 (introduced the single shared `parent_unsafe` signal, correct under the then-OR'd D-9; not revisited when D-9 was corrected to AND). - Raised during PR #193 review by hurui200320, explicitly scoped out of that PR as a separate, pre-existing architectural question. Tracks the fix via issue #195. ## Subtasks - [ ] Write a Behave scenario in `features/llm_agent_tool_loop.feature` (or the agent-skills feature covering LLM-agent-driven skill dispatch) proving the bug (#195): agent-only `safe_mode: false`, no host-level unsafe signal, privileged skill operation is wrongly permitted. - [ ] Tag the scenario `@tdd_issue`, `@tdd_issue_195`, `@tdd_expected_fail`. - [ ] Confirm the scenario fails (asserts the bug is present) when run without the tag inversion. - [ ] Run `nox -s unit_tests` to confirm the suite passes overall (the new scenario passes via `@tdd_expected_fail` inversion). - [ ] Verify coverage >=97% via `nox -s coverage_report`. - [ ] Run `nox` (all default sessions), fix any errors. ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the first line matches the Commit Message in Metadata exactly. - The commit is pushed to the branch matching the Branch in Metadata exactly. - The commit is submitted as a PR to develop, reviewed, and merged.
CoreRasurae added this to the v2.1.0 milestone 2026-11-26 11:52:14 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveractors-core#194
No description provided.