TDD: 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) #190

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

Metadata

Commit Message: test(agents): add failing regression for the skill gate's OR-composed global safety (#189)
Branch: tdd/m1-skill-gate-global-safety-and

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

Background and context

Companion TDD issue for #189 ("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)"). Per this project's mandatory Bug Fix TDD workflow, a failing Behave scenario proving the bug exists must be written and merged to develop before any fix is implemented on a bugfix/ branch for #189.

The defect: ToolAgent._is_global_unsafe (src/cleveractors/agents/tool.py, ~line 1622) returns (not self.safe_mode) or bool(context.get("_unsafe_mode", False)). Because this is an OR, either the agent's own safe_mode: false alone, or the invocation context's _unsafe_mode: true alone, opens the "global safety" half of the ADR-2034 D-9 double-safety gate — even though D-9 (corrected 2026-11-09 revision, amended 2026-11-25) requires both to hold at once before a privileged skill operation (script execution, or reading/listing/executing a non-standard-folder resource) is permitted.

Current behavior

No Behave scenario asserts that the gate stays closed when only one of the two global conditions holds. The existing scenarios in features/agent_skills.feature that open the gate (e.g. "A non-standard read succeeds when both safety switches are false", ~line 735) set only the invocation context is globally unsafe plus the skill "pdf-processing" declares safe_mode false — never also configuring the ToolAgent's own "safe_mode": false — and currently pass, which is only possible because the implementation treats either global condition as sufficient.

Expected behavior

A Behave scenario exists, tagged @tdd_issue @tdd_issue_189 @tdd_expected_fail, that:

  • Configures a ToolAgent with its own config "safe_mode" left at the default true (not set to false).
  • Loads a skill (e.g. pdf-processing) that declares safe_mode: false and bundles a non-standard-folder resource (e.g. fixtures/sample.pdf), matching the existing "every D-8 class" skill fixture already used by sibling scenarios.
  • Sets the invocation context to globally unsafe (the invocation context is globally unsafe, i.e. _unsafe_mode: true) — the agent's own safe_mode remains true.
  • Attempts to read the non-standard resource via the skill tool.
  • Asserts the read is refused (gate closed) — e.g. the skill tool fails with a message naming the gate as closed.
  • The assertion currently fails, because the bug is present: with the agent's own safe_mode still true, context._unsafe_mode: true alone already satisfies the buggy OR composition, so the read currently succeeds instead of being refused — the scenario passes in CI only because the @tdd_expected_fail tag inverts the result, per this project's TDD tag rules.
  • The failing step raises/asserts via AssertionError only — never ValueError, RuntimeError, or any other exception type — so the TDD CI hook inverts it correctly.

Acceptance criteria

  • The scenario carries all three required tags: @tdd_issue, @tdd_issue_189, @tdd_expected_fail.
  • The scenario's failing step raises/asserts via AssertionError only.
  • Running the scenario's assertion with @tdd_expected_fail removed locally fails against current develop, confirming the bug is genuinely reproduced (the gate opens with the agent's own safe_mode still true).
  • nox -s unit_tests is green (CI passes via the @tdd_expected_fail inversion).
  • Coverage stays >= 97% (nox -s coverage_report).
  • The scenario is merged to develop via its own PR before work begins on #189's fix.

Supporting information

  • Bug issue: #189.
  • Relevant code: cleveractors.agents.tool.ToolAgent._is_global_unsafe, consumed by the gate_open = global_unsafe and not skill_safe sites in the same module.
  • Existing skill-fixture step a skills context with skill "pdf-processing" having resources of every D-8 class and the the invocation context is globally unsafe / the skill "pdf-processing" declares safe_mode false steps already defined in features/steps/agent_skills_steps.py — reuse rather than duplicate.
  • Spec: docs/adr/ADR-2034-skill-package-support.md D-9 (corrected 2026-11-25); docs/index.md §4.4.8.
  • Forgejo dependency: #189 depends on this issue (this issue blocks #189), per this project's TDD-before-fix workflow.

Subtasks

  • Write a Behave scenario (in features/agent_skills.feature, alongside the existing double-safety-gate coverage) that leaves the ToolAgent's own "safe_mode" at its default true, sets the invocation context globally unsafe, loads a safe_mode: false skill with a non-standard resource, and asserts the gated read/execute is refused.
  • Implement any missing step definitions, extending the existing shared features/steps/agent_skills_steps.py file rather than creating a new one.
  • Tag the scenario @tdd_issue @tdd_issue_189 @tdd_expected_fail.
  • Confirm the scenario's assertion fails when @tdd_expected_fail is removed locally (proving the bug), and passes CI with the tag in place.
  • 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.
  • This TDD issue is closed, with #189 depending on it (Forgejo dependency set after creation).
## Metadata Commit Message: `test(agents): add failing regression for the skill gate's OR-composed global safety (#189)` Branch: `tdd/m1-skill-gate-global-safety-and` **Note (amended 2026-11-25):** This repository's PRs are submitted against `develop`, not `master`. Every reference to `master` below describing the PR target/workflow baseline is corrected to `develop` accordingly; nothing else about the acceptance criteria changes. ## Background and context Companion TDD issue for #189 ("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)"). Per this project's mandatory Bug Fix TDD workflow, a failing Behave scenario proving the bug exists must be written and merged to `develop` before any fix is implemented on a `bugfix/` branch for #189. The defect: `ToolAgent._is_global_unsafe` (`src/cleveractors/agents/tool.py`, ~line 1622) returns `(not self.safe_mode) or bool(context.get("_unsafe_mode", False))`. Because this is an OR, either the agent's own `safe_mode: false` alone, or the invocation context's `_unsafe_mode: true` alone, opens the "global safety" half of the ADR-2034 D-9 double-safety gate — even though D-9 (corrected 2026-11-09 revision, amended 2026-11-25) requires both to hold at once before a privileged skill operation (script execution, or reading/listing/executing a non-standard-folder resource) is permitted. ## Current behavior No Behave scenario asserts that the gate stays **closed** when only one of the two global conditions holds. The existing scenarios in `features/agent_skills.feature` that open the gate (e.g. "A non-standard read succeeds when both safety switches are false", ~line 735) set only `the invocation context is globally unsafe` plus `the skill "pdf-processing" declares safe_mode false` — never also configuring the `ToolAgent`'s own `"safe_mode": false` — and currently pass, which is only possible because the implementation treats either global condition as sufficient. ## Expected behavior A Behave scenario exists, tagged `@tdd_issue @tdd_issue_189 @tdd_expected_fail`, that: - Configures a `ToolAgent` with its own config `"safe_mode"` left at the default `true` (not set to `false`). - Loads a skill (e.g. `pdf-processing`) that declares `safe_mode: false` and bundles a non-standard-folder resource (e.g. `fixtures/sample.pdf`), matching the existing "every D-8 class" skill fixture already used by sibling scenarios. - Sets the invocation context to globally unsafe (`the invocation context is globally unsafe`, i.e. `_unsafe_mode: true`) — the agent's own `safe_mode` remains `true`. - Attempts to read the non-standard resource via the skill tool. - Asserts the read is refused (gate closed) — e.g. the skill tool fails with a message naming the gate as closed. - The assertion currently fails, because the bug is present: with the agent's own `safe_mode` still `true`, `context._unsafe_mode: true` alone already satisfies the buggy OR composition, so the read currently **succeeds** instead of being refused — the scenario passes in CI only because the `@tdd_expected_fail` tag inverts the result, per this project's TDD tag rules. - The failing step raises/asserts via `AssertionError` only — never `ValueError`, `RuntimeError`, or any other exception type — so the TDD CI hook inverts it correctly. ## Acceptance criteria - [ ] The scenario carries all three required tags: `@tdd_issue`, `@tdd_issue_189`, `@tdd_expected_fail`. - [ ] The scenario's failing step raises/asserts via `AssertionError` only. - [ ] Running the scenario's assertion with `@tdd_expected_fail` removed locally fails against current `develop`, confirming the bug is genuinely reproduced (the gate opens with the agent's own `safe_mode` still `true`). - [ ] `nox -s unit_tests` is green (CI passes via the `@tdd_expected_fail` inversion). - [ ] Coverage stays >= 97% (`nox -s coverage_report`). - [ ] The scenario is merged to `develop` via its own PR before work begins on #189's fix. ## Supporting information - Bug issue: #189. - Relevant code: `cleveractors.agents.tool.ToolAgent._is_global_unsafe`, consumed by the `gate_open = global_unsafe and not skill_safe` sites in the same module. - Existing skill-fixture step `a skills context with skill "pdf-processing" having resources of every D-8 class` and the `the invocation context is globally unsafe` / `the skill "pdf-processing" declares safe_mode false` steps already defined in `features/steps/agent_skills_steps.py` — reuse rather than duplicate. - Spec: `docs/adr/ADR-2034-skill-package-support.md` D-9 (corrected 2026-11-25); `docs/index.md` §4.4.8. - Forgejo dependency: #189 depends on this issue (this issue blocks #189), per this project's TDD-before-fix workflow. ## Subtasks - [ ] Write a Behave scenario (in `features/agent_skills.feature`, alongside the existing double-safety-gate coverage) that leaves the `ToolAgent`'s own `"safe_mode"` at its default `true`, sets the invocation context globally unsafe, loads a `safe_mode: false` skill with a non-standard resource, and asserts the gated read/execute is refused. - [ ] Implement any missing step definitions, extending the existing shared `features/steps/agent_skills_steps.py` file rather than creating a new one. - [ ] Tag the scenario `@tdd_issue @tdd_issue_189 @tdd_expected_fail`. - [ ] Confirm the scenario's assertion fails when `@tdd_expected_fail` is removed locally (proving the bug), and passes CI with the tag in place. - [ ] 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. - This TDD issue is closed, with #189 depending on it (Forgejo dependency set after creation).
CoreRasurae added this to the v2.1.0 milestone 2026-11-25 13:08:41 +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#190
No description provided.