Skip to content

test(core): crashable stdio fixture + mid-session crash reconciliation tests - #2598

Merged
cliffhall merged 3 commits into
v2/mainfrom
v2/chore/2437-crash-reconciliation-fixture
Oct 5, 2026
Merged

cliffhall merged 3 commits into
v2/mainfrom
v2/chore/2437-crash-reconciliation-fixture

Conversation

@cliffhall

@cliffhall cliffhall commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Closes #2437

What changed

Fixture: test-servers/src/test-server-stdio.ts

The stdio test server now accepts --crashable (via getCrashableTestMcpServerCommand()). In that mode it serves the default config plus:

  • crash_server (createCrashServerTool()), which exits the process at a point the test chooses:
    • respond: false (the default) exits without answering, so the call and anything else in flight is still outstanding when the process dies.
    • respond: true answers first and exits delayMs later, so the crash lands on an idle session.
    • stderr writes a message before exiting. The exit waits for stderr and stdout to flush first, because pipe writes are async on macOS.
  • collect_elicitation and collect_sample, so a test can have a peer request pending at the moment of the crash.

The tool exists only on the spawned stdio entry and is deliberately absent from the presets: it calls process.exit, so wiring it into an in-process server would end the test runner.

Tests: clients/web/src/test/integration/mcp/inspectorClient-crash-reconciliation.test.ts

These drive a real process death through the onclose teardown route in attachTransportListeners. Until now that route was only reached by unit tests calling onclose on a fake transport. Cases:

  • Idle crash: status settles to disconnected and disconnect fires exactly once. A follow-up disconnect() does not announce it again.
  • Call in flight: the call rejects with Connection closed.
  • Pending elicitation / pending sampling: the queue is cleared, and its …Change([]) event fires before disconnect. A disconnect listener sees both queues empty.
  • Stderr on the way down: the server's dying words are captured.
  • Reconnect: the same client reconnects to a fresh process and can be crashed and reconciled again. The crash route leaves the transport object cached, and this confirms the SDK's stdio transport restarts through it.

Docs: the test-servers skill (the spawned-stdio section said no variant could be selected) and docs/test-servers.md.

Not covered

Verification

  • 15/15 consecutive runs of the new file pass.
  • Mutation check: deleting clearAndAnnouncePendingPeerRequests() from onclose fails the elicitation and sampling cases.
  • npm run local:gate is green. It was run with the sandbox's HTTP(S)_PROXY variables unset: with them set, 18 tests in server-extra-coverage and node/transport fail with Proxy response (502) … HTTP Tunneling, and they all pass once the variables are unset. That is an environment problem unrelated to this change.

🤖 Generated with Claude Code

… reconciliation

The transport `onclose` route in InspectorClient — settle the status, drop
and announce queued sampling/elicitation requests before `disconnect`,
reject what we asked the server, fire `disconnect` once — was only reached
by unit tests calling `onclose` on a fake transport.

The stdio test server now takes `--crashable`
(`getCrashableTestMcpServerCommand()`), which adds a `crash_server` tool
that exits the process at a point the test picks: with the call in flight,
or after answering on an idle session, optionally writing to stderr first.
It lives only on the spawned stdio entry because it calls `process.exit`.

The new integration suite drives a real process death through: idle
crash, in-flight call rejection, pending elicitation and sampling cleared
and announced before `disconnect`, stderr dying words captured, and
reconnecting the same client to a fresh process.

Closes #2437

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
@cliffhall cliffhall added the v2 Issues and PRs for v2 label Oct 5, 2026
@cliffhall cliffhall linked an issue Oct 5, 2026 that may be closed by this pull request
2 tasks done
@cliffhall
cliffhall requested a balanced review from Copilot October 5, 2026 11:44

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

The response-first crash mode can exit before stdout flushes, making idle-crash behavior timing-dependent.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds a crashable stdio fixture and integration coverage for real mid-session process failures.

Changes:

  • Adds configurable crash behavior to the stdio test server.
  • Tests teardown, pending requests, stderr capture, and reconnection.
  • Documents the new fixture mode.
File Description
test-servers/​src/​test-server-stdio.ts Adds the crashable server variant and tool.
clients/​web/​src/​test/​integration/​mcp/​inspectorClient-crash-reconciliation.test.ts Exercises crash reconciliation through a real subprocess.
docs/​test-servers.md Documents crashable stdio usage.
.claude/​skills/​test-servers/​SKILL.md Updates fixture-running guidance.

Comment thread test-servers/src/test-server-stdio.ts Resolved
respond: true exited on a timer without waiting for the answer it had
just written to stdout, so on a platform with asynchronous pipe writes
(macOS) the process could die before the client received it — turning
the idle-session crash back into a crash with the call in flight. Put an
empty-write barrier on stdout ahead of the exit, as stderr already had.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 1: 1 finding, fixed in 5ef0a06.

  • Wait for stdout to flush before exiting in respond mode: fixed. crash_server now puts an empty-write flush barrier on stdout before process.exit, so the respond: true answer can't be lost on platforms with async pipe writes. Replied in the thread.

There was nothing in Suppressed comments. local:gate is green again. Requesting round 2.

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

The advertised custom exit-code behavior lacks coverage, and one source comment is outdated.

Review effort: Balanced
Findings: None

Resolved since last review (1)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Add coverage for non-default crash_server exit codes

test-servers/​src/​test-server-stdio.ts:89

The new exitCode branch is not exercised by the crash-reconciliation suite: every crash_server call omits it, so all subprocesses still exit with the default code. Because this is an advertised fixture control, a regression that ignores or mishandles a requested code would pass. Add a subprocess-level test that invokes a non-default code and asserts the child's exit status, or remove the unsupported option.

Low severity Update comment to reflect command-line config selection

test-servers/​src/​test-server-stdio.ts:255

This conditional means the standalone entry no longer always starts with the default config, so the preceding “start with default config” comment is now inaccurate. Update it to mention selecting the default or crashable config from the command-line flag.

Nothing in the Inspector observes a stdio server's exit code — the
transport's onclose fires the same either way — so the option was
surface no test could give a reason to exercise. The process always
exits 1. Also corrects the standalone entry's comment, which still said
it always starts on the default config.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
@cliffhall

Copy link
Copy Markdown
Member Author

Copilot round 2: no inline findings; two items in Previously missed, both addressed in c03fd53. Neither has a thread to reply in, so this comment is the answer.

  • Add coverage for non-default crash_server exit codes: I took the review's alternative and removed the exitCode option. Nothing in the Inspector observes a stdio server's exit code: the transport's onclose fires the same either way, so no reconciliation test could have a reason to vary it. The process now always exits 1. I updated the PR body to match.
  • Update the stale comment on the standalone entry: fixed. It now says the entry starts the default config, or the crashable one when --crashable is passed.

local:gate is green. The one red run in between was server-auto-open.test.ts losing a port race, which isn't touched by this PR; I filed it as #2602. Requesting round 3.

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The fixture, integration coverage, cleanup behavior, and documentation consistently address the linked issue.

Review effort: Balanced
Findings: None

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot review closed after round 3, which was clean: no inline comments, no findings, nothing suppressed, approval recommended.

  • Round 1: 1 finding (stdout flush before exit), fixed.
  • Round 2: 2 previously-missed items (untested exitCode option, stale comment), both addressed.

@cliffhall
cliffhall merged commit a610279 into v2/main Oct 5, 2026
6 checks passed
@cliffhall
cliffhall deleted the v2/chore/2437-crash-reconciliation-fixture branch October 5, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Issues and PRs for v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No dedicated test fixture simulates a mid-session server crash/disconnect

2 participants