Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion acp_adapter/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limit is pulled from kwargs without validation/capping, despite the comment “Cap limit”. If the client passes a non-int (or a negative/zero) this can raise at len(infos) > limit / infos[:limit] or produce surprising pagination behavior. Consider coercing to int, defaulting on failure, and clamping to a sensible range (e.g., 1..1000).

Suggested change
limit = kwargs.get("limit", 50)
raw_limit = kwargs.get("limit", 50)
try:
limit = int(raw_limit)
except (TypeError, ValueError):
limit = 50
limit = max(1, min(limit, 1000))

Copilot uses AI. Check for mistakes.
has_more = len(infos) > limit
infos = infos[:limit]

sessions = []
for s in infos:
updated_at = s.get("updated_at")
Expand All @@ -451,7 +467,9 @@ async def list_sessions(
updated_at=updated_at,
)
)
return ListSessionsResponse(sessions=sessions)

Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is trailing whitespace on the blank line after appending to sessions, which will show up in diffs and can trip linters. Consider removing the extra spaces.

Suggested change

Copilot uses AI. Check for mistakes.
next_cursor = sessions[-1].session_id if has_more and sessions else None
return ListSessionsResponse(sessions=sessions, nextCursor=next_cursor)
Comment on lines 442 to +472
Copy link

Copilot AI Apr 21, 2026

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 uses AI. Check for mistakes.
Comment on lines +470 to +472
Copy link

Copilot AI Apr 21, 2026

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.

# ---- Prompt (core) ------------------------------------------------------

Expand Down
Loading