Skip to content

feat(mcp): name the next operation when a completed result overflows the response budget - #11015

Merged
morluto merged 2 commits into
mainfrom
feat/unknown-overflow-recovery
Nov 15, 2026
Merged

morluto merged 2 commits into
mainfrom
feat/unknown-overflow-recovery

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Refs #10508 (Phase 6.1). When a completed MCP result does not fit the response budget, ToolResultDelivery picks a recovery sentence: export the bundle, page again with a smaller limit, follow a view continuation, or use CLI JSON. That choice existed only as prose. It is now also details.reported_limits.next_operation, naming the MCP operation the recovery starts with. A one-row list_unknowns page no longer suggests a smaller limit, since one row cannot be split.

Problem and expected behavior

  • serverUnknownsMcp.test.ts could check the route only by matching text: not.toContain("or page list_unknowns") for a committed-unknown receipt, and "same connection" / "smaller limit" / not "CLI JSON" for an overflowing list. test(mcp): assert snapshot-import and unknown-receipt facts instead of guidance prose #11004 left these as prose because no field existed.
  • A list_unknowns call with limit: 1 whose single head exceeds the budget got "use a smaller limit, then follow next_offset". That retry cannot succeed; only export recovers the head.
  • Expected: a caller can route on a field: export_evidence_bundle vs list_unknowns vs inspect_analysis_view vs get_evidence_bundle, and no field when the only recovery is CLI JSON.

Change and scope

  • src/server/ToolResultDelivery.ts: the nested ternary that chose nextStep becomes overflowNextStep(), which returns { text, operation? }. Texts are unchanged except the new one-row branch. operation is added to the reported limits as next_operation:
    • committed unknown receipt, retained evidence_reference, bundle summary: export_evidence_bundle
    • view continuation: inspect_analysis_view
    • list_unknowns with more than one row: list_unknowns; with zero or one row: export_evidence_bundle (new text)
    • other get_evidence_bundle projections and inspect_address_context: get_evidence_bundle
    • anything else (CLI JSON fallback): absent
  • serverUnknownsMcp.test.ts: the receipt helper, the one-row page and the overflowing list assert next_operation; the four prose fragments are removed.
  • docs/reference/mcp-contracts.md: documents the field next to the list-overflow recovery.

Not included: the forwarded-content overflow (toForwardedToolResult, a screenshot too large) keeps prose only; its recovery is "ask for a smaller image", not a different operation. reported_limits is a free-form record in the error schema, so no catalog change.

Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the readiness and merge checklists
unchecked. Maintainers can help resolve open questions.

Contract and boundary impact

  • Semantic owner and earliest changed stage: ToolResultDelivery.successResult overflow recovery (producer); consumers: every MCP tool whose completed result can overflow
  • Contribution scope fit and linked maintainer decision: not applicable (additive diagnostic field, Phase 6.1 tracker [Design] Assert structured remediation facts instead of guidance prose #10508)
  • CLI and MCP/tool-catalog contract: additive details.reported_limits.next_operation on transport resource_constraint; no schema or catalog change (reported_limits is free-form)
  • Provider, bridge, target-format, or platform compatibility: none
  • Evidence, artifact, provenance, or reconstruction contract: none
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): none

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests: 8 in serverUnknownsMcp.test.ts before and after (assertions changed). toolResult.test.ts goes from 18 to 24: a table drives ToolResultDelivery through every other branch (CLI fallback has no field; retained Evidence, view continuation, address context, bundle summary and record selection each name their operation).
  • Mutation (run locally, then reverted): without the next_operation spread, 2 of 8 fail ("returns exact committed unknown receipts when creation and update replies overflow", "recovers an oversized list with same-session paging or export"). Before the one-row branch existed, the one-row page assertion failed with next_operation: "list_unknowns", which is how the misleading recovery was found.
  • Neighbouring overflow consumers run unchanged: toolResult.test.ts (18), contextEvidenceOverflow.test.ts (5), evidenceRecordSelectionMcp.test.ts (6), largeToolResult.test.ts (8) all pass.
  • Wall/CPU: the 5-file focused run took 46.6 s wall, 33.4 s user, 7.3 s sys including build (vitest 32.4 s; contextEvidenceOverflow 7.4 s and evidenceRecordSelectionMcp 6.7 s dominate, unchanged here). serverUnknownsMcp.test.ts alone: vitest 14.2 s, mostly transform.
  • User-visible CLI/MCP output: overflow errors gain details.reported_limits.next_operation; a one-row list_unknowns overflow gets an export-only remediation.

For boundary fixes, identify the applicable boundary regressions
and lifecycle regressions
covered by the evidence above, and explain relevant gaps.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:focused -- tests/boundary/mcp/serverUnknownsMcp.test.ts tests/boundary/mcp/toolResult.test.ts tests/boundary/mcp/contextEvidenceOverflow.test.ts tests/boundary/mcp/evidenceRecordSelectionMcp.test.ts tests/boundary/mcp/largeToolResult.test.ts: 45 passed after the one-row fix (first run: 1 failure, which led to that fix)
  • npm run test:focused -- tests/boundary/mcp/serverUnknownsMcp.test.ts with next_operation removed: 2 failed (expected)
  • npm run test:focused -- tests/boundary/mcp/toolResult.test.ts after adding the route table: 24 passed
  • npm run check:fast: passed
  • npm run docs:check: passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none
  • Real Hopper/Ghidra, browser, or OS coverage: macOS only
  • Package or release metadata impact: none
  • Security, privacy, process, or containment review: none; the value is a tool name

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T10:21:31.766064Z 1eec6cd New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge.

Summary

The PR adds details.reported_limits.next_operation so callers can choose a recovery without reading prose. An overflowing one-row list_unknowns page now points to export.

  • MCP overflow errors name the first recovery operation.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Completed result"] --> B{"Fits response budget?"}
  B -->|Yes| C["Return complete result"]
  B -->|No| D["Choose recovery text and optional operation"]
  D --> E{"MCP recovery available?"}
  E -->|Yes| F["Return resource_constraint with next_operation"]
  E -->|No| G["Return CLI guidance without next_operation"]
Loading

Reviews (2) · Last reviewed commit: "test(mcp): assert next_operation for eve..." · Reviewed by Greptile

Comment thread src/server/ToolResultDelivery.ts Resolved
@morluto
morluto merged commit e793fd6 into main Nov 15, 2026
7 of 9 checks passed
@morluto
morluto deleted the feat/unknown-overflow-recovery branch November 15, 2026 10:22
@morluto morluto added area: mcp MCP server, transport, and tool registration enhancement New feature or request labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant