AgentScope Version
2.0.12dev
Description
Fixes #4013.
A stop request can capture parked reply A, enter the dispatcher retry path while the session is locked, and later be consumed after the session has advanced to parked reply B. The service currently applies that old event to B and ends B as interrupted.
Discard queued interrupts when the loaded agent has no awaiting work or the event targets a different reply. Check under the session lock, before starting channel delivery, registering an inbox consumer, reading/updating the current message or publishing a synthetic reply start. This also prevents an ignored channel-bound trigger from leaving a delivery subscription that duplicates the next legitimate response. Direct SDK behavior and the running-session pub/sub path are unchanged.
Related: #3690 covers the idle-interrupt subset. This combines idle and stale-target handling, with validation before channel delivery starts. These changes should be coordinated, and the guards can be consolidated if #3690 merges first.
The regression tests exercise the real interrupt producer, session lock, dispatcher retry/requeue, run registry and serialized service execution using event gates. Controls cover ASKING/SUBMITTED work, valid targets, idle sessions, session-lock release and channel delivery. A real ChannelClients stream also verifies that a stale interrupt followed by a legitimate confirmation produces exactly one response with the expected text and terminal reply ID.
Model/storage/resource factories and the platform sender remain offline fixtures. The A-to-B checkpoint transition models another serialized run; this is not an HTTP/Redis/multi-process end-to-end test.
Validation
Python 3.11.6 on macOS arm64:
- 14 related agent/HITL/service/pipeline/channel suites: 170 passed, 42 subtests passed.
- The dispatcher stale-target selection fails on unmodified main.
- The channel regression tests fail with the late guard: an ignored trigger starts delivery, and the next legitimate confirmation is delivered twice. They pass with validation before channel delivery.
- Original
pre-commit run --all-files: passed; all applicable hooks passed, including add-trailing-comma, mypy, Black, Flake8, Pylint and Pyroma.
- Full
pytest tests was attempted in this local environment but stopped at collection because dependencies including anthropic, dashscope, fakeredis, redis, SQLAlchemy and aiortc are missing. The full repository suite has not been validated locally.
Related suite command:
PYTHONPATH=src:tests python -m pytest tests/agent_interrupt_test.py tests/service_stale_interrupt_test.py tests/agent_basic_test.py tests/hitl_user_confirmation_test.py tests/hitl_external_execution_test.py tests/hitl_mixed_test.py tests/service_agent_interrupt_test.py tests/service_chat_locking_test.py tests/service_chat_run_context_test.py tests/service_wakeup_dispatcher_test.py tests/pipeline_team_test.py tests/service_chat_channel_delivery_test.py tests/channel_clients_test.py tests/channel_stream_test.py -q --tb=short
Checklist
- An issue has been created for this PR
- I have read CONTRIBUTING.md
- Docstrings follow the existing style
- Related documentation in agentscope-ai/docs: no companion change included; the queued-target behavior is documented in ChatService.interrupt's docstring
- Code is ready for review, with the full-suite environment limitation recorded above
AI-assisted investigation, implementation and regression testing.