Skip to content

Fix successful stdio EOF shutdown exit codes - #10475

Merged
tim-smart merged 5 commits into
mainfrom
agent/effect-bot/a19104de808c
Nov 9, 2026
Merged

tim-smart merged 5 commits into
mainfrom
agent/effect-bot/a19104de808c

Conversation

@effect-bot

@effect-bot effect-bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix normal RPC/MCP stdio EOF shutdown returning exit code 130 under Layer.launch(...).pipe(NodeRuntime.runMain).

  • Add Runtime.InterruptExitCode for intentional interruption exit codes. defaultTeardown uses the largest annotated code only when every interruption reason is annotated; a mixed annotated/plain cause still exits 130.
  • Annotate the stdio shutdown interrupt with 0 only after stdout completes and pending responses drain. Use an exit-aware finalizer: successful completion sends the annotated interrupt, interruption-only scope cancellation does nothing, and writer defects retain the unannotated shutdown path. All shutdown interruptions remain detached.
  • Preserve failure exit codes and signal semantics. Include an effect patch changeset.

Validation

All toolchain commands ran with nix develop -c.

  • pnpm test --run packages/effect/test/rpc/RpcServer.test.ts packages/effect/test/ai/McpServer/McpServer.test.ts: 143 passed.
  • pnpm doctest --run packages/effect/src/Runtime.ts: 6 passed.
  • pnpm lint-fix, pnpm lint, pnpm check, pnpm jsdocs --check, and git diff --check: passed.
  • Real Node subprocess checks against the checkout sources using the documented MCP layer-launch entrypoint:
Scenario Exit Response
Empty stdin 0 —
Initialize and complete echo session, then EOF 0 Echo received
EOF after delayed echo handler starts 0 Echo received before process exit
SIGINT with stdin open after initialization 130 —
SIGTERM with stdin open after initialization 130 —
Layer-build failure after constructing the server layer 1 Failure reported

The temporary subprocess probes were removed. No test changes were made in the implementation commit.

Review guide

  • dcc0f8e177: regression tests only; pre-fix runs had four 130-versus-0 assertion failures, plus a runtime doctest failure for the missing annotation API.
  • Implementation commit: runtime/transport fix, API documentation, and changeset only.
  • Review follow-up: 15b98b13fd adds the stdout-defect regression; the follow-up implementation restores abnormal writer shutdown without changing tests. The new regression and all prior acceptance checks now pass.
  • 303a435480: Architect simplification pass. Documentation only for Runtime.InterruptExitCode (usage guidance, a runnable Fiber.interruptAs example, trimmed duplicated rules) plus removal of a redundant Effect.asVoid; shutdown semantics unchanged.

Closes EFF-3511
Closes #10474

@changeset-bot

changeset-bot Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 303a435

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-cloudflare Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/ai-typesafe Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/graphql-generator Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-janitor effect-janitor Bot added the 4.0 label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 39.61 KB 39.61 KB 0.00 KB (0.00%)
basic.ts 7.31 KB 7.31 KB 0.00 KB (0.00%)
batching.ts 11.21 KB 11.21 KB 0.00 KB (0.00%)
brand.ts 7.00 KB 7.00 KB 0.00 KB (0.00%)
cache.ts 11.73 KB 11.73 KB 0.00 KB (0.00%)
config.ts 23.06 KB 23.06 KB 0.00 KB (0.00%)
differ.ts 22.20 KB 22.20 KB 0.00 KB (0.00%)
http-client.ts 27.25 KB 27.25 KB 0.00 KB (0.00%)
http-router.ts 37.13 KB 37.13 KB 0.00 KB (0.00%)
logger.ts 12.19 KB 12.19 KB 0.00 KB (0.00%)
metric.ts 9.64 KB 9.64 KB 0.00 KB (0.00%)
optic.ts 7.21 KB 7.21 KB 0.00 KB (0.00%)
pubsub.ts 16.21 KB 16.21 KB 0.00 KB (0.00%)
queue.ts 13.09 KB 13.09 KB 0.00 KB (0.00%)
schedule.ts 11.99 KB 11.99 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.29 KB 14.29 KB 0.00 KB (0.00%)
schema-binary.ts 42.38 KB 42.38 KB 0.00 KB (0.00%)
schema-class.ts 21.96 KB 21.96 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.89 KB 29.89 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 28.22 KB 28.22 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.54 KB 15.54 KB 0.00 KB (0.00%)
schema-string.ts 12.50 KB 12.50 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.42 KB 16.42 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 39.16 KB 39.16 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 26.36 KB 26.36 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 21.11 KB 21.11 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 21.28 KB 21.28 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.37 KB 21.37 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.38 KB 26.38 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.45 KB 21.45 KB 0.00 KB (0.00%)
schema.ts 21.05 KB 21.05 KB 0.00 KB (0.00%)
stm.ts 14.40 KB 14.40 KB 0.00 KB (0.00%)
stream.ts 10.56 KB 10.56 KB 0.00 KB (0.00%)

@tim-smart
tim-smart merged commit 31368ab into main Nov 9, 2026
17 checks passed
@tim-smart
tim-smart deleted the agent/effect-bot/a19104de808c branch November 9, 2026 22:39
laithalsaadoon added a commit to memhtml/memhtml that referenced this pull request Nov 22, 2026
## What moves

- The Effect catalog set goes from 4.1.2 to 4.1.4 as one version: `effect`, `@effect/platform-node`, `@effect/platform-node-shared`, `@effect/vitest`.
- The lockfile follows: the four Effect packages, plus `undici` 8.12.3 -> 8.12.4 under `@effect/platform-node`, which asks for `^8.12.4`. Nothing else in the lockfile changes; `ws` stays at 8.22.1, and the docs site's own `undici` 8.12.3 (under `unifont`) stays where it is.
- No source change was needed. The only source edits are comments and prose that name the pin.

## Behavior changes memhtml reaches

Effect 4.1.3 changed behavior that memhtml reaches, and 4.1.4 keeps all but one of those changes. A user or operator moving from 4.1.2 to 4.1.4 can observe five things:

1. **`memhtml-mcp` exits with code 0 instead of 130 when its client closes stdin.** Anything that spawns the server and reads its exit code sees the new value. ([#10475](Effect-TS/effect#10475))
2. **A list request with a cursor the server never issued is refused.** `tools/list`, `resources/list`, `resources/templates/list` and `prompts/list` now answer `-32602 "Unknown cursor"`; before, they ignored the cursor and returned the full list. memhtml never issues a `nextCursor`, so a conforming client never sends one. ([#10447](Effect-TS/effect#10447))
3. **MCP request spans are renamed, only when `OTEL_EXPORTER_OTLP_ENDPOINT` is set.** A span such as `McpServer.@effect/mcp/2025-06-18/tools/call` becomes `tools/call memory_search`, and its attributes move from `rpc.*`, `tool` and `parameters` to `mcp.*`, `gen_ai.*`, `jsonrpc.request.id` and `network.transport`. Tool arguments are no longer exported on the span. Dashboards or queries keyed on the old names need updating. ([#10304](Effect-TS/effect#10304))
4. **Successful spans carry status Unset instead of Ok, under the same condition.** This applies to every span the MCP server and the CLI export. ([#10440](Effect-TS/effect#10440))
5. **`memhtml head serve` stops at once after SIGTERM when a local client had sent an HTTP `Upgrade` request.** Before, it waited the full two-second shutdown grace. memhtml's own client never sends `Upgrade`, so this needs a foreign client on the socket. Replies are unchanged. ([#10360](Effect-TS/effect#10360))

One 4.1.3 change does not carry over: 4.1.3 answered three malformed Skills requests with `-32601` instead of `-32602`, and 4.1.4 restores `-32602` ([#10540](Effect-TS/effect#10540)). Those replies are identical on 4.1.2 and 4.1.4.

None of the other 4.1.4 entries is reached: they cover `HttpApi`, `effect/cli`, the AI provider clients, `SchemaRepresentation` and `TestClock` internals.

## Proofs

- **Typecheck:** `turbo run typecheck` passes, 35 of 35 tasks, 0 errors (tsc 7.0.2).
- **Emit comparison:** every project was rebuilt with `tsc -b --force` and compared with a build of `main`: 418 `.js` and `.d.ts` files, 414 byte-identical. Three of the other four (`apps/mcp/dist/server.js`, `tools.js`, `server.d.ts`) differ only in the restated comment lines. The fourth, `apps/mcp/dist/tools.d.ts`, gains a third type argument (`Tool.Execution`) on the 15 tool types; that file is not part of the published bundle. No executable line differs.
- **Tests:** the `apps/mcp` suite passes 163 of 163. `apps/cli` `head-server.test.ts` passes 26 of 27 in a run with a long temp directory; the one failure is the socket-path-limit case, whose own precondition failed by one byte before any server code ran, and the file passes in the full gate. `catalog.test.ts` passes 4 of 4, `packages/eval` `corpus.test.ts` 26 of 26, `packages/llm` `structured.test.ts` 45 of 45. The full local gate (`mise run check`) passes 76 of 76 tasks on this head.
- **MCP stdio harness**, the `main` build against this branch's build, same fixture store:
  - 50 requests: 46 replies identical, 4 differ (the four cursor requests in item 2).
  - `tools/list` is identical: 41,197 bytes, same sha256.
  - Requests sent before `initialize` (9) and requests with bad header fields (8) are all identical.
  - All seven Skills requests are identical.
  - Exit code at stdin close: 130 before, 0 after.
- **Telemetry probe** against a local collector: 49 MCP spans and 22 CLI spans on both builds, with the name, attribute and status differences in items 3 and 4. Batch timing is unchanged.
- **Head server probe:** 17 replies equal on both builds apart from a duration, a pid and the store path. Stop time after an `Upgrade` request: 2,027 ms before, 27 ms after.
- **Advisories:** none affects Effect 4.1.2, 4.1.3 or 4.1.4, or undici 8.12.3 or 8.12.4. 4.1.4 is the newest release of all four packages.

## Restated sentences

- `apps/mcp/src/server.ts`: two comments now name effect 4.1.4 (the `instructions` option, the five protocol adapters).
- `apps/mcp/src/tools.ts`: one comment now names effect 4.1.4.
- `docs/backlog.md`: the `instructions` entry names the 4.1.4 pin and adds the 2026-11-16 probe.
- `CLAUDE.md`: the adapters sentence names 4.1.4. The "differs from recall" paragraph is reworded, not just renumbered: `Schema.d.ts` changed in 4.1.3 (it adds `Rational` and `RationalFromString` and changes the `isAnyOf` and `Iso` types), so the paragraph now says the claims it names were checked again against the installed 4.1.4, where `Effect.d.ts` is byte-identical to 4.1.2's.

## Merge

This PR is left open for the maintainer. It compiles and the emitted code is unchanged, but it changes an exit code, one MCP error path and the exported telemetry, and those are a maintainer's call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(McpServer): stdio server exits 130 instead of 0 when the client closes stdin

2 participants