test(agents): add failing regression for LLMAgent's collapsed D-9 global-safety signal (#195) #197

Merged
CoreRasurae merged 1 commit from tdd/m1-llm-tool-dispatch-shared-unsafe-signal into develop 2026-11-27 15:26:18 +00:00
Member

Summary

Adds a failing-first Behave regression test proving issue #195: LLMAgent._resolve_parent_unsafe() (src/cleveractors/agents/llm.py) returns True when EITHER this agent's own safe_mode config field is False OR the invocation context already carries _unsafe_mode: true -- an OR of the two ADR-2034 D-9 "global safety" legs. Every dispatch site in _execute_tool_loop() then feeds that SAME parent_unsafe value into both _build_ephemeral_tool_config() (the ephemeral ToolAgent's own safe_mode) and _build_tool_context() (the ephemeral context's _unsafe_mode), so ToolAgent._is_global_unsafe()'s AND of those two (corrected by PR #193 / issue #189) always sees two identical operands and collapses back to the pre-#193 OR semantics.

Extends features/llm_agent_tool_loop.feature / features/steps/llm_agent_tool_loop_steps.py with a new scenario (tagged @tdd_issue, @tdd_issue_195, @tdd_expected_fail) and two new step definitions: an LLM agent with only its own safe_mode: false set (no host ever placed in unsafe mode) and a loaded safe_mode: false skill bundling a non-standard resource, driving a model-issued skill tool call that attempts to read that resource, asserting the call is refused.

Verified locally that removing @tdd_expected_fail makes the assertion genuinely fail against current develop (the resource read currently succeeds instead of being refused), confirming the bug is reproduced, and that the failing step raises only AssertionError so the TDD CI hook inverts it correctly.

The actual fix lands separately on a bugfix/ branch per issue #195.

Verification

  • nox -s lint - green
  • nox -s format -- --check - green
  • nox -s typecheck - green (0 errors)
  • nox -s security_scan - green (0 findings)
  • nox -s dead_code - green
  • nox -s unit_tests - green (160 features, 3364 scenarios, 0 failed)
  • nox -s coverage_report - 97.3% (>= 96.5% threshold)
  • nox -s integration_tests - green (382 Robot tests, 0 failed)

Test plan

  • New scenario tagged @tdd_issue, @tdd_issue_195, @tdd_expected_fail
  • Confirmed the scenario's assertion fails (AssertionError) against current develop when the tag is removed
  • Confirmed the TDD @tdd_expected_fail inversion makes the scenario pass with the tag restored
  • Full nox -s unit_tests suite green
  • Coverage >= threshold via nox -s coverage_report

Closes #194
Refs #195

## Summary Adds a failing-first Behave regression test proving issue #195: `LLMAgent._resolve_parent_unsafe()` (`src/cleveractors/agents/llm.py`) returns `True` when EITHER this agent's own `safe_mode` config field is `False` OR the invocation context already carries `_unsafe_mode: true` -- an OR of the two ADR-2034 D-9 "global safety" legs. Every dispatch site in `_execute_tool_loop()` then feeds that SAME `parent_unsafe` value into both `_build_ephemeral_tool_config()` (the ephemeral `ToolAgent`'s own `safe_mode`) and `_build_tool_context()` (the ephemeral context's `_unsafe_mode`), so `ToolAgent._is_global_unsafe()`'s AND of those two (corrected by PR #193 / issue #189) always sees two identical operands and collapses back to the pre-#193 OR semantics. Extends `features/llm_agent_tool_loop.feature` / `features/steps/llm_agent_tool_loop_steps.py` with a new scenario (tagged `@tdd_issue`, `@tdd_issue_195`, `@tdd_expected_fail`) and two new step definitions: an LLM agent with only its own `safe_mode: false` set (no host ever placed in unsafe mode) and a loaded `safe_mode: false` skill bundling a non-standard resource, driving a model-issued skill tool call that attempts to read that resource, asserting the call is refused. Verified locally that removing `@tdd_expected_fail` makes the assertion genuinely fail against current `develop` (the resource read currently succeeds instead of being refused), confirming the bug is reproduced, and that the failing step raises only `AssertionError` so the TDD CI hook inverts it correctly. The actual fix lands separately on a `bugfix/` branch per issue #195. ## Verification - `nox -s lint` - green - `nox -s format -- --check` - green - `nox -s typecheck` - green (0 errors) - `nox -s security_scan` - green (0 findings) - `nox -s dead_code` - green - `nox -s unit_tests` - green (160 features, 3364 scenarios, 0 failed) - `nox -s coverage_report` - 97.3% (>= 96.5% threshold) - `nox -s integration_tests` - green (382 Robot tests, 0 failed) ## Test plan - [x] New scenario tagged `@tdd_issue`, `@tdd_issue_195`, `@tdd_expected_fail` - [x] Confirmed the scenario's assertion fails (AssertionError) against current develop when the tag is removed - [x] Confirmed the TDD `@tdd_expected_fail` inversion makes the scenario pass with the tag restored - [x] Full `nox -s unit_tests` suite green - [x] Coverage >= threshold via `nox -s coverage_report` Closes #194 Refs #195
test(agents): add failing regression for LLMAgent's collapsed D-9 global-safety signal (#195)
Some checks failed
CI / lint (pull_request) Successful in 40s
CI / quality (pull_request) Successful in 51s
CI / build (pull_request) Successful in 49s
CI / security (pull_request) Successful in 2m51s
CI / typecheck (pull_request) Successful in 2m56s
CI / integration_tests (pull_request) Successful in 3m15s
CI / unit_tests (pull_request) Successful in 6m51s
CI / benchmark (pull_request) Failing after 12m44s
CI / coverage (pull_request) Successful in 6m50s
CI / status-check (pull_request) Successful in 2s
d02a7984c2
Adds a failing-first Behave regression test proving issue #195:
LLMAgent._resolve_parent_unsafe() (src/cleveractors/agents/llm.py)
returns True when EITHER this agent's own safe_mode config field is
False OR the invocation context already carries _unsafe_mode: true --
an OR of the two ADR-2034 D-9 "global safety" legs. Every dispatch
site in _execute_tool_loop() (three call sites, ~lines 1221-1230,
1376-1395, 1544-1553) then feeds that SAME parent_unsafe value into
both _build_ephemeral_tool_config() (the ephemeral ToolAgent's own
safe_mode) and _build_tool_context() (the ephemeral context's
_unsafe_mode). ToolAgent._is_global_unsafe()'s AND of those two
(corrected by PR #193 / issue #189) therefore always sees two
identical operands and collapses back to the pre-#193 OR semantics --
an LLM agent author's own safe_mode: false alone opens the gate, with
no host ever placed in unsafe mode, exactly the case docs/index.md
§4.4.8 (ADR-2034 D-9, corrected 2026-11-25) requires two independent
signals to refuse.

Extends features/llm_agent_tool_loop.feature / features/steps/
llm_agent_tool_loop_steps.py (the dedicated LLM-agent-driven
tool-dispatch feature, already covering skill-tool dispatch via its
stuck-model/loaded-skill scenario) with a new scenario and two new
step definitions: an LLMAgent with its own safe_mode: false and a
loaded safe_mode: false skill bundling a non-standard resource, with
no context argument passed to _execute_tool_loop() at all (so no
host-propagated _unsafe_mode reaches it), drives a model-issued skill
tool call reading that resource, and asserts the resulting ToolMessage
reports a refusal ("global safety is true", "skill safety is false")
-- the same refusal signature ToolAgent._skill_tool already uses for a
directly constructed agent.

Verified locally that removing @tdd_expected_fail makes the scenario's
assertion fail against current develop (the resource read currently
succeeds, returning [SKILL_RESOURCE_READ]...sample fixture, instead of
being refused), confirming the bug is genuinely reproduced; the
failing step raises only AssertionError, so the TDD CI hook inverts it
correctly. With the tag restored, nox -s lint, nox -s format --
--check, nox -s typecheck, nox -s security_scan, nox -s dead_code,
nox -s unit_tests (full suite, 3364 scenarios), nox -s
coverage_report (97.3%), and nox -s integration_tests (382 Robot
tests) are all green.

The actual fix (deriving the ephemeral ToolAgent's safe_mode and
_unsafe_mode independently instead of from one shared parent_unsafe
signal) lands separately on a bugfix/ branch per issue #195.

ISSUES CLOSED: #194
Refs: #195
hurui200320 left a comment

PR Review: !197 (Ticket #194)

Verdict: Approve

Test-only TDD capture PR, executed exactly as issue #194 prescribes. I independently verified the failing-first property locally: with @tdd_expected_fail removed in a throwaway worktree, the new scenario fails with AssertionError (No ToolMessage found with content containing 'global safety is true'), with the ToolMessage showing [SKILL_RESOURCE_READ]📄 Skill: pdf-processing | Resource: fixtures/sample.pdf | Size: 14 chars ... sample fixture — i.e. the non-standard resource read currently succeeds through the real LLM-agent dispatch path, reproducing bug #195 for the right reason. The failing step raises only AssertionError, so the TddExpectedFailPolicy inversion handles it correctly, and the stale-tag guard (inverted == 0 check) is genuinely exercised. With the tag restored: lint, format -- --check, typecheck (0 errors), unit_tests (160 features / 3364 scenarios), and coverage_report (97.3%) all verified green locally, matching the reported results. (integration_tests relied on the reported 382-test green run — a Behave-only change cannot affect the Robot suite.) No gism0 MCP tools were available in this session, so the ticket memory journal was not consulted; issues #194/#195 were read directly from Forgejo instead.

The PR correctly implements only the test capture: the actual fix (deriving the ephemeral ToolAgent's safe_mode and _unsafe_mode independently across all three _execute_tool_loop dispatch sites) is deliberately deferred to the bugfix/ branch per issue #195, so the absence of a fix is not counted against this PR. No prior review comments or author responses exist on the PR, so nothing needed to be dropped as out-of-scope from the discussion.

Critical Issues

None.

Major Issues

None.

Minor Issues

None.

Nits

  1. features/llm_agent_tool_loop.feature:211-212 — refusal assertion omits the requested resource name. Spec §4.4.8 requires the execution error to name "both safety states and the requested resource"; the sibling direct-ToolAgent #189 scenarios in features/agent_skills.feature (lines 708-727, 760-777) also assert non-standard and fixtures/sample.pdf. Adding one more assertion (e.g. And the messages list should contain a ToolMessage with content containing fixtures/sample.pdf) would pin the full spec-mandated message shape on the LLM-dispatch path too. Optional; can be folded into the fix PR for #195.

  2. Regression pins only the primary dispatch site. The scenario exercises the main-loop dispatch (~llm.py 1376-1395); the budget-retry (~1221-1230) and stuck-model-retry (~1544-1553) mirrors remain unpinned by this failing-first test. This is compliant with issue #194's acceptance criteria (one scenario required), and issue #195's fix criteria already mandate updating all three sites and auditing scenarios that rely on the collapsed signal — noting it only so the fix PR's coverage of the two mirror sites isn't assumed from this scenario alone.

Summary

A clean, minimal, single-commit TDD capture that does precisely what issue #194 specifies: a type: llm agent with only its own safe_mode: false (no host-level unsafe signal anywhere in the invocation context — _execute_tool_loop is invoked with no context argument), a loaded safe_mode: false skill bundling a non-standard resource, and a model-issued skill tool call reading it, asserting the refusal signature (global safety is true, skill safety is false) that matches the corrected §4.4.8 / ADR-2034 D-9 AND-gate and the refusal messages emitted at tool.py 1395-1401/1456-1461. Implementation details check out against production code: _loaded_skills is the real SkillLoader-injected config key (llm.py 994), the mock's {"skill_name", "resource"} args match _SkillToolRequest parsing (tool.py 215), and SkillResourceClassifier.classify(...).value produces "non_standard", matching _SKILL_NON_STANDARD_CLASS. Both new step definitions follow the file's existing conventions exactly. Tag combination satisfies TddExpectedFailPolicy validation; commit first line and branch name match issue #194's Metadata exactly; the branch merges cleanly into current develop. One heads-up for the follow-up fix PR (already covered by #195's acceptance criteria, not an issue here): the pre-existing #115 scenario in this same feature file ("LLM agent with safe_mode false successfully writes a file...") asserts the collapsed-signal behavior and will need updating once the gate is derived independently. Approve.

## PR Review: !197 (Ticket #194) ### Verdict: Approve Test-only TDD capture PR, executed exactly as issue #194 prescribes. I independently verified the failing-first property locally: with `@tdd_expected_fail` removed in a throwaway worktree, the new scenario fails with `AssertionError` (`No ToolMessage found with content containing 'global safety is true'`), with the ToolMessage showing `[SKILL_RESOURCE_READ]📄 Skill: pdf-processing | Resource: fixtures/sample.pdf | Size: 14 chars ... sample fixture` — i.e. the non-standard resource read currently succeeds through the real LLM-agent dispatch path, reproducing bug #195 for the right reason. The failing step raises only `AssertionError`, so the `TddExpectedFailPolicy` inversion handles it correctly, and the stale-tag guard (`inverted == 0` check) is genuinely exercised. With the tag restored: `lint`, `format -- --check`, `typecheck` (0 errors), `unit_tests` (160 features / 3364 scenarios), and `coverage_report` (97.3%) all verified green locally, matching the reported results. (`integration_tests` relied on the reported 382-test green run — a Behave-only change cannot affect the Robot suite.) No gism0 MCP tools were available in this session, so the ticket memory journal was not consulted; issues #194/#195 were read directly from Forgejo instead. The PR correctly implements only the test capture: the actual fix (deriving the ephemeral ToolAgent's `safe_mode` and `_unsafe_mode` independently across all three `_execute_tool_loop` dispatch sites) is deliberately deferred to the `bugfix/` branch per issue #195, so the absence of a fix is not counted against this PR. No prior review comments or author responses exist on the PR, so nothing needed to be dropped as out-of-scope from the discussion. ### Critical Issues None. ### Major Issues None. ### Minor Issues None. ### Nits 1. **features/llm_agent_tool_loop.feature:211-212 — refusal assertion omits the requested resource name.** Spec §4.4.8 requires the execution error to name "both safety states and the requested resource"; the sibling direct-`ToolAgent` #189 scenarios in `features/agent_skills.feature` (lines 708-727, 760-777) also assert `non-standard` and `fixtures/sample.pdf`. Adding one more assertion (e.g. `And the messages list should contain a ToolMessage with content containing fixtures/sample.pdf`) would pin the full spec-mandated message shape on the LLM-dispatch path too. Optional; can be folded into the fix PR for #195. 2. **Regression pins only the primary dispatch site.** The scenario exercises the main-loop dispatch (~`llm.py` 1376-1395); the budget-retry (~1221-1230) and stuck-model-retry (~1544-1553) mirrors remain unpinned by this failing-first test. This is compliant with issue #194's acceptance criteria (one scenario required), and issue #195's fix criteria already mandate updating all three sites and auditing scenarios that rely on the collapsed signal — noting it only so the fix PR's coverage of the two mirror sites isn't assumed from this scenario alone. ### Summary A clean, minimal, single-commit TDD capture that does precisely what issue #194 specifies: a `type: llm` agent with only its own `safe_mode: false` (no host-level unsafe signal anywhere in the invocation context — `_execute_tool_loop` is invoked with no context argument), a loaded `safe_mode: false` skill bundling a non-standard resource, and a model-issued `skill` tool call reading it, asserting the refusal signature (`global safety is true`, `skill safety is false`) that matches the corrected §4.4.8 / ADR-2034 D-9 AND-gate and the refusal messages emitted at `tool.py` 1395-1401/1456-1461. Implementation details check out against production code: `_loaded_skills` is the real `SkillLoader`-injected config key (`llm.py` 994), the mock's `{"skill_name", "resource"}` args match `_SkillToolRequest` parsing (`tool.py` 215), and `SkillResourceClassifier.classify(...).value` produces `"non_standard"`, matching `_SKILL_NON_STANDARD_CLASS`. Both new step definitions follow the file's existing conventions exactly. Tag combination satisfies `TddExpectedFailPolicy` validation; commit first line and branch name match issue #194's Metadata exactly; the branch merges cleanly into current `develop`. One heads-up for the follow-up fix PR (already covered by #195's acceptance criteria, not an issue here): the pre-existing #115 scenario in this same feature file ("LLM agent with safe_mode false successfully writes a file...") asserts the collapsed-signal behavior and will need updating once the gate is derived independently. Approve.
CoreRasurae force-pushed tdd/m1-llm-tool-dispatch-shared-unsafe-signal from d02a7984c2
Some checks failed
CI / lint (pull_request) Successful in 40s
CI / quality (pull_request) Successful in 51s
CI / build (pull_request) Successful in 49s
CI / security (pull_request) Successful in 2m51s
CI / typecheck (pull_request) Successful in 2m56s
CI / integration_tests (pull_request) Successful in 3m15s
CI / unit_tests (pull_request) Successful in 6m51s
CI / benchmark (pull_request) Failing after 12m44s
CI / coverage (pull_request) Successful in 6m50s
CI / status-check (pull_request) Successful in 2s
to 6d2750e895
Some checks failed
CI / lint (pull_request) Successful in 47s
CI / typecheck (pull_request) Successful in 2m11s
CI / benchmark (pull_request) Has started running
CI / quality (pull_request) Successful in 1m42s
CI / security (pull_request) Successful in 2m5s
CI / build (pull_request) Successful in 1m36s
CI / integration_tests (pull_request) Successful in 3m23s
CI / unit_tests (pull_request) Successful in 7m17s
CI / coverage (pull_request) Successful in 6m2s
CI / status-check (pull_request) Successful in 1s
CI / lint (push) Successful in 40s
CI / typecheck (push) Successful in 1m22s
CI / build (push) Successful in 46s
CI / security (push) Successful in 2m8s
CI / quality (push) Successful in 2m18s
CI / integration_tests (push) Successful in 4m28s
CI / unit_tests (push) Failing after 20m36s
CI / benchmark (push) Successful in 33m30s
CI / coverage (push) Has been skipped
CI / status-check (push) Failing after 1s
2026-11-27 15:02:34 +00:00
Compare
Author
Member

Thanks for the review and the independent verification, @hurui200320.

What was done

Nit 1 — refusal assertion omits the requested resource name

Confirmed valid against the spec before touching anything: docs/index.md §4.4.8 states "the operation MUST fail with an execution error naming both safety states and the requested resource" (same wording carried in docs/adr/ADR-2034-skill-package-support.md's D-9 text and docs/actor-registry-standard.md §16.1). The scenario only asserted the two safety-state substrings and omitted the resource path, unlike the sibling direct-ToolAgent #189 scenarios in features/agent_skills.feature (lines 708-727, 760-777), which assert non-standard, global safety is ..., skill safety is ..., and fixtures/sample.pdf.

Applied exactly the fix you suggested: added And the messages list should contain a ToolMessage with content containing fixtures/sample.pdf, reusing the existing generic assertion step — no new step definition and no production code change, since ToolAgent._skill_tool's refusal message already names the resource (tool.py ~1395-1401). Re-verified locally that the untagged scenario still fails with the same AssertionError at the global safety is true step (the new assertion is simply never reached while the bug is present, since Behave stops at the first failing step), and that all scenarios in the feature file pass with @tdd_expected_fail restored.

Nit 2 — regression pins only the primary dispatch site

Not changed, per your own scoping: you noted this "is compliant with issue #194's acceptance criteria (one scenario required)" and is a heads-up for the follow-up fix PR's test coverage of the two mirror sites, not an issue with this PR. Agreed, and issue #195's own acceptance criteria already call for auditing/updating all three dispatch sites in the fix — left for that PR.

Heads-up on the pre-existing #115 scenario needing a future update

Not changed here either — you flagged this explicitly as a note for the follow-up fix PR (once the gate is derived independently, that scenario's assertions will need revisiting), not an action item for this test-capture PR. No change made.

Other notes

develop advanced in the meantime with an unrelated commit (issue #191, D-11 skill safe-mode/resource consistency validation). The branch was rebased onto it; confirmed that commit touches only SkillValidator/skill_schema.py and feature files unrelated to this scenario, and does not interact with it (this scenario injects _loaded_skills directly, bypassing SkillValidator entirely, and its skill fixture already declares safe_mode: false, outside D-11's trigger condition in any case). Re-ran lint, format -- --check, and typecheck against the rebased branch — all green. No src/ files changed in this update, so the previously-reported full-suite coverage_report (97.3%), security_scan, dead_code, and integration_tests (382/382) results remain valid; also re-confirmed via a feature-scoped unit_tests run (all 37 scenarios in features/llm_agent_tool_loop.feature pass).

Commit was amended in place (not a new commit) and force-pushed to this same branch, per the project's single-commit-per-issue convention; commit message updated to document the above.

Thanks for the review and the independent verification, @hurui200320. ## What was done ### Nit 1 — refusal assertion omits the requested resource name Confirmed valid against the spec before touching anything: `docs/index.md` §4.4.8 states "the operation MUST fail with an execution error naming both safety states and the requested resource" (same wording carried in `docs/adr/ADR-2034-skill-package-support.md`'s D-9 text and `docs/actor-registry-standard.md` §16.1). The scenario only asserted the two safety-state substrings and omitted the resource path, unlike the sibling direct-`ToolAgent` #189 scenarios in `features/agent_skills.feature` (lines 708-727, 760-777), which assert `non-standard`, `global safety is ...`, `skill safety is ...`, **and** `fixtures/sample.pdf`. Applied exactly the fix you suggested: added `And the messages list should contain a ToolMessage with content containing fixtures/sample.pdf`, reusing the existing generic assertion step — no new step definition and no production code change, since `ToolAgent._skill_tool`'s refusal message already names the resource (`tool.py` ~1395-1401). Re-verified locally that the untagged scenario still fails with the same `AssertionError` at the `global safety is true` step (the new assertion is simply never reached while the bug is present, since Behave stops at the first failing step), and that all scenarios in the feature file pass with `@tdd_expected_fail` restored. ### Nit 2 — regression pins only the primary dispatch site Not changed, per your own scoping: you noted this "is compliant with issue #194's acceptance criteria (one scenario required)" and is a heads-up for the follow-up fix PR's test coverage of the two mirror sites, not an issue with this PR. Agreed, and issue #195's own acceptance criteria already call for auditing/updating all three dispatch sites in the fix — left for that PR. ### Heads-up on the pre-existing #115 scenario needing a future update Not changed here either — you flagged this explicitly as a note for the follow-up fix PR (once the gate is derived independently, that scenario's assertions will need revisiting), not an action item for this test-capture PR. No change made. ## Other notes `develop` advanced in the meantime with an unrelated commit (issue #191, D-11 skill safe-mode/resource consistency validation). The branch was rebased onto it; confirmed that commit touches only `SkillValidator`/`skill_schema.py` and feature files unrelated to this scenario, and does not interact with it (this scenario injects `_loaded_skills` directly, bypassing `SkillValidator` entirely, and its skill fixture already declares `safe_mode: false`, outside D-11's trigger condition in any case). Re-ran `lint`, `format -- --check`, and `typecheck` against the rebased branch — all green. No `src/` files changed in this update, so the previously-reported full-suite `coverage_report` (97.3%), `security_scan`, `dead_code`, and `integration_tests` (382/382) results remain valid; also re-confirmed via a feature-scoped `unit_tests` run (all 37 scenarios in `features/llm_agent_tool_loop.feature` pass). Commit was amended in place (not a new commit) and force-pushed to this same branch, per the project's single-commit-per-issue convention; commit message updated to document the above.
CoreRasurae deleted branch tdd/m1-llm-tool-dispatch-shared-unsafe-signal 2026-11-27 15:26:18 +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.

Dependencies

No dependencies set.

Reference
cleveragents/cleveractors-core!197
No description provided.