Repository navigation
fix: page explain(subject=result/recovery) instead of infinite retry - #3342
Conversation
Problem: explain(subject="result"|"recovery") serializes the full
QUERY_DISCOVERY_EXAMPLES catalog (106 examples, ~82.5KB) inside one
MCPRootPayload -- well over MCP_RESPONSE_BUDGET_BYTES (25000). Two
compounding defects made this unrecoverable rather than merely large:
1. _bounded_item_page only checked payload.items/.messages/.hits via
getattr. MCPRootPayload is a pydantic RootModel wrapping a plain dict,
so none of those attributes ever resolved, and the dict additionally
carries multiple list-valued keys (result_semantics, examples,
read_views) that a single hardcoded field name could never generalize
to anyway. The trimmer always returned page=None.
2. The synthesized continuation came from
_fallback_response_arguments(fn_name, session_id), which only knows
session_id. For a non-session-scoped call like explain(subject=
"result") it returned {}, silently dropping subject -- retrying the
continuation replayed the identical oversized call forever.
What changed:
- _bounded_item_page (polylogue/mcp/server_support.py) now detects a
dict-rooted RootModel payload and delegates to a new
_bounded_root_dict_page helper, which picks the single largest
list-valued key in the root dict and binary-searches its prefix the
same way the attribute-based path already does for items/messages/hits,
leaving smaller sibling lists untouched. This generalizes beyond
explain to any current or future dict-rooted MCP payload with multiple
list fields.
- _fallback_response_arguments/_safe_call/_async_safe_call (plus the
SafeCallHook/AsyncSafeCallHook protocols and server.py's hook wiring)
gained an explicit `arguments` parameter so a tool body can hand its own
bound call arguments to the response-context continuation machinery
instead of the session-id-only fallback.
- explain() (polylogue/mcp/server_cutover.py) gained an `offset` parameter
used to window the examples/read_views lists before serialization, and
now passes {subject, expression, ref, offset} as its safe-call
arguments so a budget-exceeded continuation replays with subject
preserved and offset advanced by the count actually returned.
Verification:
- devtools test tests/unit/mcp/ -> 193 passed (includes the 5 new tests
in tests/unit/mcp/test_explain_catalog_pagination.py, which drive the
real wired explain tool through continuation to exhaustion for both
subject="result" and subject="recovery", asserting all 106 examples are
retrieved exactly once with no duplicates/skips, and that the
continuation's offset strictly advances).
- Manually reverted the three production files (git stash) with the new
test file left in place: 4 of 5 tests failed exactly as described
(page=None, continuation.arguments={}), confirming the test reproduces
the pre-fix defect before the fix was restored.
- devtools verify --quick -> exit 0 (format, lint, mypy --strict, render
all --check, layering/closure-matrix/manifests/doc-commands/
docs-coverage/test-infra-currency/clock-hygiene/timeout-overrides/
degrade-loudly/hash-boundary-census).
Ref polylogue-3k30
Co-Authored-By: Claude <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 18 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes
explain(subject="result"|"recovery")returningpage=null/returned_items=0with a continuation that silently dropssubject,making the query-discovery catalog unrecoverable through the MCP
discovery surface. Generalizes the response-budget trimmer to handle
dict-rooted payloads with multiple list fields, and threads real call
arguments through to continuations for non-session-scoped tools.
Problem
explain(subject="result"|"recovery")serializes the fullQUERY_DISCOVERY_EXAMPLEScatalog (106 examples, ~82.5KB) inside oneMCPRootPayload, well overMCP_RESPONSE_BUDGET_BYTES(25000). Twocompounding defects made this unrecoverable rather than merely large:
_bounded_item_page(polylogue/mcp/server_support.py) only checkedpayload.items/.messages/.hitsviagetattr.MCPRootPayloadis apydantic
RootModelwrapping a plain dict, so none of those attributesever resolve, and the dict additionally carries multiple list-valued
keys (
result_semantics,examples,read_views) that a singlehardcoded field name could never generalize to anyway. The trimmer
always returned
page=None._fallback_response_arguments(fn_name, session_id), which only knowssession_id. For a non-session-scoped call likeexplain(subject="result")it returned{}, silently droppingsubject-- retryingcontinuation.tool/continuation.argumentsreplayed the identical oversized, argument-losing call forever. A
cold model relying purely on the shipped MCP discovery surface
(
list_tools+explain) could not retrieve the query-discoverycatalog at all.
Discovered while building the polylogue-z9gh gap #3 cold-model MCP
continuity replay harness (
devtools/cold_model_continuity_replay.py).Solution
_bounded_item_pagenow detects a dict-rootedRootModelpayloadand delegates to a new
_bounded_root_dict_pagehelper, which picks thesingle largest list-valued key in the root dict and binary-searches its
prefix the same way the existing attribute-based path does for
items/messages/hits, leaving smaller sibling lists untouched. Thisis a clean generalization (not an
explain-only special case): anycurrent or future dict-rooted MCP payload with multiple list fields
gets correct budget trimming for free.
_fallback_response_arguments/_safe_call/_async_safe_call(plusthe
SafeCallHook/AsyncSafeCallHookprotocols andserver.py's hookwiring) gained an explicit
argumentsparameter so a tool body can handits own bound call arguments to the response-context continuation
machinery, instead of the session-id-only fallback that only covers
session-scoped tools.
explain()(polylogue/mcp/server_cutover.py) gained anoffsetparameter that windows the
examples/read_viewslists beforeserialization, and now passes
{subject, expression, ref, offset}as its safe-call arguments so abudget-exceeded continuation replays with
subjectpreserved andoffsetadvanced by the count actually returned on the prior page.total(previously an unrelatedlen(read_views), always 0 for theresult/recoverysubjects) now correctly reports the full catalogsize.
Alternative considered
A dedicated per-
explainpagination path restructuring the responseshape was the fallback plan (AC1 option b), but the generic
_bounded_root_dict_pagegeneralization turned out no more complex andalso silently fixes at least one other pre-existing dict-rooted payload
(
abandoned/maintenance{"items": [...], "total": ...}shapes) that wasnever actually reachable by the old attribute-based trimmer either.
Verification
devtools test tests/unit/mcp/-> 193 passed, including the 5 newtests in
tests/unit/mcp/test_explain_catalog_pagination.py, whichdrive the real wired
explaintool through continuation to exhaustionfor both
subject="result"andsubject="recovery", asserting all 106examples are retrieved exactly once with no duplicates/skips, and that
the continuation's
offsetstrictly advances.file changes (test file left in place) and reran the new test module --
4 of 5 tests failed with
page: None,continuation.arguments: {},confirming the test exercises the exact described failure before the
fix restores it green.
devtools verify --quick-> exit 0 (format, lint,mypy --strict,render all --check, layering/closure-matrix/manifests/doc-commands/docs-coverage/test-infra-currency/clock-hygiene/timeout-overrides/
degrade-loudly/hash-boundary-census). Ran automatically on
git pushvia the pre-push hook as well.
devtools verify --all(reserved for harness/dependencychanges or a final pre-merge diagnostic per repo convention); per-PR CI
skips the heavy
testsuite by design (runs post-merge on master), sothe
devtools test tests/unit/mcp/run above is the actual testevidence for this PR.
Acceptance criteria (polylogue-3k30)
explain(subject="result"|"recovery")pages itsexampleslist with a continuation that preservessubject(andexpression/ref) and advancesoffset._fallback_response_argumentsnow accepts anexplicit
argumentsoverride;explainsupplies it. The mechanism isgeneral (any tool body can opt in), not an
explain-only patch, thoughonly
explainwas migrated to use it in this PR -- othernon-session-scoped tools whose continuations may still fall back to
{}are unaffected by this change and are not claimed as fixed here.explaintool forthe full catalog and asserts every example is retrievable through
continuation; verified to fail pre-fix.
Ref polylogue-3k30