Skip to content

fix(mcp): name response-byte and startup ceilings in recovery - #6005

Merged
morluto merged 6 commits into
mainfrom
cursor/mcp-response-startup-ceilings-8a8c
Oct 21, 2026
Merged

morluto merged 6 commits into
mainfrom
cursor/mcp-response-startup-ceilings-8a8c

Conversation

@morluto

@morluto morluto commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

Refs #5910 (parent #5808). When the MCP stdio response budget is hit, recovery now names REA_MCP_MAX_RESPONSE_BYTES, the effective byte value, the 10485760 byte (10 MiB) floor, and that a change requires restarting the REA process. It names REA's reserved single-string limit (MAX_STRING_LENGTH - 1024) separately from Node's MAX_STRING_LENGTH, and says this setting raises neither.

An oversized complete get_evidence_bundle still tells the agent to call detail: summary, then inspect_analysis_view. An oversized summary does not repeat that step. It still names export_evidence_bundle, which writes the retained bundle outside one MCP frame. That remains the MCP recovery path when the overflow is a string-length limit a larger byte budget cannot raise.

Fixed MCP startup phase budgets are named when those deadlines fire: value, units, and no runtime override. Codex startup_timeout_sec of 30 seconds stays client guidance on the doctor path. REA does not enforce that figure as the doctor deadline. A binary_session timeout after the catalog uses that same sentence.

Oversized SDK validation recovery still returns parseable JSON. When a diagnostic preview of quotes or backslashes would expand past the text budget, only that preview is shortened. The error keeps reported_limits.evidence_reference.kind: "retained-evidence" when recording succeeds, and the complete diagnostic stays in retained Evidence.

Problem and expected behavior

A response that exceeds the stdio budget said to use a larger MCP response budget without naming REA_MCP_MAX_RESPONSE_BYTES, the floor, or restart. The string-ceiling branch reported REA's reserved limit as Node's ceiling. Oversized complete dossier delivery replaced the detail: summary next step with generic CLI JSON guidance.

rea mcp doctor reported an expired deadline without the effective milliseconds when the deadline fired during binary_session after initialize and the catalog. Packaged startup checks for initialize (15000 ms), tools/list (5000 ms), and first catalog (20000 ms) failed without those values on the probe path.

A quoted SDK validation diagnostic ("\\ repeated) made the replacement error's text encoding fail. The transport then removed the structured carrier and sent empty content, so the client could not read the retained-evidence reference.

An oversized get_evidence_bundle summary told MCP-only callers to use CLI JSON. export_evidence_bundle still works on the same connection, and a string-length overflow is not fixed by raising the byte budget.

Change and scope

Wording and projection, plus fitting the SDK diagnostic preview to the MCP text budget. Numeric ceilings are unchanged and no new setting was added.

  • Completed-result overflow (ToolResultDelivery) and oversized-error replacement (EvidenceMcpServer.recoverError) share one projection. Receive-buffer text names the effective REA_MCP_MAX_RESPONSE_BYTES value. String-ceiling text names REA's reserved limit and Node's actual ceiling, and says the env var does not raise either. A complete get_evidence_bundle keeps the detail: summary discovery sentence. An oversized summary drops only that sentence and keeps the same export_evidence_bundle clause. Paging or complete CLI JSON stays the next step for the other overflow paths.
  • rea mcp doctor appends the fixed doctor deadline when the deadline, an SDK request timeout, or an abort fires, including a binary_session rejection after the catalog. The effective milliseconds are the applied budget (policy default 30000 ms).
  • The packaged startup probe names the same fixed phase budgets when its initialize, tools/list, first-catalog, or doctor connect deadlines fire. Unrelated probe failures do not get that sentence.
  • JSON depth refusal names the 1000-level cap and says this release has no runtime override.
  • Oversized SDK validation recovery still records the original error. If the 256-character diagnostic_preview expands past the text budget under JSON escaping, only that preview is shortened (diagnostic_truncated: true). The wire error remains parseable JSON and keeps the retained-evidence reference.

Moonshot's 13312 byte schema budget and the compact schema depth of 10 do not fail the call; compact presentation reduces the advertisement. No new error was added for them.

Analysis-view, environment, and HTTP admission caps in the same inventory theme were left unchanged. They either truncate with an existing limitation or fail through a mixed refusal, and this PR does not spray wording into those directories.

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.

Not applicable. This is recovery text for existing MCP budgets. It does not add a provider, target execution, injection, mutation, or protection recovery.

Contract and boundary impact

  • Semantic owner and earliest changed stage: MCP result delivery owns response-budget text (src/server/toolResult.ts, src/server/EvidenceMcpServer.ts). src/config/mcpResponseBudget.ts owns the stdio budget facts. src/server/toolResultEncoding.ts owns the reserved string limit versus Node's ceiling. src/mcpStartupPolicy.ts and src/mcpDoctor.ts own startup-deadline recovery. The packaged probe repeats that sentence because it cannot import the TypeScript module. src/domain/analysisErrorPresentation.ts owns the shared discovery and export sentences.
  • Contribution scope fit and linked maintainer decision: not applicable. Wording within the existing MCP delivery and doctor boundaries.
  • CLI and MCP/tool-catalog contract: tool and doctor failure text changes. No schema, catalog, or numeric limit change. docs/mcp-contracts.md now says the response-byte setting is read at process start and does not raise the reserved string limit or Node's ceiling.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged. Oversized results still keep an acknowledged Evidence reference when recording succeeds. The wire preview of an SDK diagnostic may be shorter than 256 characters when escaping would otherwise drop the error text; the retained record still holds the original result.
  • 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. Skill text was not changed.

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 added or updated: tests/conformance/contracts/mcpResponseBudget.test.ts, tests/boundary/mcp/largeToolResult.test.ts, tests/boundary/mcp/mcpDoctor.test.ts, tests/boundary/mcp/mcpStartupPolicy.test.ts, tests/boundary/mcp/analysisViewMcp.test.ts, plus the existing oversized-error delivery test. The quoted SDK diagnostic case in src/server/EvidenceMcpServer.test.ts is the regression for empty error content. The summary-overflow case now requires export_evidence_bundle and rejects a repeated detail: summary.
  • Base reproduction or other evidence: the analysis-view boundary test expected get_evidence_bundle and detail: summary and received only the generic CLI JSON sentence. String-ceiling text reported MCP_RESULT_STRING_LIMIT as Node's ceiling. The doctor saved a plain binary_session error when that call passed the deadline after the catalog. Source tests on 13de9bca9 failed both protocol revisions in expectEscapedSdkDiagnosticRetention because content was empty. An oversized summary's remediation stopped at CLI JSON (discussion_r4339174785).
  • User-visible CLI/MCP output (if applicable): an oversized complete bundle remediation includes get_evidence_bundle and detail: summary and REA's reserved single-string limit of <MCP_RESULT_STRING_LIMIT> plus Node's single-string ceiling of <MAX_STRING_LENGTH>. An oversized summary remediation includes export_evidence_bundle and caller-selected path, and does not repeat detail: summary. The doctor hang fixture (applied deadline 60000 ms) includes 60000 ms, no runtime override, and Codex startup_timeout_sec of 30 seconds is client guidance. A binary_session timeout after the catalog uses that same 60000 ms sentence. A quote-heavy SDK validation failure returns a resource_constraint JSON text body with evidence_reference.kind retained-evidence.
  • Remaining proof gaps: no separate live stdio capture beyond the in-memory MCP boundary tests. Moonshot compact presentation was not given a new failure. The production catalog doctor checks compare source-computed digests with this VM's already compiled server and were not re-run to green here. A string-length summary was not allocated at MAX_STRING_LENGTH; summary overflow uses the same export sentence for both constraints, and the string-ceiling facts are covered by the existing projection test.

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

  • Merged origin/main at d8a9673fc. The only conflict was src/domain/analysisErrorPresentation.ts: fixed-allowance recovery stays first, and transport overflow still uses the detail: summary discovery sentence.
  • Re-ran npm run check:fast after the merge (typecheck and lint succeeded).
  • npx vitest run tests/conformance/contracts/mcpResponseBudget.test.ts — 7 passed.
  • npx vitest run tests/boundary/mcp/largeToolResult.test.ts — 8 passed.
  • npx vitest run tests/boundary/mcp/mcpStartupPolicy.test.ts — 10 passed, including probe phase failures, the first-catalog overrun, and unrelated failures.
  • npx vitest run tests/boundary/mcp/mcpDoctor.test.ts -t "request-flow deadline|child lifecycle" — startup deadline, binary_session deadline, and unrelated request-flow failure passed.
  • npx vitest run tests/boundary/mcp/analysisViewMcp.test.ts — 21 passed, including the oversized dossier discovery case.
  • src/domain/fixedAllowanceRemediation.test.ts (8) and tests/boundary/providers/fixedAllowanceRecovery.test.ts (2) passed after the conflict resolution.
  • After 33923c55c: npm run check:fast — typecheck and lint succeeded.
  • npm run test:focused -- src/server/EvidenceMcpServer.test.ts tests/boundary/mcp/largeToolResult.test.ts tests/boundary/mcp/analysisViewMcp.test.ts tests/conformance/contracts/mcpResponseBudget.test.ts — 40 passed, including both SDK validation retention revisions.
  • After 30c6b4b6c: npm run check:fast — typecheck and lint succeeded.
  • npm run test:local -- src/server/EvidenceMcpServer.test.ts — 4 passed, including both public stdio SDK revisions.
  • npm run test:local -- tests/conformance/contracts/mcpResponseBudget.test.ts src/server/toolResultEncoding.test.ts — 17 passed.
  • npm run test:focused -- tests/boundary/mcp/largeToolResult.test.ts tests/boundary/mcp/toolResult.test.ts tests/boundary/mcp/analysisViewMcp.test.ts — 45 passed. largeToolResult was re-run after the export assertion (8 passed).
  • Static checks on 30c6b4b6c failed oxfmt --check in src/server/EvidenceMcpServer.ts (the fitted-preview return). CI required then failed because static was a failure and the lanes that need it were skipped. 4e2671b9e wraps that ternary. Behavior is unchanged.
  • After 4e2671b9e: npm run format:check — all matched files use the correct format.
  • npm run check:fast — typecheck and lint succeeded.
  • npm run test:focused -- src/server/EvidenceMcpServer.test.ts — 4 passed.

Real provider workflows were not required. These paths are MCP delivery, doctor, and startup-probe projection.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Callers that match the old "larger MCP response budget" sentence will see the named setting instead. Callers that treated MCP_RESULT_STRING_LIMIT as Node's ceiling will see both numbers. An oversized summary now names export_evidence_bundle instead of CLI JSON alone. Limits and configuration parsing are unchanged. A quote-heavy SDK diagnostic may now include a shorter diagnostic_preview than 256 characters; diagnostic_truncated stays true and the retained record still has the original error.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable. No provider behavior changed.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: not applicable. Recovery text does not add authority or retain new caller data.

Author readiness

Human owner: @morluto

  • 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.
Open in Web Open in Cursor 

Name REA_MCP_MAX_RESPONSE_BYTES, its effective value, the 10485760 byte
floor, and process restart when the stdio response budget is hit, and
state that the setting does not raise Node's string ceiling. Name fixed
MCP startup phase budgets when those deadlines fire, and keep Codex's
30 second startup figure as client guidance.

Co-authored-by: morluto <morluto@users.noreply.github.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-21T16:30:17.634227Z 30c6b4b 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e279a61b0

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/server/toolResult.ts Resolved
@greptile-apps

greptile-apps Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no outstanding blocking issue was identified.

Summary

The PR names MCP response limits and startup deadlines, improves recovery guidance, and keeps oversized SDK errors readable.

  • MCP response failures name the limit and a fitting recovery path.
  • Oversized SDK errors keep a readable wire message and retained reference.
  • MCP startup failures name the fixed deadline that expired.
  • JSON depth refusals name the fixed nesting limit.

Reviews (3) · Last reviewed commit: "style(mcp): format the SDK diagnostic pr..." · Reviewed by Greptile

Comment thread src/mcpDoctor.ts Resolved
Comment thread src/server/toolResult.ts Resolved
cursoragent and others added 2 commits October 21, 2026 16:02
Name REA's reserved string limit separately from Node's ceiling, restore
detail:summary discovery for an oversized complete evidence bundle, and
apply the doctor deadline sentence when binary_session itself times out.

Co-authored-by: morluto <morluto@users.noreply.github.com>
Keep detail:summary discovery, the reserved-versus-Node string ceiling,
the binary_session doctor deadline, and startup probe failure coverage
alongside main's fixed-allowance remediation.

Co-authored-by: morluto <morluto@users.noreply.github.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 13de9bca98

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/server/toolResult.ts Resolved
cursoragent and others added 2 commits October 21, 2026 16:24
Quoted SDK validation diagnostics expand when recovery JSON is escaped
into MCP text. Shorten only that preview so the retained-evidence
reference still arrives as parseable error content.

Co-authored-by: morluto <morluto@users.noreply.github.com>
An oversized get_evidence_bundle summary no longer repeats detail: summary.
export_evidence_bundle still writes the retained bundle outside one MCP frame,
including when a larger byte budget cannot raise the string ceiling.

Co-authored-by: morluto <morluto@users.noreply.github.com>
oxfmt rejected the fitted-preview ternary in EvidenceMcpServer.ts, which failed Static checks and the CI required gate.

Co-authored-by: morluto <morluto@users.noreply.github.com>
@morluto
morluto merged commit bdf0be8 into main Oct 21, 2026
46 of 48 checks passed
@morluto
morluto deleted the cursor/mcp-response-startup-ceilings-8a8c branch October 21, 2026 21:48
@morluto morluto added area: mcp MCP server, transport, and tool registration bug Something isn't working labels Nov 23, 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 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants