Skip to content

feat(mcp): make MCP startup phase budgets configurable - #6304

Merged
morluto merged 3 commits into
mainfrom
cursor/mcp-startup-budgets-d806
Oct 22, 2026
Merged

morluto merged 3 commits into
mainfrom
cursor/mcp-startup-budgets-d806

Conversation

@morluto

@morluto morluto commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

Part of #6176. The MCP initialize, tools/list, first-catalog, and doctor phase budgets are now named settings. Unset behavior stays 15000, 5000, 20000, and 30000 ms. Codex's 30 second startup figure stays client guidance.

Problem and expected behavior

Those four phase budgets were fixed, and recovery said this release has no runtime override. Callers need named settings whose defaults are those constants. Invalid values must fail configuration and name the setting. They must not fall back to the default.

Unset behavior stays the current constants. A value from 1 to 2147483647 ms is the effective budget. Any other value fails startup, doctor, rea mcp doctor, and client-registration configuration and names the setting. Setup copies a caller-selected value through SELECTED_REGISTRATION_SETTINGS.

Recovery names the setting, the effective milliseconds, the source (default or setting), the default, the floor, the maximum, and how to change it. Doctor recovery still says Codex startup_timeout_sec of 30 seconds is client guidance and that REA does not enforce that figure as the doctor deadline.

REA_MCP_FIRST_CATALOG_BUDGET_MS bounds the whole initialize plus tools/list startup, including while either request is still pending. A value lower than a phase budget must stop that pending request. It must not wait until the longer phase timeout returns.

Change and scope

src/config/mcpStartupBudgets.ts owns the four settings. Startup (parseEnvironment / parseConfig) and doctor use that schema. rea mcp doctor resolves the same parser from its selected environment before it starts a child. An invalid setting returns an unhealthy check named for that setting and does not launch the child.

The packaged startup probe reads resolveMcpStartupProbePolicy from the environment it is given, so a selected value is not ignored. The probe's recovery sentence is duplicated in scripts/lib/mcp-startup-probe.mjs because that script cannot import the TypeScript module; a test requires the two sentences to be identical. A synthetic probe budget carries its own source, so a 200 ms test budget is source setting and still names the real default.

The probe measures one first-catalog deadline from the same instant as the phase durations. Each in-flight initialize or tools/list request uses the shorter of that phase's budget and the time still left. The recovery names that shorter bound. The deadline also rejects the probe when the SDK timeout has not started yet, and the existing close path stops the child. A completed run still fails when the measured total exceeds the first-catalog budget. The module profiler is unchanged: it has no first-catalog budget.

This branch includes current main, including REA_REGEX_WORKER_HEAP_REQUEST_MIB. Registration, environment parsing, and the related tests keep that setting together with the four phase budgets. Doctor timeout recovery still uses the phase budget, and it is attached only for an owned abort or an SDK request timeout.

The floor is 1 ms. The maximum is 2147483647 ms, the largest delay Node schedules exactly. A larger setTimeout or SDK timeout is clamped to 1 ms, so it is refused. Zero, negative, non-decimal, and out-of-range values are configuration_invalid.

codexStartupTimeoutSeconds (30), kimiStartupTimeoutMs (30000), toolOperationHeadroomMs (120000), and doctorStderrBytes (64 KiB) stay fixed. They are not settings.

Follow the contribution scope. This is configuration of existing MCP startup admissions. It does not add a provider or a capability that executes, injects, mutates, or recovers a target. Maintainer scope decision: not applicable. The product decision to make these ceilings settings is recorded in #6176.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/config/mcpStartupBudgets.ts parses the settings; parseEnvironment rejects them before provider startup. explicitSetupRegistrationEnvironment preserves a caller-selected value when setup writes a registration. runProductionMcpDoctor resolves them again before connecting. scripts/lib/mcp-startup-probe.mjs owns enforcement of those budgets on the packaged probe.
  • Contribution scope fit and linked maintainer decision: existing MCP startup budgets only; not applicable.
  • CLI and MCP/tool-catalog contract: no tool schema change. rea mcp doctor and the packaged startup probe name the effective budget, source, default, floor, and maximum. Invalid settings fail the doctor report before a child starts.
  • Provider, bridge, target-format, or platform compatibility: none. Codex's 30 second startup timeout is unchanged client guidance.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): none.
  • 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): client-configuration docs name the four settings. No tool catalog text 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: parser and startup rejection, including every invalid setting named together; doctor and client-registration rejection; setup-host state includes 16000, 6000, 21000, and 31000 when set and omits the initialize key when unset; public Codex and Kimi setup writes those values and still omits REA_UNRELATED_MARKER. Probe timeouts of 200 ms and a 1 ms first-catalog budget name source setting and the real default. A hanging initialize with a 250 ms first-catalog budget and an 8000 ms initialize budget names the first-catalog setting and returns before that initialize budget. A child that finishes initialize and then hangs, with an 800 ms first-catalog budget and an 8000 ms tools/list budget, leaves the initialize marker and names the first-catalog setting. rea mcp doctor with REA_MCP_DOCTOR_DEADLINE_MS=2000 and no caller deadline fired at that budget. 0 for initialize and doctor returns unhealthy checks named for those settings and does not start the missing child. Codex's 30 second constant remains 30 after an initialize override.
  • Base reproduction or other evidence: on main the phase budgets are constants and recovery says there is no runtime override. Before this fix, the probe checked the first-catalog budget only after initialize and tools/list both returned, so a pending phase waited for its own longer timeout. The doctor hang with an explicit 60000 ms caller deadline still reports 60000 ms, now with source setting and default 30000 ms.
  • User-visible CLI/MCP output (if applicable): the default doctor recovery says The effective REA_MCP_DOCTOR_DEADLINE_MS value for the MCP doctor startup deadline is 30000 ms (source default; default 30000 ms, floor 1 ms, maximum 2147483647 ms). Set REA_MCP_DOCTOR_DEADLINE_MS in the environment that starts REA to a positive decimal integer from 1 to 2147483647, then restart REA. It then says Codex startup_timeout_sec of 30 seconds is client guidance. A selected 2000 ms deadline uses source setting and 2000 ms. A probe that exceeds the first-catalog budget names REA_MCP_FIRST_CATALOG_BUDGET_MS and the effective milliseconds.
  • Remaining proof gaps: the packaged verify-package workflow was not executed. The probe tests use the production probe against the fixture child. Windows was not executed. A budget above the default was checked through the parser, setup registration, and the 60000 ms doctor deadline, not by waiting out a full 30 second packaged startup.

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

  • After merging origin/main (af924ca4b): npm run check:fast — typecheck and lint passed (2 tasks, 4.235s).
  • npm run format:check — all matched files use the correct format.
  • npm run test:local -- src/config/mcpStartupBudgets.test.ts src/application/Doctor.test.ts src/setupEnvironment.test.ts — 90 passed.
  • npm run test:focused -- tests/boundary/mcp/mcpStartupPolicy.test.ts tests/boundary/mcp/mcpDoctor.test.ts tests/boundary/filesystem/clientConfigurationEnvironment.test.ts tests/acceptance/setup/registrationRuntimeEnvironmentCli.test.ts — 82 passed, 11 skipped. The pending tools/list first-catalog case completed in 808 ms. REA_MCP_DOCTOR_DEADLINE_MS=2000 completed in 1923 ms. Remote timeout prose did not receive doctor deadline guidance. Codex and Kimi setup preserved the phase budgets and REA_REGEX_WORKER_HEAP_REQUEST_MIB.

Compatibility, safety, and release

  • Breaking changes or migration steps: none for an unset environment. The four budgets remain 15000, 5000, 20000, and 30000 ms. User-facing text no longer says those phase budgets have no runtime override; it names the setting. Invalid values that were previously ignored, because the variables were unread, now fail configuration. An existing registration created before this fix does not gain an override until setup runs again with the setting present. Codex's 30 second startup timeout is unchanged. A selected first-catalog budget that is shorter than a phase budget now stops a pending probe request at the first-catalog deadline.
  • Real Hopper/Ghidra, browser, or OS coverage: not run. Doctor and probe behavior was measured on Linux Node 22 with the production doctor and the fixture MCP child.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: a longer budget only extends the existing doctor and probe timers. A shorter first-catalog budget now stops the packaged probe's child while initialize or tools/list is pending. It does not change tool-operation headroom, the doctor stderr cap, or client startup timeouts.

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 

REA_MCP_INITIALIZE_BUDGET_MS, REA_MCP_TOOLS_LIST_BUDGET_MS,
REA_MCP_FIRST_CATALOG_BUDGET_MS, and REA_MCP_DOCTOR_DEADLINE_MS keep
today's defaults and refuse values outside 1 to 2147483647 ms. Codex's
30 second startup figure stays client guidance.

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

chatgpt-codex-connector Bot commented Oct 22, 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 ⚠️ Failed 2026-10-22T15:48:40.867186Z
We couldn’t complete this review. Comment @codex review to try again.
af924ca 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: 9256f1d260

ℹ️ 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 scripts/lib/mcp-startup-probe.mjs Resolved
@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable new defects or rule violations were established.

Summary

Makes four MCP startup budgets configurable while preserving their defaults.

  • Callers can set four MCP startup budgets by name.
  • The packaged probe stops startup work when its first-catalog deadline expires.
  • Setup carries chosen MCP startup budgets into client registrations.

No actionable new issues were found. The previous and current commits have different merge bases with the target, so the full PR diff was reviewed. No previous review threads were supplied. Tests were inspected but not run. Remote supersession status could not be checked because GitHub access was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Selected environment] --> B[Parse four budgets]
  B --> C{Valid?}
  C -->|No| D[Report named configuration errors]
  C -->|Yes| E[Doctor uses doctor deadline]
  C -->|Yes| F[Probe starts first-catalog timer]
  F --> G[Initialize within remaining time]
  G --> H[List tools within remaining time]
  F -->|Deadline expires| I[Fail probe and close child]
  H --> J[Check measured durations]
Loading

Reviews (3) · Last reviewed commit: "Merge origin/main into cursor/mcp-startu..." · Reviewed by Greptile

The packaged startup probe applied each phase timeout on its own and
checked REA_MCP_FIRST_CATALOG_BUDGET_MS only after both requests
finished. A shorter first-catalog budget now clamps the in-flight
request and cancels it from one deadline measured at startup.

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

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Keep the MCP startup budget settings and the first-catalog deadline.
Take the regex worker heap setting, and attribute doctor timeouts from
owned abort and SDK timeout facts.

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

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@morluto
morluto merged commit 584937c into main Oct 22, 2026
39 of 43 checks passed
@morluto
morluto deleted the cursor/mcp-startup-budgets-d806 branch October 22, 2026 15:54
@morluto morluto mentioned this pull request Oct 25, 2026
3 tasks done
@morluto morluto added area: mcp MCP server, transport, and tool registration enhancement New feature or request 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 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants