fix(agents): derive the ephemeral ToolAgent's own safe_mode and the host's _unsafe_mode independently in LLMAgent tool dispatch #198
No reviewers
Labels
No labels
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Bounty
$100
Bounty
$1000
Bounty
$10000
Bounty
$20
Bounty
$2000
Bounty
$250
Bounty
$50
Bounty
$500
Bounty
$5000
Bounty
$750
MoSCoW
Could have
MoSCoW
Must have
MoSCoW
Should have
Needs Feedback
Points
1
Points
13
Points
2
Points
21
Points
3
Points
34
Points
5
Points
55
Points
8
Points
88
Priority
Backlog
Priority
CI Blocker
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
State
Completed
State
Duplicate
State
In Progress
State
In Review
State
Paused
State
Unverified
State
Verified
State
Wont Do
Type
Automation
Type
Bug
Type
Discussion
Type
Documentation
Type
Epic
Type
Feature
Type
Legendary
Type
Refactor
Type
Support
Type
Task
Type
Testing
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Blocks
Reference
cleveragents/cleveractors-core!198
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "bugfix/m1-llm-tool-dispatch-shared-unsafe-signal"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes issue #195:
LLMAgent._execute_tool_loop()'s three ephemeral-ToolAgentdispatch sites derived a single sharedparent_unsafeboolean (_resolve_parent_unsafe) -- true when EITHER this agent's ownsafe_mode: falseOR the invocation context's_unsafe_mode: true-- and fed that same value into both the ephemeral agent's ownsafe_modeand its context's_unsafe_mode. Because both operands ofToolAgent._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 ownsafe_mode: falsealone could still unlock a loaded skill's privileged operations, or a model-issuedfile_write, with no host ever placed in unsafe mode._resolve_parent_unsafeis replaced with two independent resolvers:_resolve_own_unsafe_opt_out()-- this agent's ownsafe_modeconfig field only._resolve_host_unsafe_signal(context)-- the invocation context's genuine host-propagated_unsafe_modeonly.Both are threaded independently through all three
_execute_tool_loopdispatch sites (budget-retry, primary, stuck-model-retry mirrors), so_build_ephemeral_tool_configonly ever sees the agent's own opt-out and_build_tool_contextonly ever sees the host signal -- matchingdocs/index.md§4.4.8/§4.5.4/§10.3 anddocs/adr/ADR-2034-skill-package-support.mdD-9 (corrected 2026-11-25).Changes
src/cleveractors/agents/llm.py: split_resolve_parent_unsafeinto_resolve_own_unsafe_opt_out/_resolve_host_unsafe_signal; updated_build_ephemeral_tool_config/_build_tool_contextsignatures 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_failfrom the issue #194 regression scenario (now passes for the right reason); added ahost-unsafe invocation contextWhen-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 ownsafe_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), mirroringagent_skills.feature:816-832's #189 shape.robot/SkillLoadingTestLib.py/robot/agent_skills.robot: added ahost_unsafekeyword argument toProcess Message With Agent; updated theBundled Script Executes End To End Behind The Double Safety Gateintegration test to configure both D-9 conditions explicitly.CHANGELOG.md: one### Changedentry covering the skill-gate andfile_writeconsequences.Test plan
nox -s lint/nox -s format -- --check-- greennox -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 coverednox -s security_scan-- 0 findingsnox -s dead_code-- cleannox -s integration_tests-- 382/382 passed@tdd_issue_195regression matrix (own-only / host-only / both-true) passes without@tdd_expected_failCloses #195
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_loopdispatch sites, and the production host wiring (runtime_dispatch.py) forwards_unsafe_modeonly from the host — exactly matchingdocs/index.md§4.4.8 and ADR-2034 D-9. The consequence for §4.5.4file_write(ownsafe_mode: falseno 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
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 ownsafe_modeat its defaulttrue, a genuine host-unsafe invocation context, asafe_mode: falseskill — is asserted nowhere on this path:features/runtime_unsafe_host_mode.featureprobes only the §4.5.4file_writegate,features/agent_skills.feature:816covers 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_configever regressed to receivingown_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 ephemeralsafe_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 mirroringagent_skills.feature:816's #189 shape on the LLM path — reuse the loaded-skill Given step withoutsafe_mode: false, run with the new host-unsafe When-step, and assert refusal"global safety is true"+"skill safety is false".Minor Issues
file_writeconsequence (CHANGELOG.md:12). The fix also changes behavior beyond the skill gate: an LLM agent with its ownsafe_mode: falseon a safe host can no longer perform a model-issuedfile_write(the ephemeral context's_unsafe_modeis 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 notingfile_writenow requires a genuine host-unsafe signal regardless of the agent's ownsafe_mode, so downstream users relying on the pre-#195 #115-era behavior are not surprised.Nits
agent_skills.robot"Bundled Script Executes End To End Behind The Double Safety Gate" withhost_unsafe=True) plus the both-truefile_writeBehave 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
ToolAgentdispatch 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.py940–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.llm.py~1252, ~1411, ~1580) resolve and thread both signals consistently with no variable shadowing;_build_tool_context/_build_ephemeral_tool_confighave no other call sites;ToolAgent._is_global_unsafeand direct construction are untouched; production_unsafe_modeproducers remain host-only (runtime_dispatch.py:155/377/859/1216,application.py); no stale@tdd_expected_failtags remain anywhere infeatures/.Commit Messageexactly, branch name matches Metadata, single linear commit based on the currentdeveloptip, 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.
372050d9ed9cfd1cf789Thanks 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). AddedA 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) tofeatures/llm_agent_tool_loop.feature, backed by a newan LLMAgent with default safe_mode and a loaded skill ...Given step infeatures/steps/llm_agent_tool_loop_steps.py. This now pins the config-derivation leg's independence exactly as you described — a regression toown_unsafe_opt_out or host_unsafewould 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, mirroringagent_skills.feature:816-832exactly.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 vianox -s coverage_report -- features/llm_agent_tool_loop.feature: every line in the changed region (llm.py938-1074, all three dispatch sites) is covered by this feature file alone; the full-suite baseline (97.3%, unaffected since nosrc/lines changed this round) still applies.nox -s integration_tests/security_scan/dead_code/typecheckunaffected (nosrc//robot/changes this round) — prior green results on record still hold.Re-requesting your review.
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
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_modecontext 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 deadunsafe_modeconfig key ... so file_write is unconditionally blocked" — while the corrected code reads_unsafe_modefrom the invocation context via_resolve_host_unsafe_signal, and the scenario below passes precisely because a host-unsafe context is supplied. This contradictsdocs/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_modein the invocation context; the agent's ownsafe_mode: falsealone is insufficient (issue #195)"). Non-blocking.Nits
features/llm_agent_tool_loop.feature:233— the both-true success scenario lacks the@tdd_issue @tdd_issue_195tags 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.Prior review round — resolution verified (author response of 2026-11-30)
features/llm_agent_tool_loop.feature:225-232adds "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 toown_unsafe_opt_out or host_unsafe, the ephemeral agent would receivesafe_mode=falseand 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 mirrorsagent_skills.feature:816-832's #189 shape exactly, as the ticket's test subtask requires.features/llm_agent_tool_loop.feature:234-240, completing the matrix at Behave level on the real LLM dispatch path.file_writeconsequence): RESOLVED —CHANGELOG.md:12now names "or let a model-issuedfile_writethrough" 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: #195is 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 modifiedProcess Message With Agentkeyword's other call sites (defaulthost_unsafe=False) all still pass.nox -s dead_code,nox -s security_scan: pass.ToolAgentconstruction 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_unsafereferences anywhere;ToolAgent._is_global_unsafeand direct construction untouched; production_unsafe_modeproducers remain host-only (runtime_dispatch.pycomment-only changes); no stale@tdd_expected_failtags;process_message/stream_message/_execute_tool_loopcontext 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.
9cfd1cf789de925046d1Thanks 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_modeis "Set By: Host environment", required forfile_write) before touching anything. Rewrotefeatures/llm_agent_tool_loop.feature:170-186so the header states the correct, current requirement (host-propagated_unsafe_mode; ownsafe_mode: falsealone is insufficient) and the history paragraph accurately separates issue #115 (fixed the deadunsafe_modeconfig 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_Ntag'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 insrc//robot/moved; your full-suite numbers from the previous round still apply.Re-requesting review since the force-push marked your approval stale.