Skip to content

feat(config): make the regex matching deadline configurable - #6267

Merged
morluto merged 3 commits into
mainfrom
cursor/regex-matching-deadline-b35c
Oct 22, 2026
Merged

morluto merged 3 commits into
mainfrom
cursor/regex-matching-deadline-b35c

Conversation

@morluto

@morluto morluto commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

Part of #6176. The supervised ECMAScript regex matching deadline is now REA_REGEX_MATCHING_DEADLINE_MS. Unset still uses 5000 ms. This does not cover the issue's later decoder-heap or MCP startup budgets.

Problem and expected behavior

MATCHING_DEADLINE_MS was a fixed 5000 ms, and capability, limitation, and recovery text said this release has no runtime override. Callers need a named setting whose default is that constant, with invalid values refused and recovery that names the setting, effective milliseconds, source (default or setting), default, floor, and maximum.

A caller override such as REA_REGEX_MATCHING_DEADLINE_MS=10000 rea setup was validated and then omitted from setup-created MCP registrations, so the launched server returned to 5000 ms.

Change and scope

src/config/regexMatchingDeadline.ts owns the setting. Startup (parseConfig) and doctor (parseEnvironment) resolve it with the same schema. The effective deadline is stored on AppConfig and passed into Hopper and Kuna, which pass it to RegexMatcher. A direct KunaProvider resolves the selected environment instead of ambient process.env.

Setup now keeps REA_REGEX_MATCHING_DEADLINE_MS in SELECTED_REGISTRATION_SETTINGS, with the other caller-selected registration settings. A present value is copied into the generated registration. An unset value is omitted.

The floor is 1 ms. The maximum is 2147483647 ms, the largest delay Node schedules exactly; a larger setTimeout delay is clamped to 1 ms, so it is refused rather than left unbounded. Zero, negative, non-decimal, and out-of-range values are configuration_invalid and do not fall back to 5000. The schema does not trim whitespace.

Follow the contribution scope. This is an ordinary configuration of an existing matching deadline. It does not add target execution, injection, mutation, or protection recovery. Maintainer scope decision: not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/config/regexMatchingDeadline.ts parses the setting; parseConfig resolves it before providers match. explicitSetupRegistrationEnvironment preserves a caller-selected value when setup writes a registration.
  • Contribution scope fit and linked maintainer decision: existing regex matching only; not applicable.
  • CLI and MCP/tool-catalog contract: search_procedures and search_strings descriptions name REA_REGEX_MATCHING_DEADLINE_MS, the 5000 ms default, and the 2147483647 ms maximum. Capability and deadline failures name the effective value and source.
  • Provider, bridge, target-format, or platform compatibility: Hopper and Kuna share the deadline. The worker heap flags are unchanged and do not raise it.
  • Evidence, artifact, provenance, or reconstruction contract: deadline failures add matching_deadline_source beside matching_deadline_ms.
  • 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): tool descriptions changed in source contracts. No authored skill text claimed the deadline had no override.

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; doctor and client-registration rejection; Hopper/Kuna capability text; worker timer armed at 10000 ms; a 100 ms deadline stops a slow match; the Kuna boundary probe still waits the unset 5000 ms deadline and a selected REA_REGEX_MATCHING_DEADLINE_MS=200 stops early. Ambient process.env does not override the selected environment. The Kuna capability assertion restores stubbed environment in finally. Setup-host state includes 10000 when set and omits the key when unset. Public Codex and Kimi setup writes REA_REGEX_MATCHING_DEADLINE_MS=10000 and still omits REA_UNRELATED_MARKER.
  • Base reproduction or other evidence: on main the deadline constant is 5000 and recovery says there is no runtime override. The unset Kuna probe still reports matching_deadline_ms: 5000 and takes about 5.4 s. Before this fix, SELECTED_REGISTRATION_SETTINGS did not include the deadline, so setup-created registrations dropped the override.
  • User-visible CLI/MCP output (if applicable): a deadline failure for the default says The effective REA_REGEX_MATCHING_DEADLINE_MS value is 5000 ms (source default; default 5000 ms, floor 1 ms, maximum 2147483647 ms). Set REA_REGEX_MATCHING_DEADLINE_MS in the environment that starts REA to a positive decimal integer from 1 to 2147483647, then restart REA. A 10000 ms setting uses source setting and 10000 ms.
  • Remaining proof gaps: no real Hopper or Kuna binary was used. The Kuna probe uses the fake Kuna executable and the production regex worker.

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:local -- src/config/regexMatchingDeadline.test.ts src/application/Doctor.test.ts — 74 passed.
  • npm run test:local -- src/config/regexMatchingDeadline.test.ts src/process/RegexMatcher.test.ts src/hopper/HopperProvider.test.ts — parser, matcher, and Hopper provider tests passed (the first parser run found and fixed schema/assertion failures; the rerun passed).
  • npm run check:fast — typecheck and lint passed (rerun on this fix; passed).
  • npm run format:check — passed on the previous head. This fix was covered by check:fast lint.
  • npm run test:focused -- tests/boundary/process/regexMatcher.test.ts tests/boundary/providers/kuna/kunaRegexSearch.test.ts tests/boundary/filesystem/clientConfigurationEnvironment.test.ts src/config/regexMatchingDeadline.test.ts src/process/RegexMatcher.test.ts — 107 passed, 10 skipped. Unset Kuna deadline probes took 5409 ms and 5356 ms. REA_REGEX_MATCHING_DEADLINE_MS=200 on the selected environment finished in 568 ms and reported source setting.
  • npm run test:local -- src/config/regexMatchingDeadline.test.ts src/setupEnvironment.test.ts — 23 passed.
  • npm run test:focused -- tests/acceptance/setup/registrationRuntimeEnvironmentCli.test.ts — 15 passed, 1 skipped. Codex and Kimi setup preserved 10000.

Compatibility, safety, and release

  • Breaking changes or migration steps: none for an unset environment. The deadline remains 5000 ms. User-facing text no longer says the deadline has no runtime override; it names REA_REGEX_MATCHING_DEADLINE_MS. Invalid values that were previously ignored, because the variable was unread, now fail configuration. An existing registration created before this fix does not gain the override until setup runs again with the setting present.
  • Real Hopper/Ghidra, browser, or OS coverage: not run. Deadline behavior was measured with the production regex worker and the fake Kuna probe.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the worker is still terminated when the deadline fires. The heap request is unchanged. A longer deadline only extends that existing supervision.

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_REGEX_MATCHING_DEADLINE_MS defaults to 5000 ms and refuses values
outside 1..2147483647. Recovery and capability text name the effective
deadline, its source, and how to change the setting.

Co-authored-by: morluto <[email protected]>
@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-22T07:15:02.607743Z
We couldn’t complete this review. Comment @codex review to try again.
609f0be 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: ae96ddbe3e

ℹ️ 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/config/environment.ts 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 blocking issue remains.

Summary

Makes REA_REGEX_MATCHING_DEADLINE_MS control the supervised regex deadline. Unset keeps 5000 ms; invalid values are rejected.

  • Hopper and Kuna regex searches use the configured matching deadline.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  E["Selected environment"] --> V["Shared deadline schema"]
  V --> C["AppConfig"]
  C --> H["Hopper"]
  C --> K["Kuna"]
  H --> W["Regex worker timer"]
  K --> W
  E --> S["Setup selects registration settings"]
  S --> R["Check merged client environment"]
  R --> P["Save client registration"]
Loading

Reviews (2) · Last reviewed commit: "test(config): restore a stubbed regex ma..." · Reviewed by Greptile

@prasad2512 prasad2512 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a very thorough and well-designed addition. Making the regex matching deadline configurable while strictly enforcing boundaries avoids accidental worker starvation on large binaries.

A few technical observations and suggestions:

1. Great Defensive Boundary on 32-bit Max Timeout

The decision to enforce MAXIMUM_REGEX_MATCHING_DEADLINE_MS = 2_147_483_647 (signed 32-bit limit) is spot-on. In Node.js, values exceeding 2^31 - 1 trigger integer overflow and cause setTimeout to clamp to 1 ms, which would immediately fail every regex query. Enforcing this explicitly in regexMatchingDeadline.ts rather than letting it fail silently is great defensive engineering.

2. Idiomatic Timer Spy in RegexMatcher.test.ts

In src/process/RegexMatcher.test.ts:

const delays: number[] = [];
const original = global.setTimeout;
global.setTimeout = ((handler, timeout, ...args) => {
  if (typeof timeout === "number") delays.push(timeout);
  return original(handler, timeout, ...args);
}) as typeof setTimeout;
try {
  // ...
} finally {
  global.setTimeout = original;
}

Suggestion: Rather than manually monkey-patching global.setTimeout with a cast as typeof setTimeout, we can use Vitest's built-in vi.spyOn (similar to V8InspectorProvider.partial.test.ts):

const timeoutSpy = vi.spyOn(globalThis, "setTimeout");
try {
  await matchRegexValues({
    operation: "search_procedures",
    pattern: "^a",
    caseSensitive: true,
    values: ["a"],
    deadline: { deadlineMs: 10_000, source: "setting" },
  });
  expect(timeoutSpy).toHaveBeenCalledWith(expect.any(Function), 10_000);
  expect(timeoutSpy).not.toHaveBeenCalledWith(expect.any(Function), 5_000);
} finally {
  timeoutSpy.mockRestore();
}

This avoids global object mutation risks during parallel worker runs and removes manual type casting.

3. Whitespace Resiliency in Environment Parsing

In regexMatchingDeadlineMsSchema:

const decimalInteger = /^[1-9]\d*$/u;

If an operator exports REA_REGEX_MATCHING_DEADLINE_MS=" 5000 " with accidental leading/trailing whitespace (common in .env files or shell profiles), the current regex rejects it with ConfigurationError. Consider adding .trim() before matching decimalInteger to make environment parsing slightly more forgiving, or explicitly note the zero-whitespace expectation in configuration docs.

Overall, the propagation through AppConfig, HopperRegexSearch, KunaQueryWork, and capability text diagnostics is exceptionally clean!

cursoragent and others added 2 commits October 22, 2026 07:14
Setup validated REA_REGEX_MATCHING_DEADLINE_MS but left it out of the
selected registration environment, so a caller override never reached
the launched server and matching fell back to 5000 ms.

Co-authored-by: morluto <[email protected]>
Kuna deadline assertions now unstub the environment in finally, so a
thrown construction or expectation cannot leave the setting stubbed.

Co-authored-by: morluto <[email protected]>
@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 c7efd3a into main Oct 22, 2026
42 of 44 checks passed
@morluto
morluto deleted the cursor/regex-matching-deadline-b35c branch October 22, 2026 09:10
kaoru0822-kitauji added a commit that referenced this pull request Oct 25, 2026
* fix(mcp)!: return a compact binary_session status by default

binary_session {} with no target open returned about 66 KB, most of it
provider rejection diagnostics and candidate capability sets that the
skill's recovery flow re-reads on every retry. 6.8.0 grew it by 21%
because the shared regex capability limitation began repeating setting
bounds and step-by-step recovery for every search operation of every
provider (#6099, #6267, #6301, #7049) and IDA gained that limitation for
its two search operations (#4862).

The regex limitation now states the effective deadline and heap, their
sources and where to change them; the deadline and heap errors keep the
full recovery. binary_session gains detail: summary (default) or
complete. The summary keeps open state, target identity, the binding,
route capabilities, run, activity and health status, each candidate's
availability and target-support status, code and reason, and every
tool's availability, reason, remediation and modes, and lists the
fields it leaves out in omitted_fields. Complete detail returns the
previous shape. The CLI capabilities and providers commands keep
complete provider facts through the same application projection.

BREAKING CHANGE: binary_session {} no longer returns
analysis_provider_candidates[].availability.diagnostics,
target_support.diagnostics or capabilities, or tool_availability group
surface, effects and annotations. Pass {"detail": "complete"} to get
them.

Fixes #7109

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(mcp): key binary_session output fields by detail

The output schema accepted detail: "complete" with summary candidates or
tool groups, and a summary without omitted_fields, so detail did not
tell callers which fields existed. Each session kind is now crossed
with a detail-specific shape: a summary requires omitted_fields and
summary-only candidates and tool groups; complete requires diagnostics,
candidate capabilities and static tool flags and forbids omitted_fields.
Both the canonical schema and the SDK-validated advertised schema reject
mismatched shapes.

The verifier helper accepts summary candidates only for a validated MCP
summary; CLI provider output still requires candidate capabilities.
Regex limitation tests check values, sources and setting names instead
of whole sentences.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@morluto morluto added area: setup Setup, packaging, upgrade, install, Doctor, and client 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: setup Setup, packaging, upgrade, install, Doctor, and client registration enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants