ToolAgent._is_global_unsafe composes host-unsafe-mode and the agent's own safe_mode with OR instead of AND, weakening the skill double-safety gate (ADR-2034 D-9) #189

Closed
opened 2026-11-25 12:44:31 +00:00 by CoreRasurae · 0 comments
Member

Metadata

Commit Message: fix(agents): require both host unsafe mode and the agent's own safe_mode:false to open the skill gate's global safety
Branch: bugfix/m1-skill-gate-global-safety-and

Note (amended 2026-11-25): This repository's PRs are submitted against develop, not master. The reference to master below describing the PR target is corrected to develop accordingly; nothing else about the acceptance criteria changes.

Background and context

ADR-2034 D-9 defines the skill double-safety gate as two independent switches that must both be false before a privileged skill operation (script execution, or reading/listing/executing a non-standard-folder resource) is permitted: "global safety" and "skill safety". The ADR's 2026-11-25 revision corrects the "global safety" half, which was originally specified (and implemented) as an OR of host/actor unsafe mode and the parent type: llm agent's own safe_mode configuration field. Composed with OR, either switch alone opens that half of the gate — exactly the two failure modes D-9's own "Trust model" paragraph and Alternatives A-7/A-8 say the gate exists to prevent: an agent author's own safe_mode: false opening the gate while the host/actor remains safely configured, and a host/actor placed in unsafe mode for an unrelated reason silently authorizing every skill loaded on every agent running on it. The corrected text requires both conditions to hold at once, matching the AND composition already used elsewhere in the standard for an equivalent decision (§13's shell execution: allow_shell: true and host unsafe mode, never either alone).

ToolAgent._is_global_unsafe (src/cleveractors/agents/tool.py) implements the original, now-corrected OR composition.

Current behavior

def _is_global_unsafe(self, context: Optional[dict[str, Any]]) -> bool:
    return (not self.safe_mode) or bool(
        context and context.get("_unsafe_mode", False)
    )

gate_open = global_unsafe and not skill_safe (both call sites, src/cleveractors/agents/tool.py around lines 1357 and 1444) therefore opens the gate whenever either self.safe_mode is False or the invocation context carries _unsafe_mode: true, as long as the skill declares safe_mode: false. A type: llm agent that never sets its own safe_mode: false still has every loaded skill's privileged resources become executable/readable the moment anything propagates _unsafe_mode: true into its invocation context — and conversely, an agent author can set safe_mode: false on their own agent config and unlock every safe_mode: false skill's privileged resources even while the host/actor stays in its default safe mode.

This is also encoded as currently-passing test expectations: features/agent_skills.feature ("Activation lists non-standard resources only when the double-safety gate is open", "A missing resource listing includes non-standard paths when the gate is open", "A non-standard read succeeds when both safety switches are false", and roughly a dozen sibling scenarios) set only the invocation context is globally unsafe (which injects _unsafe_mode: true into the tool-call context) together with the skill "pdf-processing" declares safe_mode false, without configuring the ToolAgent's own "safe_mode": false — and assert the gate is open / the operation succeeds.

Expected behavior

_is_global_unsafe returns True only when both hold: self.safe_mode is False and the invocation context carries _unsafe_mode: true. Either alone must leave the global half of the gate closed, so gate_open (and every execution/read/listing path gated by it) stays False unless the skill and both independent global conditions are satisfied.

Acceptance criteria

  • _is_global_unsafe returns False when self.safe_mode is True and the invocation context carries _unsafe_mode: true (host unsafe alone is insufficient).
  • _is_global_unsafe returns False when self.safe_mode is False and the invocation context does not carry _unsafe_mode: true (agent config alone is insufficient).
  • _is_global_unsafe returns True only when self.safe_mode is False and the invocation context carries _unsafe_mode: true.
  • Every call site gated by gate_open (src/cleveractors/agents/tool.py: skill-tool activation/read/execute, non-standard-resource listing) reflects the corrected composition — no separate OR path remains anywhere in the gate's evaluation.
  • No change to the "skill safety" half (not skill_safe) or to any check unrelated to this gate (e.g. allow_shell, the safe-mode shell blocklist).

Supporting information

  • docs/adr/ADR-2034-skill-package-support.md D-9 (corrected 2026-11-25), A-14.
  • docs/index.md §4.4.8 "The double-safety gate".
  • docs/tools/safe-mode.md "Bundled skill script execution".
  • Affected code: ToolAgent._is_global_unsafe (src/cleveractors/agents/tool.py, ~line 1622), consumed at the two gate_open = global_unsafe and not skill_safe sites (~lines 1357, 1444).
  • Existing scenarios that currently assert the OR behavior and must be updated to also configure the agent's own "safe_mode": false wherever gate-open is expected: features/agent_skills.feature — "Activation lists non-standard resources only when the double-safety gate is open" (~line 574), "A missing resource listing includes non-standard paths when the gate is open" (~line 655), "A non-standard read succeeds when both safety switches are false" (~line 735), and the remaining sibling scenarios that use the the invocation context is globally unsafe step together with the skill "pdf-processing" declares safe_mode false without also setting "safe_mode": false on the ToolAgent config.
  • Parent Epic: #160 ("Epic: Agent Skills — Full Resource Support and Safe Execution") — linked via Forgejo dependency, not referenced further here.

Subtasks

  • Change _is_global_unsafe (src/cleveractors/agents/tool.py) from (not self.safe_mode) or bool(context._unsafe_mode) to (not self.safe_mode) and bool(context._unsafe_mode).
  • Audit both gate_open = global_unsafe and not skill_safe call sites and any other D-9 gate evaluation in src/cleveractors/agents/tool.py for the same composition, correcting any found.
  • Update every features/agent_skills.feature scenario that currently expects the gate open via the invocation context is globally unsafe alone (without the agent's own "safe_mode": false) to also configure "safe_mode": false on the ToolAgent, so each continues to exercise a genuinely-open gate under the corrected composition.
  • Add Behave scenarios proving the gate stays closed when only one of the two global conditions holds (host unsafe alone; agent safe_mode: false alone), in addition to the existing both-closed/both-open coverage.
  • Tests (Robot): extend robot/ integration coverage for skill script execution if it exercises this gate end-to-end with real process execution.
  • 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, followed by a blank line, then additional lines providing relevant details.
  • The commit is pushed to the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to develop, reviewed, and merged.
  • A companion Type/Testing TDD issue exists, its scenario (tagged @tdd_expected_fail) is merged first, and this issue's Forgejo dependency correctly shows it depends on that TDD issue.
## Metadata Commit Message: `fix(agents): require both host unsafe mode and the agent's own safe_mode:false to open the skill gate's global safety` Branch: `bugfix/m1-skill-gate-global-safety-and` **Note (amended 2026-11-25):** This repository's PRs are submitted against `develop`, not `master`. The reference to `master` below describing the PR target is corrected to `develop` accordingly; nothing else about the acceptance criteria changes. ## Background and context ADR-2034 D-9 defines the skill double-safety gate as two independent switches that must both be false before a privileged skill operation (script execution, or reading/listing/executing a non-standard-folder resource) is permitted: "global safety" and "skill safety". The ADR's 2026-11-25 revision corrects the "global safety" half, which was originally specified (and implemented) as an OR of host/actor unsafe mode and the parent `type: llm` agent's own `safe_mode` configuration field. Composed with OR, either switch alone opens that half of the gate — exactly the two failure modes D-9's own "Trust model" paragraph and Alternatives A-7/A-8 say the gate exists to prevent: an agent author's own `safe_mode: false` opening the gate while the host/actor remains safely configured, and a host/actor placed in unsafe mode for an unrelated reason silently authorizing every skill loaded on every agent running on it. The corrected text requires both conditions to hold at once, matching the AND composition already used elsewhere in the standard for an equivalent decision (§13's shell execution: `allow_shell: true` **and** host unsafe mode, never either alone). `ToolAgent._is_global_unsafe` (`src/cleveractors/agents/tool.py`) implements the original, now-corrected OR composition. ## Current behavior ```python def _is_global_unsafe(self, context: Optional[dict[str, Any]]) -> bool: return (not self.safe_mode) or bool( context and context.get("_unsafe_mode", False) ) ``` `gate_open = global_unsafe and not skill_safe` (both call sites, `src/cleveractors/agents/tool.py` around lines 1357 and 1444) therefore opens the gate whenever *either* `self.safe_mode is False` *or* the invocation context carries `_unsafe_mode: true`, as long as the skill declares `safe_mode: false`. A `type: llm` agent that never sets its own `safe_mode: false` still has every loaded skill's privileged resources become executable/readable the moment anything propagates `_unsafe_mode: true` into its invocation context — and conversely, an agent author can set `safe_mode: false` on their own agent config and unlock every `safe_mode: false` skill's privileged resources even while the host/actor stays in its default safe mode. This is also encoded as currently-passing test expectations: `features/agent_skills.feature` ("Activation lists non-standard resources only when the double-safety gate is open", "A missing resource listing includes non-standard paths when the gate is open", "A non-standard read succeeds when both safety switches are false", and roughly a dozen sibling scenarios) set only `the invocation context is globally unsafe` (which injects `_unsafe_mode: true` into the tool-call context) together with `the skill "pdf-processing" declares safe_mode false`, **without** configuring the `ToolAgent`'s own `"safe_mode": false` — and assert the gate is open / the operation succeeds. ## Expected behavior `_is_global_unsafe` returns `True` only when **both** hold: `self.safe_mode is False` **and** the invocation context carries `_unsafe_mode: true`. Either alone must leave the global half of the gate closed, so `gate_open` (and every execution/read/listing path gated by it) stays `False` unless the skill *and* both independent global conditions are satisfied. ## Acceptance criteria - [ ] `_is_global_unsafe` returns `False` when `self.safe_mode is True` and the invocation context carries `_unsafe_mode: true` (host unsafe alone is insufficient). - [ ] `_is_global_unsafe` returns `False` when `self.safe_mode is False` and the invocation context does not carry `_unsafe_mode: true` (agent config alone is insufficient). - [ ] `_is_global_unsafe` returns `True` only when `self.safe_mode is False` **and** the invocation context carries `_unsafe_mode: true`. - [ ] Every call site gated by `gate_open` (`src/cleveractors/agents/tool.py`: skill-tool activation/read/execute, non-standard-resource listing) reflects the corrected composition — no separate OR path remains anywhere in the gate's evaluation. - [ ] No change to the "skill safety" half (`not skill_safe`) or to any check unrelated to this gate (e.g. `allow_shell`, the safe-mode shell blocklist). ## Supporting information - `docs/adr/ADR-2034-skill-package-support.md` D-9 (corrected 2026-11-25), A-14. - `docs/index.md` §4.4.8 "The double-safety gate". - `docs/tools/safe-mode.md` "Bundled skill script execution". - Affected code: `ToolAgent._is_global_unsafe` (`src/cleveractors/agents/tool.py`, ~line 1622), consumed at the two `gate_open = global_unsafe and not skill_safe` sites (~lines 1357, 1444). - Existing scenarios that currently assert the OR behavior and must be updated to also configure the agent's own `"safe_mode": false` wherever gate-open is expected: `features/agent_skills.feature` — "Activation lists non-standard resources only when the double-safety gate is open" (~line 574), "A missing resource listing includes non-standard paths when the gate is open" (~line 655), "A non-standard read succeeds when both safety switches are false" (~line 735), and the remaining sibling scenarios that use the `the invocation context is globally unsafe` step together with `the skill "pdf-processing" declares safe_mode false` without also setting `"safe_mode": false` on the `ToolAgent` config. - Parent Epic: #160 ("Epic: Agent Skills — Full Resource Support and Safe Execution") — linked via Forgejo dependency, not referenced further here. ## Subtasks - [ ] Change `_is_global_unsafe` (`src/cleveractors/agents/tool.py`) from `(not self.safe_mode) or bool(context._unsafe_mode)` to `(not self.safe_mode) and bool(context._unsafe_mode)`. - [ ] Audit both `gate_open = global_unsafe and not skill_safe` call sites and any other D-9 gate evaluation in `src/cleveractors/agents/tool.py` for the same composition, correcting any found. - [ ] Update every `features/agent_skills.feature` scenario that currently expects the gate open via `the invocation context is globally unsafe` alone (without the agent's own `"safe_mode": false`) to also configure `"safe_mode": false` on the `ToolAgent`, so each continues to exercise a genuinely-open gate under the corrected composition. - [ ] Add Behave scenarios proving the gate stays closed when only one of the two global conditions holds (host unsafe alone; agent `safe_mode: false` alone), in addition to the existing both-closed/both-open coverage. - [ ] Tests (Robot): extend `robot/` integration coverage for skill script execution if it exercises this gate end-to-end with real process execution. - [ ] 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, followed by a blank line, then additional lines providing relevant details. - The commit is pushed to the branch matching the Branch in Metadata exactly. - The commit is submitted as a pull request to `develop`, reviewed, and merged. - A companion `Type/Testing` TDD issue exists, its scenario (tagged `@tdd_expected_fail`) is merged first, and this issue's Forgejo dependency correctly shows it depends on that TDD issue.
CoreRasurae added this to the v2.1.0 milestone 2026-11-25 13:57:38 +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#189
No description provided.