-
Notifications
You must be signed in to change notification settings - Fork 15.5k
fix: support pagination and cwd filtering in list sessions #13460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -438,6 +438,22 @@ async def list_sessions( | |||||||||||||
| **kwargs: Any, | ||||||||||||||
| ) -> ListSessionsResponse: | ||||||||||||||
| infos = self.session_manager.list_sessions(cwd=cwd) | ||||||||||||||
|
|
||||||||||||||
| if cursor: | ||||||||||||||
| # Find the cursor index | ||||||||||||||
| for idx, s in enumerate(infos): | ||||||||||||||
| if s["session_id"] == cursor: | ||||||||||||||
| infos = infos[idx + 1:] | ||||||||||||||
| break | ||||||||||||||
| else: | ||||||||||||||
| # Cursor not found, return empty | ||||||||||||||
| infos = [] | ||||||||||||||
|
|
||||||||||||||
| # Cap limit | ||||||||||||||
| limit = kwargs.get("limit", 50) | ||||||||||||||
| has_more = len(infos) > limit | ||||||||||||||
| infos = infos[:limit] | ||||||||||||||
|
|
||||||||||||||
| sessions = [] | ||||||||||||||
| for s in infos: | ||||||||||||||
| updated_at = s.get("updated_at") | ||||||||||||||
|
|
@@ -451,7 +467,9 @@ async def list_sessions( | |||||||||||||
| updated_at=updated_at, | ||||||||||||||
| ) | ||||||||||||||
| ) | ||||||||||||||
| return ListSessionsResponse(sessions=sessions) | ||||||||||||||
|
|
||||||||||||||
|
||||||||||||||
Copilot
AI
Apr 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pagination behavior (cursor slicing, limit, and nextCursor generation) is introduced here, but the existing ACP server tests only cover title/updated_at conversion and cwd filtering. Adding tests for: (1) limit truncation + nextCursor set, (2) passing cursor returns the next page, and (3) boundary cases like empty results would help prevent regressions.
Copilot
AI
Apr 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ListSessionsResponse constructor is populated with nextCursor=... while the rest of this file consistently uses snake_case field names when instantiating ACP schema models (e.g., session_id=..., protocol_version=...). Even if aliases currently make this work, using the canonical Python field name here (likely next_cursor) would keep style consistent and reduce the chance of a runtime validation error if the schema config changes.
| next_cursor = sessions[-1].session_id if has_more and sessions else None | |
| return ListSessionsResponse(sessions=sessions, nextCursor=next_cursor) | |
| next_cursor = sessions[-1].session_id if has_more and sessions else None | |
| return ListSessionsResponse(sessions=sessions, next_cursor=next_cursor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
limitis pulled fromkwargswithout validation/capping, despite the comment “Cap limit”. If the client passes a non-int (or a negative/zero) this can raise atlen(infos) > limit/infos[:limit]or produce surprising pagination behavior. Consider coercing toint, defaulting on failure, and clamping to a sensible range (e.g., 1..1000).