Skip to content

feat(gateway): paginate /api/sessions/{id}/messages and /api/jobs (#38370) - #38942

Open
rodboev wants to merge 3 commits into
NousResearch:mainfrom
rodboev:pr/api-server-pagination
Open

feat(gateway): paginate /api/sessions/{id}/messages and /api/jobs (#38370)#38942
rodboev wants to merge 3 commits into
NousResearch:mainfrom
rodboev:pr/api-server-pagination

Conversation

@rodboev

@rodboev rodboev commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

GET /api/sessions/{session_id}/messages and GET /api/jobs returned 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/offset query params and return {limit, offset, total, has_more}, mirroring the existing GET /api/sessions paging contract and its _parse_nonnegative_int helper. 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_more is computed against the real total count 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 pushing LIMIT/OFFSET into SessionDB and cron.jobs.

Fixes #38370

Changes

  • gateway/platforms/api_server.py: parse limit/offset in _handle_session_messages and _handle_list_jobs via existing _parse_nonnegative_int; slice and add {limit, offset, total, has_more} (+16 lines)
  • tests/gateway/test_session_api.py: test_session_messages_pagination covering 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 passed
  • Existing test_session_crud_and_message_history, test_list_jobs, test_list_jobs_include_disabled, test_list_jobs_default_excludes_disabled all pass unchanged

@alt-glitch alt-glitch added type/feature New feature or request comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have labels Jun 4, 2026
@rodboev
rodboev force-pushed the pr/api-server-pagination branch from 00e5b07 to 6f0cda8 Compare June 10, 2026 14:02
@rodboev
rodboev force-pushed the pr/api-server-pagination branch from dc1b78b to cf2d43d Compare June 28, 2026 16:29

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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-302 says 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 the limit, offset, total, and has_more response fields for both endpoints in website/docs/user-guide/features/api-server.md.

Automated hermes-sweeper review.

Comment thread gateway/platforms/api_server.py
@rodboev

rodboev commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Added the docs pass you called out in b4adf0d.

website/docs/user-guide/features/api-server.md now documents limit and offset on GET /api/sessions/{id}/messages, spells out the pagination metadata fields that come back with that response, and notes the matching limit / offset / include_disabled surface plus total / has_more metadata on GET /api/jobs.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform area/sessions Session lifecycle, resume, persistence, history labels Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Query new API Server Jobs and Sessions with pagination and limits.

3 participants