fix(agentscope): support QwenPaw v2 task handoffs - #255
Merged
Conversation
sipercai
marked this pull request as ready for review
July 30, 2026 09:54
ralf0131
approved these changes
Jul 30, 2026
ralf0131
left a comment
Collaborator
There was a problem hiding this comment.
Summary
Well-structured fix for cross-Task context safety in AgentScope v2 and QwenPaw v2 instrumentation. The refactoring correctly addresses the GeneratorExit handling, context token lifecycle, and nested span parentage issues reported in #252.
Review Highlights
- Correctness: Proper context attach/detach pattern using dataclasses (
_AgentState,_ActingState,_EntryState) to track state across async boundaries. Thehook_advicefail-open boundary is correctly applied to probe-owned lifecycle operations. - GeneratorExit handling: Distinguishes between normal downstream
aclose()(successful completion) and real errors — critical for QwenPaw v2's heartbeat layer. - Backward compatibility: Preserves QwenPaw 1 and CoPaw compatibility while adding v2 support.
- Tests: Comprehensive regression tests validate
ENTRY -> AGENT -> LLMandENTRY -> AGENT -> STEP -> TOOLacross fresh Tasks.
Minor Note
The large diff is mostly CI workflow configuration (1500+ lines). Core logic changes are focused and well-scoped.
Automated review by github-manager-bot
14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
QwenPaw 2 advances the AgentScope reply async generator through a heartbeat
layer that may call
__anext__()andaclose()from differentasyncio.Taskcontexts. The original AgentScope v2 instrumentation keptOpenTelemetry and probe-owned
ContextVar.Tokenvalues across yields, so alater Task could attempt to reset a token created by another Context.
QwenPaw 2 also closes downstream AgentScope iterators when its ENTRY stream is
closed. Before this follow-up, AgentScope treated the resulting
GeneratorExitas a tool/ReAct failure, and nested LLM/STEP/TOOL spans couldlose the active AGENT parent after a Task handoff.
This change:
ContextVarlifecycle and derives the1-based round from AgentScope v2's
agent.state.cur_iter;qwenpaw.runtime.runtime.Runtime.runwhile preservingQwenPaw 1 and CoPaw compatibility;
underlying
__anext__()oraclose()is executing, then detaches them inthe same Task before yielding to the caller;
GeneratorExitfrom a normal downstreamaclose()as successfulcompletion while preserving a real error raised by the downstream close;
hook_advicefail-open boundary for probe-owned lifecycleoperations while leaving business iteration and close operations outside
advice;
assistant output, ignoring response-created, in-progress, and heartbeat
envelopes;
exception identity when instrumentation callbacks fail;
that validates
ENTRY -> AGENT -> LLMandENTRY -> AGENT -> STEP -> TOOLacross fresh Tasks;mcp<2only in the AgentScope-oldest and QwenPaw v1/legacy testenvironments because those framework versions use the MCP 1.x API.
This addresses the cross-Context crash, missing QwenPaw 2 request root,
incorrect
GeneratorExiterror statuses, and broken nested AgentScopeparentage reported in #252. Duplicate instrumentation remains an independent
follow-up and is not claimed as fixed here.
Addresses #252
Type of change
How Has This Been Tested?
ReAct spans ended as
ERROR / GeneratorExit, the nested child was parenteddirectly to ENTRY, and cross-Task token detach was logged.
spans end as
UNSET, the child is parented to AGENT, andchild_parent_is_agent=true.py311/py312/py313-test-loongsuite-instrumentation-agentscope-latest—24 passed per environment.
py310/py313-test-loongsuite-instrumentation-agentscope-oldest—94 passed per environment.
py312-test-loongsuite-instrumentation-qwenpaw-latest—22 passed, 4 skipped.
py310-test-loongsuite-instrumentation-qwenpaw-{v1,legacy}—14 passed, 1 skipped per environment.
tox -e precommit.cassette privacy scan, and
git diff --check.no violations; only existing development-stability and provider-enum advice.
Validation Evidence
Spec and Scope
semantics, QwenPaw 2 downstream close behavior, compatibility test
dependencies, focused tests, and changelogs.
Local Checks
python3 "$PIPELINE_SKILL_DIR/scripts/check_loongsuite_pr_readiness.py" --repo .PRE_COMMIT_HOME="$(mktemp -d /tmp/loongsuite-precommit.XXXXXX)" uvx --from 'tox<5' tox -e precommituvx --from 'tox<5' tox -c tox-loongsuite.ini -p auto -e py311-test-loongsuite-instrumentation-agentscope-latest,py312-test-loongsuite-instrumentation-agentscope-latest,py313-test-loongsuite-instrumentation-agentscope-latestuvx --from 'tox<5' tox -c tox-loongsuite.ini -p auto -e py310-test-loongsuite-instrumentation-agentscope-oldest,py313-test-loongsuite-instrumentation-agentscope-oldestuvx --from 'tox<5' tox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-qwenpaw-latestuvx --from 'tox<5' tox -c tox-loongsuite.ini -p auto -e py310-test-loongsuite-instrumentation-qwenpaw-v1,py310-test-loongsuite-instrumentation-qwenpaw-legacyuvx --from 'tox<5' tox -c tox-loongsuite.ini -p auto -e lint-loongsuite-instrumentation-agentscope,lint-loongsuite-instrumentation-qwenpawgit diff origin/main -- . | rg -q '<credential-and-local-path-patterns>'Business Isolation
aclose()closes downstream once; ENTRY/AGENT/STEP/TOOL remainUNSET.ERRORwith the real error type.__anext__()andaclose()run in fresh Tasks without an instrumentation detach warning or current-span leak.Functional Matrix
Real E2E Matrix
Runtime.runis an async iterator only.LOONGSUITE_PYTHON_SITE_BOOTSTRAP=True OTEL_TRACES_EXPORTER=console OTEL_METRICS_EXPORTER=none qwenpaw appTelemetry and Weaver
UNSET; noerror.type.ValueError.__anext__()/aclose()regressionsweaver registry live-check -r <registry>/model --advice-profile loongsuite-genai --input-format json ...agentscopeprovider-enum advice remain.qwenpaw.*andcopaw.*custom attributes still need registry registration or a compatibility decision.CI
3ffb1c50.trigger a fresh CI run.
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.