google / google/adk-python

DatabaseSessionService.list_sessions lacks pagination support

オープン
#4,621 コメント 7 件 リアクション 6 件 担当者 2 名 @DeanChensj が担当を希望しています GitHub で見る
needs review services
主要言語
Python
スター
21.5k
フォーク
4k
平均マージ
1日 14時間
マージ済み PR(30日)
37

説明

## Description

`DatabaseSessionService.list_sessions()` queries **all** session rows for a given `app_name` (and optional `user_id`) without any pagination mechanism (`LIMIT`/`OFFSET` or cursor-based). When the number of sessions under an app grows large, this causes severe performance issues.

## Impact

In our production environment with ~10k sessions per app, calling `list_sessions()` takes approximately **74 seconds** to return, making the API endpoint essentially unusable.

## Current Behavior

```python
# base_session_service.py
class ListSessionsResponse(BaseModel):
sessions: list[Session] = Field(default_factory=list)

async def list_sessions(
self, *, app_name: str, user_id: Optional[str] = None
) -> ListSessionsResponse:
...
```

The method returns all sessions at once with no way to limit the result set.

## Proposed Solution

Add pagination support to `BaseSessionService.list_sessions()` and `DatabaseSessionService`:

```python
class ListSessionsResponse(BaseModel):
sessions: list[Session] = Field(default_factory=list)
next_page_token: str | None = None

async def list_sessions(
self,
*,
app_name: str,
user_id: str | None = None,
page_size: int = 20,
page_token: str | None = None,
) -> ListSessionsResponse:
...
```

The implementation should:
- Accept `page_size` (with a reasonable default, e.g. 20, max 100) and `page_token`
- Query with `LIMIT`/`OFFSET` (or cursor-based pagination)
- Order by `update_time DESC` for consistent results
- Return `next_page_token` when more results are available
- Maintain backward compatibility (default behavior returns first page)

## Workaround

We currently bypass `DatabaseSessionService.list_sessions()` by querying PostgreSQL directly with `LIMIT`/`OFFSET` in our service layer.

## Environment

- ADK version: 1.25.1
- Python: 3.12
- Database: PostgreSQL with asyncpg

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。