feat(DIARCHERS-1620): paginate MCP list endpoints and cap log size - #632
Merged
Conversation
liuwei08
approved these changes
Aug 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Several MCP read-only endpoints returned unbounded results — all rows /
the full log in a single response — which could overflow the client/model
context, truncate output, or hang on large data (big matrix expansions,
large test suites, long build logs). This PR bounds every such endpoint by
default while still allowing callers to page through the full set.
Changes
src/api/handlers/mcp/pagination.py— shared helper:parse_pagination()reads/validates?limit=&offset=(default limit100, max 500;
400on invalid values); the default is applied evenwhen the caller passes nothing, so a bare call is always bounded.
page(items, total, limit, offset)wraps results in a standard{items, total, limit, offset}envelope.jobs.py:list_jobs— paginated + optional?state=filter (exact match,e.g.
failure). Not filtered by default.get_job_test_results— paginated (test suites can be very large).list_job_artifacts— paginated by slicing the in-memoryarchivejsonb array.
get_job_log— bounded by bytes: returns the last 1 MB by default(where failures live),
max_bytesto change the cap (max 5 MB), oroffset+lengthfor a ranged read. Returns{log, total_bytes, offset, length, truncated}.projects.py:list_projects— paginated; the three access paths (scoped MCP token /unscoped token / session user) collapsed into one shared WHERE clause.
Impact
{items, total, limit, offset}instead of a bare array;get_job_logreturns an object instead of raw text. The MCP client is updated in the
companion PR.
restart_job/rerun_jobstillread the full
build_jobsset (no LIMIT), so downstream propagation isnot truncated.
list_buildsalready hadLIMIT 50; this brings the rest in line.Testing
py_compile).