Skip to content

test(run_agent): align concurrent-interrupt _Stub with current AIAgent interface#18974

Open
Sanjays2402 wants to merge 1 commit into
NousResearch:mainfrom
Sanjays2402:fix/main-ci-concurrent-interrupt-stub-tool-guardrails
Open

test(run_agent): align concurrent-interrupt _Stub with current AIAgent interface#18974
Sanjays2402 wants to merge 1 commit into
NousResearch:mainfrom
Sanjays2402:fix/main-ci-concurrent-interrupt-stub-tool-guardrails

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Summary

Fixes two Tests failures observed on main (and therefore propagating to every open PR):

FAILED tests/run_agent/test_concurrent_interrupt.py::test_concurrent_interrupt_cancels_pending
FAILED tests/run_agent/test_concurrent_interrupt.py::test_running_concurrent_worker_sees_is_interrupted

Reference run: 25250051126 on 5d3be898a.

Root cause

_execute_tool_calls_concurrent has gained three dependencies the lightweight _Stub fixture didn't carry:

  1. self._tool_guardrails.before_call(...) is consulted before each tool runs, and .allows_execution gates invocation. The stub had no _tool_guardrails attribute → AttributeError: '_Stub' object has no attribute '_tool_guardrails'.

  2. self._append_guardrail_observation(name, args, result, failed=...) is called for non-blocked results to fold guardrail observations into the tool output. The stub had no such method.

  3. _invoke_tool is called with messages= and pre_tool_block_checked= kwargs by the concurrent path, so the fixtures' slow_tool / polling_tool callables raised TypeError: ... got an unexpected keyword argument 'pre_tool_block_checked'.

Fix

  • _tool_guardrails set to a permissive MagicMock whose before_call/after_call return objects with allows_execution=True (these tests aren't exercising guardrails).
  • _append_guardrail_observation stubbed as a no-op pass-through.
  • slow_tool / polling_tool accept **kwargs so any future _invoke_tool plumbing is absorbed without yet another rewrite.

The interrupt-fanout invariants the tests do exercise (worker-thread tid registration, is_interrupted() propagation across ThreadPoolExecutor workers, post-clear cleanup) are unchanged.

Validation

$ pytest tests/run_agent/test_concurrent_interrupt.py -q
4 passed in 1.39s

Scope

  • ✅ No production code change (test-fixture-only fix)
  • ✅ All 4 tests in the file pass

Out of scope

The other ~13 main-CI failures — happy to send those as separate focused PRs (one already up: #18972).

…t interface

`_execute_tool_calls_concurrent` has gained two attribute / call-site
dependencies that the lightweight `_Stub` test fixture didn't carry:

1. `self._tool_guardrails.before_call(...)` is now consulted before each
   tool runs, and the result's `.allows_execution` gate decides whether
   to invoke the tool. The stub had no `_tool_guardrails` attribute, so
   both interrupt-fanout tests crashed with
   `AttributeError: '_Stub' object has no attribute '_tool_guardrails'`.

2. `self._append_guardrail_observation(name, args, result, failed=...)`
   is called for non-blocked results to fold guardrail observations into
   the tool output. The stub had no such method.

Additionally, `_invoke_tool` is now invoked with `messages=` and
`pre_tool_block_checked=` kwargs by the concurrent path, so the test
fixtures' `slow_tool` / `polling_tool` callables raised
`TypeError: ... got an unexpected keyword argument 'pre_tool_block_checked'`.

Fix all three drifts:

- `_tool_guardrails` is set to a permissive `MagicMock` whose
  `before_call`/`after_call` return objects with `allows_execution=True`
  (these tests aren't exercising guardrails).
- `_append_guardrail_observation` is stubbed as a no-op pass-through.
- `slow_tool` / `polling_tool` accept `**kwargs` so any future
  `_invoke_tool` plumbing is absorbed without yet another rewrite.

The interrupt-fanout invariants the tests *do* exercise (worker-thread
tid registration, `is_interrupted()` propagation across
ThreadPoolExecutor workers, post-clear cleanup) are unchanged.

No production code change. Fixes the two assertion failures observed
on `main` (run 25250051126):

`tests/run_agent/test_concurrent_interrupt.py::test_concurrent_interrupt_cancels_pending`
`tests/run_agent/test_concurrent_interrupt.py::test_running_concurrent_worker_sees_is_interrupted`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists type/test Test coverage or test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants