Skip to content

fix(test): keep the fake Inspector's discovery sockets alive - #8609

Closed
XiaoBinGan wants to merge 1 commit into
morluto:mainfrom
XiaoBinGan:fix/v8-mcp-inspector-keepalive
Closed

XiaoBinGan wants to merge 1 commit into
morluto:mainfrom
XiaoBinGan:fix/v8-mcp-inspector-keepalive

Conversation

@XiaoBinGan

Copy link
Copy Markdown
Contributor

Summary

tests/boundary/mcp/javascriptRuntimeObservationMcp.test.ts fails on current main at the direct-observation assertion. The second CDP connection never opens — endpoint_unreachable, cause ECONNRESET — so the case stops before it can compare the direct evidence ID against the MCP one.

The cause is not the observation path. 7bcefead6 (#8573) added a get_evidence_bundle call to that test before the direct observation, and the first such call in a process spends ~8.4s compiling the tool output schema inside the MCP client. That blocks the event loop synchronously; the fake Inspector's in-process HTTP server keeps Node's 5s keep-alive default, retires the pooled discovery socket while the loop is blocked, and the provider's next CDP upgrade reuses the retired socket and is reset.

This raises the fixture server's keep-alive window so an in-process caller that blocks the loop cannot retire a socket a later caller still holds. The fake is not modelling an idle-connection policy, so there is no reason for it to enforce Node's default there.

This is the third and last independent failure blocking main; the formatting half is #8592 and the Frida fixture half is #8595 / #8596. All three must land for main to be green again. I raised this diagnosis in #8596 first and am sending it because it is the one that had no fix.

Problem and expected behavior

On a pristine main at d3ab0faf5:

$ node node_modules/vitest/vitest.mjs run tests/boundary/mcp/javascriptRuntimeObservationMcp.test.ts
FAIL ... lists and observes one target as retained Evidence
AssertionError: expected false to be true
 ❯ tests/boundary/mcp/javascriptRuntimeObservationMcp.test.ts:292:23  (direct.ok)

BrowserObservationError { reason: "endpoint_unreachable", cause: Error: read ECONNRESET }

Expected: 3 passed. That is now the result, 3/3 for three consecutive runs.

Change and scope

One line plus a comment in tests/fixtures/inspector/fakeV8Inspector.ts:

http.keepAliveTimeout = 120_000;

The http server there serves /json/version and /json/list for the fixture's loopback endpoint. Nothing else in the fixture changes; no assertion, timeout, or stub value is touched, and the test itself is unmodified.

Contract and boundary impact

  • Semantic owner and earliest changed stage: none — test fixture only.
  • Contribution scope fit and linked maintainer decision: not applicable; restores a gate that is currently failing on main.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable — no target interaction; the fixture is a real loopback HTTP/WebSocket fake that establishes no real-provider behaviour.
  • Generated metadata, package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).

  • Documentation or usability only; no target interaction.

Evidence and regression coverage

  • Tests added or updated: none. The existing 3 cases in javascriptRuntimeObservationMcp.test.ts execute again.
  • Base reproduction: 4/4 runs fail on unmodified d3ab0faf5; 3/3 pass with this change.

Mechanism evidence, all measured on this host with Node 24.22.1:

probe result
get_evidence_bundle first call 8490ms; second and third calls 1ms each
setInterval(100ms) ticks during that first call 0
node --cpu-prof top self-time @modelcontextprotocol/client Ajv addNames 2.3s, compileSchema 1.0s, codegen
replace the block with a synchronous 8s spin fails 2/2 (reproduces)
replace the block with async 6s / 10s / 15s delays passes 5/5 (does not reproduce)
reorder: bundle assertions after the direct observation passes
/json/version, /json/list, and a raw CDP WebSocket connect immediately before the direct observation all succeed, so discovery state is intact and only the pooled socket is dead
  • User-visible CLI/MCP output: not applicable.
  • Remaining proof gaps: the 8.4s synchronous compile itself is in the MCP client library, outside this repository, and this PR does not make it go away — it only stops the fixture from treating a blocked loop as an idle connection. If the underlying cost is worth chasing, it is a separate question and I have not investigated it further.

Validation performed

  • node node_modules/vitest/vitest.mjs run tests/boundary/mcp/javascriptRuntimeObservationMcp.test.ts — 3 passed, 3 consecutive runs (4 failed on base)
  • node scripts/run-typescript.mjs --noEmit — exit 0
  • npx oxfmt --check tests/fixtures/inspector/fakeV8Inspector.ts — All matched files use the correct format.
  • all six other suites that use this fixture — unchanged. Two of them (javascriptRuntimeObservation.test.ts, javascriptRuntimeUnresolvedTarget.test.ts) still fail, but they fail identically with the change reverted, so this PR does not affect them.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable — loopback fixture only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none — binds to loopback and requires no target.

Author readiness

Human owner: @XiaoBinGan

  • 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

`tests/boundary/mcp/javascriptRuntimeObservationMcp.test.ts` fails on main at
the direct-observation assertion with `endpoint_unreachable` /
`ECONNRESET`, so the second CDP connection never opens and the case stops
before it can compare the two evidence IDs.

The cause is not the observation path. The first `get_evidence_bundle` call
in a process - which that test now performs before the direct observation -
spends ~8.4s compiling the tool output schema inside the MCP client. Measured:

    BUNDLE-CALL 1 ms= 8490
    BUNDLE-CALL 2 ms= 1
    setInterval(100ms) ticks during call 1: 0

`node --cpu-prof` attributes the time to `@modelcontextprotocol/client`'s Ajv
provider (`addNames` 2.3s, `compileSchema` 1.0s, plus codegen), so the event
loop is blocked synchronously, not waiting on I/O.

The fake Inspector's in-process HTTP server keeps Node's 5s keep-alive
default. While the loop is blocked that timeout expires, the server retires
the pooled discovery socket, and the provider's next CDP upgrade reuses the
retired socket and is reset.

Evidence that this is the mechanism rather than the assertions:

- replacing the block with a synchronous 8s spin reproduces the failure (2/2);
- replacing it with async 6s / 10s / 15s delays does not (5/5 pass);
- the fixture's CDP endpoint and WebSocket URL both answer correctly right
  before the direct observation, so discovery state is intact.

Raise the fixture server's keep-alive window so an in-process caller that
blocks the loop cannot retire a socket a later caller still holds. The fake
is not modelling an idle-connection policy, so it has no reason to enforce
Node's default there.

The MCP case now passes 3/3 for three consecutive runs. It fails 4/4 on
unmodified main. The other five files that use this fixture are unchanged: the
two that still fail (`javascriptRuntimeObservation.test.ts`,
`javascriptRuntimeUnresolvedTarget.test.ts`) fail identically with and without
this change, so they are unrelated.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 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 ✅ Completed 2026-11-01T23:53:26.213437Z 1555f82 PR opened
ℹ️ 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 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The fixture-only change appears safe to merge.

Summary

Raises the fake Inspector’s HTTP keep-alive timeout to 120 seconds so discovery sockets survive synchronous work between test calls.

  • The fake Inspector keeps discovery sockets alive through long test pauses.

Reviews (1) · Last reviewed commit: "fix(test): keep the fake Inspector's dis..." · Reviewed by Greptile

@XiaoBinGan

Copy link
Copy Markdown
Contributor Author

Folding this into #8592, which now carries both remaining fixes. Neither PR can go green alone: every PR's merge ref inherits both #8573 failures plus the Frida fixture one, so splitting them just deadlocks both. #8592 + your #8596 is the pair that makes main green — or #8592 alone if you'd rather I keep the Frida fixture change out of it.

@XiaoBinGan XiaoBinGan closed this Nov 1, 2026
@morluto morluto added area: tests Test suite and verification bug Something isn't working labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: tests Test suite and verification bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants