google / google/adk-python

contents rearrange still raises on id-less / unmatched trailing function responses (follow-up to orphan FR prune)

Đang mở
#6,751 5 bình luận 0 reaction 1 người được giao Được @surajksharma07 nhận Xem trên GitHub
live
Ngôn ngữ chính
Python
Star
21.5k
Fork
4k
Merge trung bình
1 ngày 22 giờ
Pull request đã merge (30 ngày)
31

Mô tả

### Describe the Bug

`#6582` / `73e8625` added `_drop_orphaned_function_responses`, which correctly prunes **id'd** function responses with no matching function call before contents assembly.

Two gaps remain and can still permanently poison a session (raise happens in request preprocessing, before any user callback):

1. **`_rearrange_events_for_latest_function_response` still raises** `ValueError: No function call event found for function responses ids: ...` when it cannot pair the trailing FR event. `@GWeale` noted on `#6587` that this rearrange-path drop is still worth having as defense in depth (`main` only prunes responses that carry an id).
2. **Id-less / empty-id trailing FRs are intentionally skipped by the prune helper** (`if response.id`), but then rearrange adds `None` / `''` into the id set and raises — so sessions with stripped or missing FR ids still die on the next turn.

Related hole: when rearrange finds a matching FC event but the trailing FR event also carries unmatched ids (`Last response event should only contain the responses...`), it still raises instead of dropping the unmatched parts.

### Steps to Reproduce

```python
from google.adk.events.event import Event
from google.adk.flows.llm_flows.contents import _get_contents
from google.genai import types

events = [
Event(author='user', content=types.Content(role='user', parts=[types.Part(text='hi')])),
Event(author='agent', content=types.Content(role='model', parts=[types.Part(text='done')])),
Event(
author='agent',
content=types.Content(
role='user',
parts=[types.Part(function_response=types.FunctionResponse(name='tool', id=None, response={'ok': True}))],
),
),
]
_get_contents(None, events, 'agent') # ValueError: ... ids: {None}
```

### Expected Behavior

Orphaned / unpairable trailing function responses are dropped (with a warning), contents assembly continues, and the session stays usable.

### Observed Behavior

`ValueError` during contents assembly; every later turn replays the same fatal history.

### Environment

- ADK: current `main` (post-`73e8625`)
- Related: `#6582` (closed), `#6587` (closed as duplicate of landed prune; rearrange follow-up requested)

### Additional Context

Happy to send the rearrange-path follow-up PR referenced by `@GWeale` on `#6587`.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.