feat(gateway): paginate /api/sessions/{id}/messages and /api/jobs (#38370) - #38942
feat(gateway): paginate /api/sessions/{id}/messages and /api/jobs (#38370)#38942rodboev wants to merge 3 commits into
Conversation
00e5b07 to
6f0cda8
Compare
dc1b78b to
cf2d43d
Compare
5e76126 to
64fb509
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for preserving the resolved-session behavior and adding endpoint-level paging coverage. The premise remains valid on current main: gateway/platforms/api_server.py:1861-1867 loads and serializes every session message, and gateway/platforms/api_server.py:3594-3605 returns all cron jobs. The related #60347 work landed for the dashboard web-server route, not these direct gateway handlers.
Problems
- The public API-server docs do not describe the new contract:
website/docs/user-guide/features/api-server.md:300-302says only “List all scheduled jobs,” and lines 332-344 omit pagination details for session messages.
Suggested changes
- Document
limit/offset, their default/cap behavior, and thelimit,offset,total, andhas_moreresponse fields for both endpoints inwebsite/docs/user-guide/features/api-server.md.
Automated hermes-sweeper review.
|
Added the docs pass you called out in b4adf0d.
|
Summary
GET /api/sessions/{session_id}/messagesandGET /api/jobsreturned their entire backing collection with no way to request a page. A long session can carry thousands of messages, and the client pays for the full payload with no cursor to scroll.Both now accept
limit/offsetquery params and return{limit, offset, total, has_more}, mirroring the existingGET /api/sessionspaging contract and its_parse_nonnegative_inthelper. Defaults (limit=200) preserve current behavior for typical callers; only collections longer than the page size change shape, and those gain a deterministic cursor.has_moreis computed against the realtotalcount rather than a heuristic, so paging never reports a spurious extra page. Malformed params fall back to defaults (no 400).The issue suggested reusing
get_messages_around, but that primitive anchors on a message id for symmetric windowed scrolling, not offset/limit paging. The fix keeps the slicing in the handlers (single file, same pattern as the existing list sessions endpoint) rather than pushingLIMIT/OFFSETintoSessionDBandcron.jobs.Fixes #38370
Changes
gateway/platforms/api_server.py: parselimit/offsetin_handle_session_messagesand_handle_list_jobsvia existing_parse_nonnegative_int; slice and add{limit, offset, total, has_more}(+16 lines)tests/gateway/test_session_api.py:test_session_messages_paginationcovering default, first page, short last page, malformed-param fallback (+47 lines)tests/gateway/test_api_server_jobs.py:test_list_jobs_pagination_slices_and_reports_total,test_list_jobs_default_limit_returns_all(+51 lines)Test plan
pytest tests/gateway/test_session_api.py tests/gateway/test_api_server_jobs.py -v --timeout=0-- 49 passedtest_session_crud_and_message_history,test_list_jobs,test_list_jobs_include_disabled,test_list_jobs_default_excludes_disabledall pass unchanged