RemoteA2aAgent: after_request interceptors run twice on streamed text closed without a full-replacement last_chunk
Maintainer thường phản hồi trong vòng 3 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
🔴 Required Information
Describe the Bug:
Since dbae28d3c ("persist streamed RemoteA2aAgent output without last_chunk"), an after_request interceptor runs twice on streamed text. It runs once on each partial chunk, then again on the final event, which is built from chunks the interceptor already changed.
_remote_a2a_agent.py:2392stores the intercepted partial in the aggregator (aggregator.record_partial(artifact_id, intercepted, ...)). Line 2407 stores the intercepted delta the same way.- The aggregate built from those chunks then goes through
_run_after_request_interceptorsagain: on a delta close (2411), at the boundary finalize (2473), and on the flush paths.
So an interceptor that isn't idempotent changes the stored answer twice. That covers redaction that adds markers, tags or footers, translation, and counting usage. A stream that ends with a full-replacement last_chunk still gets the interceptor once, so the stored text depends on how the remote server chunks its output.
The existing test, test_after_request_filter_suppressing_partial_chunk..., uses a filter that drops chunks, and running that twice gives the same result.
Steps to Reproduce:
- Check out main (b916291fc)
- Run the script below from the repo root. It reuses the streaming helpers in
tests/unittests/a2a/agent/test_remote_a2a_agent.py.
Expected Behavior:
The stored final text is the interceptor applied once to the whole text (<Hello world>), however the stream was chunked.
Observed Behavior:
Same output in legacy and v2 modes:
full_replacement_last_chunk: persisted=['<Hello world>']
no_last_chunk: persisted=['<<Hello ><world>>']
delta_close: persisted=['<<Hello ><world>>']
Before dbae28d3c, the last two stored [] and ['<world>'], which were the bugs that commit fixed.
Environment Details:
- ADK Library Version: main at b916291fc
- Desktop OS: macOS
- Python Version: 3.12.13
Model Information:
- Are you using LiteLLM: No
- Which model is being used: N/A (scripted A2A stream)
🟡 Optional Information
Regression:
Yes, for the paths dbae28d3c added. The full-replacement path is unchanged.
Minimal Reproduction Code:
import asyncio
from tests.unittests.a2a.agent import test_remote_a2a_agent as T
from google.adk.a2a import _compat
from google.adk.a2a.agent import RequestInterceptor
from google.adk.a2a.agent.config import A2aRemoteAgentConfig
async def tag(ctx, resp, event):
# Stands in for any rewriting interceptor (redaction, tagging, translation).
if event.content and event.content.parts:
for p in event.content.parts:
if p.text and not p.thought:
p.text = f'<{p.text}>'
return event
config = A2aRemoteAgentConfig(request_interceptors=[RequestInterceptor(after_request=tag)])
DONE = _compat.TS_COMPLETED
cases = {
# (kind, artifact_id, texts, append, last_chunk)
'full_replacement_last_chunk': [('artifact', 'a', ['Hello '], False, False),
('artifact', 'a', ['Hello world'], False, True),
('status', DONE, None)],
'no_last_chunk': [('artifact', 'a', ['Hello '], False, False),
('artifact', 'a', ['world'], True, False),
('status', DONE, None)],
'delta_close': [('artifact', 'a', ['Hello '], False, False),
('artifact', 'a', ['world'], True, True),
('status', DONE, None)],
}
async def main():
for name, steps in cases.items():
_, session = await T._run_single_streaming_turn(
T._build_streaming_a2a_script(steps, use_v2=False), config=config)
persisted = [''.join(p.text for p in e.content.parts if p.text and not p.thought)
for e in session.events
if e.author == 'specialist' and e.content and e.content.parts]
print(f'{name}: persisted={persisted}')
asyncio.run(main())
Additional Context:
A possible fix is to store the raw chunks in the aggregator (record the event from before interception at 2392 and 2407) and run the interceptors once on the aggregated final event, as the full-replacement path does. The partials sent to the caller would still be intercepted one by one. I'm happy to send a PR if that approach sounds right.
How often has this issue occurred?:
- Always (100%)
- Ngôn ngữ chính
- Python
- Star
- 22.3k
- Fork
- 4.4k
- Merge trung bình
- 1 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 6
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của google/adk-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
google/adk-python#8360 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
google/adk-python#8359 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Can pin to litellm version be changed?Có thể đã có người làm @llalitkumarrr đã nhận 10 ngày trước. Đang mởmodels
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
google/adk-python#8129 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
-
OpenAPI tools ignore operation- and path-level server overridesCó thể đã có người làm @sanketpatil06 đã nhận 14 ngày trước. Đang mởtools
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
google/adk-python#8064 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Two docstrings in openapi_tool document parameters the signatures do not acceptCó thể đã có người làm @surajksharma07 đã nhận 17 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
google/adk-python#8024 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của google/adk-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
vllm-project/vllm#70030 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
TigreGotico/tugaphone#408 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
gke-labs/kube-agents#7308 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
t: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 3 ngày
-
chore
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
lugassawan/swe-workbench#841 ·