fix(agents): derive the ephemeral ToolAgent's own safe_mode and the host's _unsafe_mode independently in LLMAgent tool dispatch #198

Merged
CoreRasurae merged 1 commit from bugfix/m1-llm-tool-dispatch-shared-unsafe-signal into develop 2026-12-01 19:47:08 +00:00
Member

Summary

Fixes issue #195: LLMAgent._execute_tool_loop()'s three ephemeral-ToolAgent dispatch sites derived a single shared parent_unsafe boolean (_resolve_parent_unsafe) -- true when EITHER this agent's own safe_mode: false OR the invocation context's _unsafe_mode: true -- and fed that same value into both the ephemeral agent's own safe_mode and its context's _unsafe_mode. Because both operands of ToolAgent._is_global_unsafe's AND (corrected by PR #193 / issue #189) were thereby forced identical, the ephemeral-dispatch path silently kept evaluating to the pre-#193 OR semantics: an LLM agent author's own safe_mode: false alone could still unlock a loaded skill's privileged operations, or a model-issued file_write, with no host ever placed in unsafe mode.

_resolve_parent_unsafe is replaced with two independent resolvers:

  • _resolve_own_unsafe_opt_out() -- this agent's own safe_mode config field only.
  • _resolve_host_unsafe_signal(context) -- the invocation context's genuine host-propagated _unsafe_mode only.

Both are threaded independently through all three _execute_tool_loop dispatch sites (budget-retry, primary, stuck-model-retry mirrors), so _build_ephemeral_tool_config only ever sees the agent's own opt-out and _build_tool_context only ever sees the host signal -- matching docs/index.md §4.4.8/§4.5.4/§10.3 and docs/adr/ADR-2034-skill-package-support.md D-9 (corrected 2026-11-25).

Changes

  • src/cleveractors/agents/llm.py: split _resolve_parent_unsafe into _resolve_own_unsafe_opt_out/_resolve_host_unsafe_signal; updated _build_ephemeral_tool_config/_build_tool_context signatures and all three dispatch sites.
  • src/cleveractors/runtime_dispatch.py: updated two doc comments referencing the old method name.
  • features/llm_agent_tool_loop.feature / features/steps/llm_agent_tool_loop_steps.py: removed @tdd_expected_fail from the issue #194 regression scenario (now passes for the right reason); added a host-unsafe invocation context When-step; updated the pre-existing issue #115 scenario (and rewrote its now-accurate explanatory comment block) to configure a genuine host-unsafe context explicitly alongside the agent's own safe_mode: false; completed the ticket's three-scenario Behave matrix on the real LLM-dispatch path (own-safe_mode-only refused, host-unsafe-only refused, both-true opens the gate), mirroring agent_skills.feature:816-832's #189 shape.
  • robot/SkillLoadingTestLib.py / robot/agent_skills.robot: added a host_unsafe keyword argument to Process Message With Agent; updated the Bundled Script Executes End To End Behind The Double Safety Gate integration test to configure both D-9 conditions explicitly.
  • CHANGELOG.md: one ### Changed entry covering the skill-gate and file_write consequences.

Test plan

  • nox -s lint / nox -s format -- --check -- green
  • nox -s typecheck -- green (0 errors)
  • nox -s unit_tests -- 3375/3375 scenarios passed, 0 failed (37 original #195-area scenarios + 2 new, matrix-completing ones)
  • nox -s coverage_report -- 97.3% (>= 96.5% threshold); changed region fully covered
  • nox -s security_scan -- 0 findings
  • nox -s dead_code -- clean
  • nox -s integration_tests -- 382/382 passed
  • @tdd_issue_195 regression matrix (own-only / host-only / both-true) passes without @tdd_expected_fail

Closes #195

## Summary Fixes issue #195: `LLMAgent._execute_tool_loop()`'s three ephemeral-`ToolAgent` dispatch sites derived a single shared `parent_unsafe` boolean (`_resolve_parent_unsafe`) -- true when EITHER this agent's own `safe_mode: false` OR the invocation context's `_unsafe_mode: true` -- and fed that same value into both the ephemeral agent's own `safe_mode` and its context's `_unsafe_mode`. Because both operands of `ToolAgent._is_global_unsafe`'s AND (corrected by PR #193 / issue #189) were thereby forced identical, the ephemeral-dispatch path silently kept evaluating to the pre-#193 OR semantics: an LLM agent author's own `safe_mode: false` alone could still unlock a loaded skill's privileged operations, or a model-issued `file_write`, with no host ever placed in unsafe mode. `_resolve_parent_unsafe` is replaced with two independent resolvers: - `_resolve_own_unsafe_opt_out()` -- this agent's own `safe_mode` config field only. - `_resolve_host_unsafe_signal(context)` -- the invocation context's genuine host-propagated `_unsafe_mode` only. Both are threaded independently through all three `_execute_tool_loop` dispatch sites (budget-retry, primary, stuck-model-retry mirrors), so `_build_ephemeral_tool_config` only ever sees the agent's own opt-out and `_build_tool_context` only ever sees the host signal -- matching `docs/index.md` §4.4.8/§4.5.4/§10.3 and `docs/adr/ADR-2034-skill-package-support.md` D-9 (corrected 2026-11-25). ## Changes - `src/cleveractors/agents/llm.py`: split `_resolve_parent_unsafe` into `_resolve_own_unsafe_opt_out`/`_resolve_host_unsafe_signal`; updated `_build_ephemeral_tool_config`/`_build_tool_context` signatures and all three dispatch sites. - `src/cleveractors/runtime_dispatch.py`: updated two doc comments referencing the old method name. - `features/llm_agent_tool_loop.feature` / `features/steps/llm_agent_tool_loop_steps.py`: removed `@tdd_expected_fail` from the issue #194 regression scenario (now passes for the right reason); added a `host-unsafe invocation context` When-step; updated the pre-existing issue #115 scenario (and rewrote its now-accurate explanatory comment block) to configure a genuine host-unsafe context explicitly alongside the agent's own `safe_mode: false`; completed the ticket's three-scenario Behave matrix on the real LLM-dispatch path (own-safe_mode-only refused, host-unsafe-only refused, both-true opens the gate), mirroring `agent_skills.feature:816-832`'s #189 shape. - `robot/SkillLoadingTestLib.py` / `robot/agent_skills.robot`: added a `host_unsafe` keyword argument to `Process Message With Agent`; updated the `Bundled Script Executes End To End Behind The Double Safety Gate` integration test to configure both D-9 conditions explicitly. - `CHANGELOG.md`: one `### Changed` entry covering the skill-gate and `file_write` consequences. ## Test plan - [x] `nox -s lint` / `nox -s format -- --check` -- green - [x] `nox -s typecheck` -- green (0 errors) - [x] `nox -s unit_tests` -- 3375/3375 scenarios passed, 0 failed (37 original #195-area scenarios + 2 new, matrix-completing ones) - [x] `nox -s coverage_report` -- 97.3% (>= 96.5% threshold); changed region fully covered - [x] `nox -s security_scan` -- 0 findings - [x] `nox -s dead_code` -- clean - [x] `nox -s integration_tests` -- 382/382 passed - [x] `@tdd_issue_195` regression matrix (own-only / host-only / both-true) passes without `@tdd_expected_fail` Closes #195
CoreRasurae added this to the v2.1.0 milestone 2026-11-27 15:54:50 +00:00
fix(agents): derive the ephemeral ToolAgent's own safe_mode and the host's _unsafe_mode independently in LLMAgent tool dispatch
Some checks failed
CI / lint (pull_request) Successful in 1m34s
CI / typecheck (pull_request) Successful in 2m11s
CI / security (pull_request) Successful in 59s
CI / build (pull_request) Successful in 1m43s
CI / quality (pull_request) Successful in 2m20s
CI / integration_tests (pull_request) Successful in 3m0s
CI / unit_tests (pull_request) Successful in 7m31s
CI / coverage (pull_request) Successful in 6m49s
CI / status-check (pull_request) Successful in 1s
CI / benchmark (pull_request) Failing after 34m6s
372050d9ed
PR #193 (issue #189) corrected ToolAgent._is_global_unsafe to AND the
host-propagated _unsafe_mode context flag with the ToolAgent's own
safe_mode field, instead of OR-ing them. That fix only reached a
directly constructed ToolAgent, though. LLMAgent's tool-call dispatch
(_execute_tool_loop's three dispatch sites) derived a single shared
parent_unsafe boolean via _resolve_parent_unsafe -- true when either
this agent's own safe_mode: false OR the invocation context already
carried _unsafe_mode: true -- and fed that SAME value into both the
ephemeral ToolAgent's own safe_mode and its context's _unsafe_mode.
Because both AND operands were forced identical before
_is_global_unsafe ever saw them, the ephemeral-dispatch path kept
evaluating to the pre-#193 OR semantics: an LLM agent author's own
safe_mode: false alone could still unlock a loaded skill's privileged
operations (script execution, non-standard-folder access) with no
host ever placed in unsafe mode.

Replaces _resolve_parent_unsafe with two independent resolvers --
_resolve_own_unsafe_opt_out (this agent's own safe_mode config field)
and _resolve_host_unsafe_signal (the context's genuine
host-propagated _unsafe_mode) -- threaded separately through all three
_execute_tool_loop dispatch sites so _build_ephemeral_tool_config only
ever sees the agent's own opt-out and _build_tool_context only ever
sees the host signal, matching docs/index.md §4.4.8 and ADR-2034 D-9
(corrected 2026-11-25).

Removes @tdd_expected_fail from the issue #194 regression scenario,
now passing for the right reason. Updates the pre-existing issue #115
Behave scenario and the agent_skills.robot script-execution
integration test, both of which previously relied on the agent's own
safe_mode: false alone to also open the ephemeral context's
_unsafe_mode -- they now configure a genuine host-unsafe invocation
context explicitly alongside the agent's own safe_mode: false, via a
new host-unsafe When-step and a new host_unsafe Robot keyword
argument, respectively.

ISSUES CLOSED: #195
hurui200320 requested changes 2026-11-30 14:13:30 +00:00
Dismissed
hurui200320 left a comment

PR Review: !198 (Ticket #195)

Verdict: Request Changes

The core fix is correct, minimal, and fully verified locally: the two D-9 "global safety" legs are now resolved independently (_resolve_own_unsafe_opt_out / _resolve_host_unsafe_signal), threaded consistently through all three _execute_tool_loop dispatch sites, and the production host wiring (runtime_dispatch.py) forwards _unsafe_mode only from the host — exactly matching docs/index.md §4.4.8 and ADR-2034 D-9. The consequence for §4.5.4 file_write (own safe_mode: false no longer forges the host flag) also aligns the LLM path with the direct-ToolAgent path and §10.3's "Set By: Host environment". Every gate I ran locally is green on the exact head. One major issue blocks approval: the ticket's own test subtask requires a three-scenario Behave matrix on the real LLM dispatch path, and the host-unsafe-only-refused leg is missing entirely — leaving a realistic privilege-granting regression undetectable by the suite (analysis below).

Critical Issues

None

Major Issues

  1. Missing Behave scenario: host-unsafe-only must be refused on the LLM tool-dispatch path. Ticket #195's test subtask explicitly requires three scenarios "on the real LLM-agent tool-dispatch path (own-safe_mode-only refused, host-unsafe-only refused, both-true opens the gate), mirroring the #189 regression shape." Only the first exists (features/llm_agent_tool_loop.feature:217, "…own safe_mode is false but whose host was never placed in unsafe mode"). The host-unsafe-only combination — agent's own safe_mode at its default true, a genuine host-unsafe invocation context, a safe_mode: false skill — is asserted nowhere on this path: features/runtime_unsafe_host_mode.feature probes only the §4.5.4 file_write gate, features/agent_skills.feature:816 covers the direct-ToolAgent path, and the Robot suite's only unsafe-host test opens the gate (robot/agent_skills.robot:158, host_unsafe=True). I verified why this gap matters: it is the only test pinning the config-derivation leg's independence. If _build_ephemeral_tool_config ever regressed to receiving own_unsafe_opt_out or host_unsafe (a re-collapse), the existing own-only scenario still passes (with no host signal the context gate stays closed regardless of the ephemeral safe_mode), the Robot both-true test also passes, and the suite ships green while a host-unsafe context alone unlocks the skill gate for agents whose author never opted out — violating D-9's "either alone is insufficient". Recommendation: add one scenario mirroring agent_skills.feature:816's #189 shape on the LLM path — reuse the loaded-skill Given step without safe_mode: false, run with the new host-unsafe When-step, and assert refusal "global safety is true" + "skill safety is false".

Minor Issues

  1. CHANGELOG entry omits the user-visible §4.5.4 file_write consequence (CHANGELOG.md:12). The fix also changes behavior beyond the skill gate: an LLM agent with its own safe_mode: false on a safe host can no longer perform a model-issued file_write (the ephemeral context's _unsafe_mode is now host-only). That is spec-correct (§4.5.4 "file_write still requires _unsafe_mode: true"; §10.3 "Set By: Host environment") and matches the direct-ToolAgent path — the PR itself had to update the issue #115 scenario (features/llm_agent_tool_loop.feature:190, retitled and given the host-unsafe step) to prove it — but the entry's parenthetical enumerates only "(script execution, non-standard folders)". Recommend one clause noting file_write now requires a genuine host-unsafe signal regardless of the agent's own safe_mode, so downstream users relying on the pre-#195 #115-era behavior are not surprised.

Nits

  1. The ticket's third requested Behave scenario ("both-true opens the gate" for the D-9 skill gate on the LLM path) is delivered only at Robot integration level (agent_skills.robot "Bundled Script Executes End To End Behind The Double Safety Gate" with host_unsafe=True) plus the both-true file_write Behave scenario. The end-to-end Robot test does catch over-tightening, so this is acceptable; adding the Behave sibling while adding the Major scenario above would complete the #189-style matrix cheaply.

Scope notes

  • PR !198 has no prior reviews and no author responses yet. The two scope exclusions recorded during !193's review — the LLMAgent → ephemeral ToolAgent dispatch path, and the Robot-integration extension — deferred exactly this work to issue #195, so both are in scope here and were reviewed; nothing was excluded from this review as out-of-scope.

Verified locally (authoritative, on head 372050d)

  • nox -s unit_tests-3.13: 3373/3373 scenarios, 15535/15535 steps, 0 failed — matches the PR's reported run. Focused subset (agent_skills.feature + llm_agent_tool_loop.feature): 197/197.
  • nox -s coverage_report: 97.3% (threshold 96.5%) — COVERAGE OK; every line in the changed region (src/cleveractors/agents/llm.py 940–1060) is covered.
  • nox -s lint: pass. nox -s typecheck: 0 errors (1 pre-existing optional-import warning, unrelated). nox -s integration_tests-3.13: pass. nox -s dead_code + nox -s security_scan: pass.
  • Code audit: all three dispatch sites (llm.py ~1252, ~1411, ~1580) resolve and thread both signals consistently with no variable shadowing; _build_tool_context/_build_ephemeral_tool_config have no other call sites; ToolAgent._is_global_unsafe and direct construction are untouched; production _unsafe_mode producers remain host-only (runtime_dispatch.py:155/377/859/1216, application.py); no stale @tdd_expected_fail tags remain anywhere in features/.
  • Commit hygiene (non-blocking): first line matches the ticket Metadata Commit Message exactly, branch name matches Metadata, single linear commit based on the current develop tip, no merge commits; CHANGELOG entry correctly placed under Unreleased → Changed.

Summary

A precise, well-scoped security fix with strong test discipline: the two D-9 legs are now genuinely independent on the ephemeral-dispatch path, all three call sites are consistent, the spec citations are accurate, and every locally runnable gate is green on the exact head. The single blocking item is the missing host-unsafe-only-refused Behave scenario — one small scenario mirroring the #189 regression shape closes it and completes the ticket's own acceptance matrix. Add that scenario (plus the CHANGELOG clause), and this is ready to approve.

## PR Review: !198 (Ticket #195) ### Verdict: Request Changes The core fix is correct, minimal, and fully verified locally: the two D-9 "global safety" legs are now resolved independently (`_resolve_own_unsafe_opt_out` / `_resolve_host_unsafe_signal`), threaded consistently through all three `_execute_tool_loop` dispatch sites, and the production host wiring (`runtime_dispatch.py`) forwards `_unsafe_mode` only from the host — exactly matching `docs/index.md` §4.4.8 and ADR-2034 D-9. The consequence for §4.5.4 `file_write` (own `safe_mode: false` no longer forges the host flag) also aligns the LLM path with the direct-ToolAgent path and §10.3's "Set By: Host environment". Every gate I ran locally is green on the exact head. One major issue blocks approval: the ticket's own test subtask requires a three-scenario Behave matrix on the real LLM dispatch path, and the **host-unsafe-only-refused** leg is missing entirely — leaving a realistic privilege-granting regression undetectable by the suite (analysis below). ### Critical Issues None ### Major Issues 1. **Missing Behave scenario: host-unsafe-only must be refused on the LLM tool-dispatch path.** Ticket #195's test subtask explicitly requires three scenarios "on the real LLM-agent tool-dispatch path (own-safe_mode-only refused, host-unsafe-only refused, both-true opens the gate), mirroring the #189 regression shape." Only the first exists (`features/llm_agent_tool_loop.feature:217`, "…own safe_mode is false but whose host was never placed in unsafe mode"). The host-unsafe-only combination — agent's own `safe_mode` at its default `true`, a genuine host-unsafe invocation context, a `safe_mode: false` skill — is asserted nowhere on this path: `features/runtime_unsafe_host_mode.feature` probes only the §4.5.4 `file_write` gate, `features/agent_skills.feature:816` covers the direct-ToolAgent path, and the Robot suite's only unsafe-host test opens the gate (`robot/agent_skills.robot:158`, `host_unsafe=True`). I verified why this gap matters: it is the only test pinning the config-derivation leg's independence. If `_build_ephemeral_tool_config` ever regressed to receiving `own_unsafe_opt_out or host_unsafe` (a re-collapse), the existing own-only scenario **still passes** (with no host signal the context gate stays closed regardless of the ephemeral `safe_mode`), the Robot both-true test also passes, and the suite ships green while a host-unsafe context alone unlocks the skill gate for agents whose author never opted out — violating D-9's "either alone is insufficient". **Recommendation:** add one scenario mirroring `agent_skills.feature:816`'s #189 shape on the LLM path — reuse the loaded-skill Given step without `safe_mode: false`, run with the new host-unsafe When-step, and assert refusal `"global safety is true"` + `"skill safety is false"`. ### Minor Issues 1. **CHANGELOG entry omits the user-visible §4.5.4 `file_write` consequence** (`CHANGELOG.md:12`). The fix also changes behavior beyond the skill gate: an LLM agent with its own `safe_mode: false` on a safe host can no longer perform a model-issued `file_write` (the ephemeral context's `_unsafe_mode` is now host-only). That is spec-correct (§4.5.4 "file_write still requires `_unsafe_mode: true`"; §10.3 "Set By: Host environment") and matches the direct-ToolAgent path — the PR itself had to update the issue #115 scenario (`features/llm_agent_tool_loop.feature:190`, retitled and given the host-unsafe step) to prove it — but the entry's parenthetical enumerates only "(script execution, non-standard folders)". Recommend one clause noting `file_write` now requires a genuine host-unsafe signal regardless of the agent's own `safe_mode`, so downstream users relying on the pre-#195 #115-era behavior are not surprised. ### Nits 1. The ticket's third requested Behave scenario ("both-true opens the gate" for the D-9 skill gate on the LLM path) is delivered only at Robot integration level (`agent_skills.robot` "Bundled Script Executes End To End Behind The Double Safety Gate" with `host_unsafe=True`) plus the both-true `file_write` Behave scenario. The end-to-end Robot test does catch over-tightening, so this is acceptable; adding the Behave sibling while adding the Major scenario above would complete the #189-style matrix cheaply. ### Scope notes - PR !198 has no prior reviews and no author responses yet. The two scope exclusions recorded during !193's review — the LLMAgent → ephemeral `ToolAgent` dispatch path, and the Robot-integration extension — deferred exactly this work to issue #195, so both are in scope here and were reviewed; nothing was excluded from this review as out-of-scope. ### Verified locally (authoritative, on head `372050d`) - `nox -s unit_tests-3.13`: **3373/3373 scenarios, 15535/15535 steps, 0 failed** — matches the PR's reported run. Focused subset (`agent_skills.feature` + `llm_agent_tool_loop.feature`): 197/197. - `nox -s coverage_report`: **97.3% (threshold 96.5%) — COVERAGE OK**; every line in the changed region (`src/cleveractors/agents/llm.py` 940–1060) is covered. - `nox -s lint`: pass. `nox -s typecheck`: 0 errors (1 pre-existing optional-import warning, unrelated). `nox -s integration_tests-3.13`: pass. `nox -s dead_code` + `nox -s security_scan`: pass. - Code audit: all three dispatch sites (`llm.py` ~1252, ~1411, ~1580) resolve and thread both signals consistently with no variable shadowing; `_build_tool_context`/`_build_ephemeral_tool_config` have no other call sites; `ToolAgent._is_global_unsafe` and direct construction are untouched; production `_unsafe_mode` producers remain host-only (`runtime_dispatch.py:155/377/859/1216`, `application.py`); no stale `@tdd_expected_fail` tags remain anywhere in `features/`. - Commit hygiene (non-blocking): first line matches the ticket Metadata `Commit Message` exactly, branch name matches Metadata, single linear commit based on the current `develop` tip, no merge commits; CHANGELOG entry correctly placed under Unreleased → Changed. ### Summary A precise, well-scoped security fix with strong test discipline: the two D-9 legs are now genuinely independent on the ephemeral-dispatch path, all three call sites are consistent, the spec citations are accurate, and every locally runnable gate is green on the exact head. The single blocking item is the missing host-unsafe-only-refused Behave scenario — one small scenario mirroring the #189 regression shape closes it and completes the ticket's own acceptance matrix. Add that scenario (plus the CHANGELOG clause), and this is ready to approve.
CoreRasurae force-pushed bugfix/m1-llm-tool-dispatch-shared-unsafe-signal from 372050d9ed
Some checks failed
CI / lint (pull_request) Successful in 1m34s
CI / typecheck (pull_request) Successful in 2m11s
CI / security (pull_request) Successful in 59s
CI / build (pull_request) Successful in 1m43s
CI / quality (pull_request) Successful in 2m20s
CI / integration_tests (pull_request) Successful in 3m0s
CI / unit_tests (pull_request) Successful in 7m31s
CI / coverage (pull_request) Successful in 6m49s
CI / status-check (pull_request) Successful in 1s
CI / benchmark (pull_request) Failing after 34m6s
to 9cfd1cf789
Some checks failed
CI / lint (pull_request) Successful in 1m22s
CI / typecheck (pull_request) Successful in 2m2s
CI / quality (pull_request) Successful in 1m49s
CI / security (pull_request) Successful in 2m18s
CI / build (pull_request) Successful in 2m41s
CI / integration_tests (pull_request) Successful in 5m29s
CI / unit_tests (pull_request) Successful in 6m50s
CI / coverage (pull_request) Failing after 17m10s
CI / benchmark (pull_request) Failing after 28m43s
CI / status-check (pull_request) Failing after 2s
2026-11-30 16:00:25 +00:00
Compare
Author
Member

Thanks for the thorough review, @hurui200320 — all addressed on head 9cfd1cf (amended, force-pushed; single commit, same feature):

Major — missing host-unsafe-only-refused scenario: Confirmed against the ticket's own Subtasks text and the #189 precedent (agent_skills.feature:816-832). Added A non-standard skill resource read is refused for an LLM agent on a genuinely unsafe host whose own safe_mode is still true (#195) (@tdd_issue @tdd_issue_195) to features/llm_agent_tool_loop.feature, backed by a new an LLMAgent with default safe_mode and a loaded skill ... Given step in features/steps/llm_agent_tool_loop_steps.py. This now pins the config-derivation leg's independence exactly as you described — a regression to own_unsafe_opt_out or host_unsafe would fail it.

Nit — both-true Behave sibling for the skill gate: Added too (A non-standard skill resource read succeeds for an LLM agent when both safety switches are false), completing the three-scenario matrix at Behave level on the real LLM-dispatch path, mirroring agent_skills.feature:816-832 exactly.

Minor — CHANGELOG omits the file_write consequence: Updated the entry to name it explicitly alongside the skill gate.

Verified locally on the new head: nox -s unit_tests -- features/llm_agent_tool_loop.feature — 39/39 scenarios (37 existing + 2 new), 0 failed. nox -s lint / nox -s format -- --check — green. Coverage delta checked via nox -s coverage_report -- features/llm_agent_tool_loop.feature: every line in the changed region (llm.py 938-1074, all three dispatch sites) is covered by this feature file alone; the full-suite baseline (97.3%, unaffected since no src/ lines changed this round) still applies. nox -s integration_tests/security_scan/dead_code/typecheck unaffected (no src//robot/ changes this round) — prior green results on record still hold.

Re-requesting your review.

Thanks for the thorough review, @hurui200320 — all addressed on head `9cfd1cf` (amended, force-pushed; single commit, same feature): **Major — missing host-unsafe-only-refused scenario:** Confirmed against the ticket's own Subtasks text and the #189 precedent (`agent_skills.feature:816-832`). Added `A non-standard skill resource read is refused for an LLM agent on a genuinely unsafe host whose own safe_mode is still true (#195)` (`@tdd_issue @tdd_issue_195`) to `features/llm_agent_tool_loop.feature`, backed by a new `an LLMAgent with default safe_mode and a loaded skill ...` Given step in `features/steps/llm_agent_tool_loop_steps.py`. This now pins the config-derivation leg's independence exactly as you described — a regression to `own_unsafe_opt_out or host_unsafe` would fail it. **Nit — both-true Behave sibling for the skill gate:** Added too (`A non-standard skill resource read succeeds for an LLM agent when both safety switches are false`), completing the three-scenario matrix at Behave level on the real LLM-dispatch path, mirroring `agent_skills.feature:816-832` exactly. **Minor — CHANGELOG omits the file_write consequence:** Updated the entry to name it explicitly alongside the skill gate. Verified locally on the new head: `nox -s unit_tests -- features/llm_agent_tool_loop.feature` — 39/39 scenarios (37 existing + 2 new), 0 failed. `nox -s lint` / `nox -s format -- --check` — green. Coverage delta checked via `nox -s coverage_report -- features/llm_agent_tool_loop.feature`: every line in the changed region (`llm.py` 938-1074, all three dispatch sites) is covered by this feature file alone; the full-suite baseline (97.3%, unaffected since no `src/` lines changed this round) still applies. `nox -s integration_tests`/`security_scan`/`dead_code`/`typecheck` unaffected (no `src/`/`robot/` changes this round) — prior green results on record still hold. Re-requesting your review.
hurui200320 left a comment

PR Review: !198 (Ticket #195)

Verdict: Approve

Re-review of the amended head 9cfd1cf (single commit, force-pushed). All three items from the prior review round are resolved and verified on the actual head, the author's response claims check out against local runs, and the only remaining findings are one stale test-file comment (non-blocking) and two cosmetic nits. The core fix is correct, minimal, spec-exact, and now guarded by a complete three-scenario regression matrix that pins both re-collapse directions.

Critical Issues

None

Major Issues

None

Minor Issues

  1. Stale normative comment block above the issue-#115 scenario — features/llm_agent_tool_loop.feature:170-179. The header (lines 170-171) still asserts the collapsed-signal semantics that issue #195 removed: "safe_mode: false must reach the ephemeral ToolAgent's _unsafe_mode context so a model-issued file_write call can succeed". The middle paragraph (lines 175-179) still describes the pre-#115 code as current — "dispatch sites ... read the dead unsafe_mode config key ... so file_write is unconditionally blocked" — while the corrected code reads _unsafe_mode from the invocation context via _resolve_host_unsafe_signal, and the scenario below passes precisely because a host-unsafe context is supplied. This contradicts docs/index.md §4.5.4 ("file_write still requires _unsafe_mode: true", Set By: Host environment, §10.3) and the corrected scenario directly beneath it. The "Updated by issue #195" paragraph (line 181) mitigates, but the header's MUST statement is now wrong. Recommendation: rewrite lines 170-179 to the post-#195 semantics (e.g., "Bug #115: a model-issued file_write from an LLM agent requires the genuine host-propagated _unsafe_mode in the invocation context; the agent's own safe_mode: false alone is insufficient (issue #195)"). Non-blocking.

Nits

  1. features/llm_agent_tool_loop.feature:233 — the both-true success scenario lacks the @tdd_issue @tdd_issue_195 tags its two sibling refusal scenarios carry (lines 216, 225). Untagged scenarios are common in this file, but tagging would keep the #195 matrix's issue linkage consistent. Purely cosmetic.
  2. PR description staleness: the body's "Changes"/"Test plan" sections describe the pre-amend head (3373 scenarios; no mention of the two new Behave scenarios). The commit message and the author's thread comment document them accurately, so this is a cosmetic refresh at most.

Prior review round — resolution verified (author response of 2026-11-30)

  1. Major (missing host-unsafe-only-refused Behave scenario): RESOLVED. features/llm_agent_tool_loop.feature:225-232 adds "A non-standard skill resource read is refused for an LLM agent on a genuinely unsafe host whose own safe_mode is still true (#195)", backed by the new default-safe_mode Given step (features/steps/llm_agent_tool_loop_steps.py:206-236). I verified the pin by derivation: under a re-collapse to own_unsafe_opt_out or host_unsafe, the ephemeral agent would receive safe_mode=false and context _unsafe_mode=true, the gate would open, and the refusal assertions ("global safety is true") would fail — so the collapse is now caught. Own-only (line 216) pins the other direction; both-true (line 234) pins over-tightening. The three-scenario matrix mirrors agent_skills.feature:816-832's #189 shape exactly, as the ticket's test subtask requires.
  2. Nit (both-true Behave sibling): RESOLVED — features/llm_agent_tool_loop.feature:234-240, completing the matrix at Behave level on the real LLM dispatch path.
  3. Minor (CHANGELOG omits file_write consequence): RESOLVED — CHANGELOG.md:12 now names "or let a model-issued file_write through" alongside the skill gate, matching §4.5.4/§10.3.

No item was declined or re-deferred in the thread; nothing needed removing from this review on out-of-scope grounds. The two items scoped out during !193 (LLMAgent ephemeral-dispatch path; Robot-integration extension) were deferred to ticket #195 and are delivered here. Red-tape items excluded per review instructions (the commit footer ISSUES CLOSED: #195 is present anyway).

Verified locally (authoritative, on exact head 9cfd1cf)

  • nox -s lint: pass. nox -s format -- --check: pass (298 files). nox -s typecheck: 0 errors (1 pre-existing optional-import warning, unrelated).
  • nox -s unit_tests (full): 3375/3375 scenarios, 15546/15546 steps, 0 failed (3373 prior + the 2 new scenarios — consistent with the author's 39/39 focused run, which I reproduced).
  • nox -s coverage_report: 97.3% (threshold 96.5%) — COVERAGE OK, ≥ the 97% standard.
  • nox -s integration_tests (full): 382 passed, 0 failed — matches the PR's claim; the modified Process Message With Agent keyword's other call sites (default host_unsafe=False) all still pass.
  • nox -s dead_code, nox -s security_scan: pass.
  • Code audit: exactly three ephemeral ToolAgent construction sites (llm.py:1260, 1426, 1585), each pairing _build_ephemeral_tool_config(own_unsafe_opt_out) with _build_tool_context(host_unsafe) and resolving the two signals independently; no stale _resolve_parent_unsafe references anywhere; ToolAgent._is_global_unsafe and direct construction untouched; production _unsafe_mode producers remain host-only (runtime_dispatch.py comment-only changes); no stale @tdd_expected_fail tags; process_message/stream_message/_execute_tool_loop context threading verified end to end.

Summary

A precise, well-scoped security fix, now complete: the two D-9 "global safety" legs are resolved independently on the ephemeral-dispatch path, all three dispatch sites are consistent, the spec citations are accurate, and the Behave regression matrix pins the AND composition in both refusal directions plus the conjunction — the exact gap that blocked the previous round. Every locally runnable gate is green on the exact head. One stale comment block (Minor) and two cosmetic nits remain; none block approval. Ready to merge.

## PR Review: !198 (Ticket #195) ### Verdict: Approve Re-review of the amended head `9cfd1cf` (single commit, force-pushed). All three items from the prior review round are resolved and verified on the actual head, the author's response claims check out against local runs, and the only remaining findings are one stale test-file comment (non-blocking) and two cosmetic nits. The core fix is correct, minimal, spec-exact, and now guarded by a complete three-scenario regression matrix that pins both re-collapse directions. ### Critical Issues None ### Major Issues None ### Minor Issues 1. **Stale normative comment block above the issue-#115 scenario** — `features/llm_agent_tool_loop.feature:170-179`. The header (lines 170-171) still asserts the collapsed-signal semantics that issue #195 removed: "safe_mode: false must reach the ephemeral ToolAgent's `_unsafe_mode` context so a model-issued file_write call can succeed". The middle paragraph (lines 175-179) still describes the pre-#115 code as current — "dispatch sites ... read the dead `unsafe_mode` config key ... so file_write is unconditionally blocked" — while the corrected code reads `_unsafe_mode` from the invocation context via `_resolve_host_unsafe_signal`, and the scenario below passes precisely because a host-unsafe context is supplied. This contradicts `docs/index.md` §4.5.4 ("file_write still requires `_unsafe_mode: true`", Set By: Host environment, §10.3) and the corrected scenario directly beneath it. The "Updated by issue #195" paragraph (line 181) mitigates, but the header's MUST statement is now wrong. **Recommendation:** rewrite lines 170-179 to the post-#195 semantics (e.g., "Bug #115: a model-issued file_write from an LLM agent requires the genuine host-propagated `_unsafe_mode` in the invocation context; the agent's own `safe_mode: false` alone is insufficient (issue #195)"). Non-blocking. ### Nits 1. `features/llm_agent_tool_loop.feature:233` — the both-true success scenario lacks the `@tdd_issue @tdd_issue_195` tags its two sibling refusal scenarios carry (lines 216, 225). Untagged scenarios are common in this file, but tagging would keep the #195 matrix's issue linkage consistent. Purely cosmetic. 2. PR description staleness: the body's "Changes"/"Test plan" sections describe the pre-amend head (3373 scenarios; no mention of the two new Behave scenarios). The commit message and the author's thread comment document them accurately, so this is a cosmetic refresh at most. ### Prior review round — resolution verified (author response of 2026-11-30) 1. **Major (missing host-unsafe-only-refused Behave scenario): RESOLVED.** `features/llm_agent_tool_loop.feature:225-232` adds "A non-standard skill resource read is refused for an LLM agent on a genuinely unsafe host whose own safe_mode is still true (#195)", backed by the new default-safe_mode Given step (`features/steps/llm_agent_tool_loop_steps.py:206-236`). I verified the pin by derivation: under a re-collapse to `own_unsafe_opt_out or host_unsafe`, the ephemeral agent would receive `safe_mode=false` **and** context `_unsafe_mode=true`, the gate would open, and the refusal assertions ("global safety is true") would fail — so the collapse is now caught. Own-only (line 216) pins the other direction; both-true (line 234) pins over-tightening. The three-scenario matrix mirrors `agent_skills.feature:816-832`'s #189 shape exactly, as the ticket's test subtask requires. 2. **Nit (both-true Behave sibling): RESOLVED** — `features/llm_agent_tool_loop.feature:234-240`, completing the matrix at Behave level on the real LLM dispatch path. 3. **Minor (CHANGELOG omits `file_write` consequence): RESOLVED** — `CHANGELOG.md:12` now names "or let a model-issued `file_write` through" alongside the skill gate, matching §4.5.4/§10.3. No item was declined or re-deferred in the thread; nothing needed removing from this review on out-of-scope grounds. The two items scoped out during !193 (LLMAgent ephemeral-dispatch path; Robot-integration extension) were deferred *to* ticket #195 and are delivered here. Red-tape items excluded per review instructions (the commit footer `ISSUES CLOSED: #195` is present anyway). ### Verified locally (authoritative, on exact head `9cfd1cf`) - `nox -s lint`: pass. `nox -s format -- --check`: pass (298 files). `nox -s typecheck`: 0 errors (1 pre-existing optional-import warning, unrelated). - `nox -s unit_tests` (full): **3375/3375 scenarios, 15546/15546 steps, 0 failed** (3373 prior + the 2 new scenarios — consistent with the author's 39/39 focused run, which I reproduced). - `nox -s coverage_report`: **97.3% (threshold 96.5%) — COVERAGE OK**, ≥ the 97% standard. - `nox -s integration_tests` (full): **382 passed, 0 failed** — matches the PR's claim; the modified `Process Message With Agent` keyword's other call sites (default `host_unsafe=False`) all still pass. - `nox -s dead_code`, `nox -s security_scan`: pass. - Code audit: exactly three ephemeral `ToolAgent` construction sites (`llm.py:1260, 1426, 1585`), each pairing `_build_ephemeral_tool_config(own_unsafe_opt_out)` with `_build_tool_context(host_unsafe)` and resolving the two signals independently; no stale `_resolve_parent_unsafe` references anywhere; `ToolAgent._is_global_unsafe` and direct construction untouched; production `_unsafe_mode` producers remain host-only (`runtime_dispatch.py` comment-only changes); no stale `@tdd_expected_fail` tags; `process_message`/`stream_message`/`_execute_tool_loop` context threading verified end to end. ### Summary A precise, well-scoped security fix, now complete: the two D-9 "global safety" legs are resolved independently on the ephemeral-dispatch path, all three dispatch sites are consistent, the spec citations are accurate, and the Behave regression matrix pins the AND composition in both refusal directions plus the conjunction — the exact gap that blocked the previous round. Every locally runnable gate is green on the exact head. One stale comment block (Minor) and two cosmetic nits remain; none block approval. Ready to merge.
CoreRasurae force-pushed bugfix/m1-llm-tool-dispatch-shared-unsafe-signal from 9cfd1cf789
Some checks failed
CI / lint (pull_request) Successful in 1m22s
CI / typecheck (pull_request) Successful in 2m2s
CI / quality (pull_request) Successful in 1m49s
CI / security (pull_request) Successful in 2m18s
CI / build (pull_request) Successful in 2m41s
CI / integration_tests (pull_request) Successful in 5m29s
CI / unit_tests (pull_request) Successful in 6m50s
CI / coverage (pull_request) Failing after 17m10s
CI / benchmark (pull_request) Failing after 28m43s
CI / status-check (pull_request) Failing after 2s
to de925046d1
Some checks failed
CI / lint (pull_request) Successful in 1m11s
CI / typecheck (pull_request) Successful in 1m48s
CI / security (pull_request) Successful in 1m4s
CI / build (pull_request) Successful in 1m50s
CI / quality (pull_request) Successful in 1m56s
CI / integration_tests (pull_request) Successful in 4m16s
CI / benchmark (pull_request) Failing after 30m23s
CI / unit_tests (pull_request) Successful in 6m2s
CI / coverage (pull_request) Successful in 6m21s
CI / status-check (pull_request) Successful in 2s
CI / lint (push) Successful in 1m18s
CI / typecheck (push) Successful in 1m49s
CI / build (push) Successful in 1m14s
CI / quality (push) Successful in 1m48s
CI / security (push) Successful in 2m11s
CI / integration_tests (push) Successful in 3m42s
CI / unit_tests (push) Successful in 7m2s
CI / coverage (push) Failing after 19m50s
CI / benchmark (push) Failing after 26m54s
CI / status-check (push) Has been cancelled
2026-12-01 18:53:34 +00:00
Compare
Author
Member

Thanks for the re-review, @hurui200320 — addressed on head de92504 (amended, force-pushed; still a single commit, same feature):

Minor (stale issue #115 comment block): FIXED. Verified against docs/index.md §4.5.4/§10.3 (_unsafe_mode is "Set By: Host environment", required for file_write) before touching anything. Rewrote features/llm_agent_tool_loop.feature:170-186 so the header states the correct, current requirement (host-propagated _unsafe_mode; own safe_mode: false alone is insufficient) and the history paragraph accurately separates issue #115 (fixed the dead unsafe_mode config key) from issue #195 (corrected #115's own fix, which had re-coupled the two signals).

Nit 1 (tag the both-true success scenario @tdd_issue/@tdd_issue_195): intentionally not applied. Checked this against the @tdd_issue_N tag's own definition (links a test to the specific bug it captures -- i.e. a regression guard) and against the precedent this ticket is explicitly asked to mirror: agent_skills.feature's analogous #189 success scenario ("A non-standard read succeeds when both safety switches are false") is likewise left untagged, by design -- it's a correctness/happy-path check, not a bug-capturing regression test. Tagging the success sibling would be inconsistent with that established convention and with the tag's defined purpose, for a purely cosmetic gain you yourself flagged as optional. Happy to add it if you feel otherwise, but I'd rather not diverge from the #189 pattern without a stronger reason.

Nit 2 (PR description staleness): FIXED. Updated the Summary/Changes/Test plan to reflect the current head (3375 scenarios, the completed three-scenario matrix, the rewritten comment block).

No further code changes this round beyond the comment rewrite -- re-ran only the targeted nox -s unit_tests -- features/llm_agent_tool_loop.feature (39/39, unchanged) since nothing in src//robot/ moved; your full-suite numbers from the previous round still apply.

Re-requesting review since the force-push marked your approval stale.

Thanks for the re-review, @hurui200320 — addressed on head `de92504` (amended, force-pushed; still a single commit, same feature): **Minor (stale issue #115 comment block): FIXED.** Verified against `docs/index.md` §4.5.4/§10.3 (`_unsafe_mode` is "Set By: Host environment", required for `file_write`) before touching anything. Rewrote `features/llm_agent_tool_loop.feature:170-186` so the header states the correct, current requirement (host-propagated `_unsafe_mode`; own `safe_mode: false` alone is insufficient) and the history paragraph accurately separates issue #115 (fixed the dead `unsafe_mode` config key) from issue #195 (corrected #115's own fix, which had re-coupled the two signals). **Nit 1 (tag the both-true success scenario `@tdd_issue`/`@tdd_issue_195`): intentionally not applied.** Checked this against the `@tdd_issue_N` tag's own definition (links a test to the specific bug it *captures* -- i.e. a regression guard) and against the precedent this ticket is explicitly asked to mirror: `agent_skills.feature`'s analogous #189 success scenario ("A non-standard read succeeds when both safety switches are false") is likewise left untagged, by design -- it's a correctness/happy-path check, not a bug-capturing regression test. Tagging the success sibling would be inconsistent with that established convention and with the tag's defined purpose, for a purely cosmetic gain you yourself flagged as optional. Happy to add it if you feel otherwise, but I'd rather not diverge from the #189 pattern without a stronger reason. **Nit 2 (PR description staleness): FIXED.** Updated the Summary/Changes/Test plan to reflect the current head (3375 scenarios, the completed three-scenario matrix, the rewritten comment block). No further code changes this round beyond the comment rewrite -- re-ran only the targeted `nox -s unit_tests -- features/llm_agent_tool_loop.feature` (39/39, unchanged) since nothing in `src/`/`robot/` moved; your full-suite numbers from the previous round still apply. Re-requesting review since the force-push marked your approval stale.
CoreRasurae deleted branch bugfix/m1-llm-tool-dispatch-shared-unsafe-signal 2026-12-01 19:47:08 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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!198
No description provided.