Skip to content

feat: add GET /sessions endpoint with pagination#238

Open
sharma-sugurthi wants to merge 1 commit intojenkinsci:mainfrom
sharma-sugurthi:feat/list-sessions
Open

feat: add GET /sessions endpoint with pagination#238
sharma-sugurthi wants to merge 1 commit intojenkinsci:mainfrom
sharma-sugurthi:feat/list-sessions

Conversation

@sharma-sugurthi
Copy link
Contributor

Fixes #218

What it does

Adds a GET /sessions endpoint that returns a paginated list of active session IDs with message counts.

Query parameters

Param Type Default Description
offset int 0 Starting index
limit int 20 Max sessions per page

Response format

{
  "sessions": [
    {"session_id": "abc-123", "message_count": 4}
  ],
  "total": 1,
  "offset": 0,
  "limit": 20
}

@sharma-sugurthi sharma-sugurthi requested a review from a team as a code owner March 4, 2026 01:58
@sharma-sugurthi
Copy link
Contributor Author

@berviantoleo
get_all_sessions() accepts an optional user_id parameter (currently defaults to None) so that once authentication lands (#78), we can filter sessions by the authenticated user without changing the function signature or the endpoint contract.

right now, no session endpoint (POST, DELETE, GET message history) filters by user either, this is consistent with the current state of the codebase.

also included pagination as discussed on PR #196 , offset and limit query params with defaults of 0 and 20 respectively.

Fixes jenkinsci#218

Adds a GET /sessions endpoint that returns a paginated list of active
session IDs with message counts.

Query parameters:
  - offset (int, default 0): starting index
  - limit (int, default 20): max sessions per page

Response includes total, offset, limit for pagination metadata.

Note: user_id param is stubbed in get_all_sessions() for future
auth filtering (jenkinsci#78). Currently returns all sessions.

Changes:
- api/models/schemas.py — SessionSummary, SessionListResponse
- api/services/memory.py — get_all_sessions(offset, limit, user_id)
- api/routes/chatbot.py — GET /sessions route
- tests/integration/test_chatbot.py — 7 integration tests
@berviantoleo
Copy link
Contributor

Most likely, I'll hold this until we have a proper handling of the session.

@sharma-sugurthi
Copy link
Contributor Author

Yeah @berviantoleo . Holding this until and unless,good handling of the session, what i also thought of..

Copy link
Contributor

@divyansh-cyber divyansh-cyber left a comment

Choose a reason for hiding this comment

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

Overall this is a good addition. The schema design is clean, pagination is reasonable, and the new tests cover the basic happy paths well. get_all_sessions is straightforward and correctly guarded by the lock.
some points that i want to address:
The GET /sessions/{session_id}/message route has been removed from chatbot.py. This breaks the existing message history functionality and needs to be restored before this can be merged.
There is no validation on offset and limit in the route handler. Negative values or very large limits are currently accepted. These should be constrained using Query parameters.
test_list_sessions_pagination_custom only checks the number of returned sessions, not which sessions are returned. It should assert specific session IDs to properly validate pagination behavior.
Ensure get_all_sessions exists in memory.py in the same PR. If not, the import will cause a startup failure.
coming to my final verdict ,the rest of the changes look well-structured and reasonable.

@sharma-sugurthi
Copy link
Contributor Author

@divyansh-cyber thanks..

"GET /sessions/{session_id}/message route removed" This route is not touched by this PR - you can verify by checking the diff. The GET message history endpoint is part of PR #196 (separate branch). Our diff only adds the new GET /sessions list endpoint. The POST /sessions/{session_id}/message and POST .../upload routes are untouched.

"No validation on offset and limit" ,"test_list_sessions_pagination_custom should assert specific session IDs", Good catch and i update that those two of the things.But many be it will be holding this updates too, as @berviantoleo holding this feature enhancement. As sooner, this feature gets attention to make this enhancement concrete. I shall fix those.

"Ensure get_all_sessions exists in memory.py" It does - it's part of this PR's diff in
api/services/memory.py

. You can see it in the files changed

@berviantoleo any comments??

@divyansh-cyber
Copy link
Contributor

@divyansh-cyber thanks..

"GET /sessions/{session_id}/message route removed" This route is not touched by this PR - you can verify by checking the diff. The GET message history endpoint is part of PR #196 (separate branch). Our diff only adds the new GET /sessions list endpoint. The POST /sessions/{session_id}/message and POST .../upload routes are untouched.

"No validation on offset and limit" ,"test_list_sessions_pagination_custom should assert specific session IDs", Good catch and i update that those two of the things.But many be it will be holding this updates too, as @berviantoleo holding this feature enhancement. As sooner, this feature gets attention to make this enhancement concrete. I shall fix those.

"Ensure get_all_sessions exists in memory.py" It does - it's part of this PR's diff in api/services/memory.py

. You can see it in the files changed

@berviantoleo any comments??

Thanks for the clarification. I see now that the GET /sessions/{session_id}/message route is handled in PR #196 and not part of this change.
Good to know get_all_sessions is included in the memory.py diff as well.
The pagination validation and test improvements sound reasonable whenever the feature moves forward. Thanks for taking a look at those.

@berviantoleo berviantoleo added the enhancement For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted label Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add GET /sessions endpoint to list all active sessions

3 participants