anthropics / anthropics/claude-agent-sdk-python

SessionStore summary fast path paginates before filtering and can skip sessions

未關閉
#1,163 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
8.1k
分支
1.3k
PR 合併指標
PR 指標待擷取

描述

### Summary

`list_sessions_from_store()` can return a short page and skip valid sessions because its summary fast path applies offset/limit before placeholder sessions are loaded and filtered.

### Affected code

`src/claude_agent_sdk/_internal/sessions.py:1632-1715`

### Current behavior

Fresh summary rows are filtered before pagination. Sessions with missing or stale summary sidecars become placeholders. The code then:

1. Sorts all slots.
2. Applies `offset` and `limit`.
3. Loads only placeholders in that page.
4. Drops placeholders that resolve to sidechain/no-summary sessions.
5. Returns the remaining items without backfilling from later slots.

The source comment at lines 1708-1714 explicitly notes that this can short-page.

### Why this matters

The public API promises results sorted by `last_modified` with normal offset/limit semantics. The disk path and slow store path filter before pagination, while the fast path behaves differently based on sidecar freshness.

A UI requesting `limit=10` may receive fewer than ten items even when later valid sessions exist. Offset-based pagination can then skip those sessions permanently or produce inconsistent pages as sidecars become fresh.

### Suggested reproduction

Create a store where:

- the newest listed session lacks a sidecar and loads as a sidechain,
- several older sessions are valid,
- `limit=2`.

The fast path includes the placeholder in the two-slot page, drops it after loading, and returns one result instead of backfilling the next valid session.

### Expected behavior

Filtering semantics should be identical across disk, slow-store, and summary-fast paths.

### Possible fix

Iteratively load bounded batches of unresolved slots until enough valid results exist to satisfy `offset + limit`, or the candidate list is exhausted. The implementation can retain bounded concurrency and avoid loading all sessions eagerly.

Tests should cover missing and stale sidecars that resolve to sidechain and no-summary entries across multiple pages.

### Environment

- Repository revision: current `main` audit at SDK version 0.2.128
- Bundled CLI version: 2.1.220
- Python test suite: 1,291 passed, 5 skipped
- Ruff and mypy: clean

I searched the existing issues and pull requests using the affected symbols and behavior before filing this.

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。