Skip to content

fix: keep the host running when an RPC error response cannot be built - #315

Merged
ThomasK33 merged 3 commits into
mainfrom
fix/rpc-unexpected-failure
Nov 4, 2026
Merged

ThomasK33 merged 3 commits into
mainfrom
fix/rpc-unexpected-failure

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Why

The advisor on #313 found three ways an RPC error response can still break, and the operator wants them shipped now:

  1. RpcServer starts each request with void this.processRequestLine(...). If building or sending the response throws, the rejection is unhandled. Node then ends the host process, and the session ends failed.
  2. fix: carry CliError details across the session host RPC #313's sendableDetails keeps any JSON. A toJSON can turn details into undefined, a string or an array. undefined makes serialized.length throw. A string or an array fails RpcResponseSchema, so the server's invariant throws. Both become the unhandled rejection in point 1.
  3. The server sends a CliError message of any length. A 1.1 MB message gives "RPC response exceeds maximum buffer size." at the CLI instead of the error's code. main has the same gap, for CliError and for other errors.

What changed

  • src/host/rpcServer.ts:
    • A .catch on processRequestLine logs the error with console.error and answers RPC_ERROR "RPC request handling failed unexpectedly." with the request's id. The host keeps running.
    • sendableDetails keeps details only when JSON.stringify gives a string of at most 65,536 characters that parses to a plain object.
    • sendableMessage cuts an error message to 65,536 characters, ending with [message truncated]. Both RPC_ERROR responses and CliError responses use it.
    • A module-load invariant checks that a message and details at their caps fit in one response, even when every character is a control character (6 characters in JSON).
  • src/host/README.md describes the message cap and the unexpected-failure answer.

Behavior changes for CLI and JSON users

  • An error with a message over 65,536 characters now keeps its code, and its message ends with [message truncated]. Before, the CLI reported exit 9 RPC_ERROR "RPC response exceeds maximum buffer size.".
  • A failure inside the host's response building now gives exit 9 RPC_ERROR "RPC request handling failed unexpectedly." Before, the host process crashed and the session ended failed.
  • The envelope shape and the error codes do not change.

The host's stdio is 'ignore', so the console.error line shows only when the host runs in the foreground, for example in tests.

Verification

  • Red first (434eb90), on main e7c7e1d (fix: carry CliError details across the session host RPC #313 merged): in test/unit/host/rpcServer.test.ts, a real RpcServer and the real sendRpc over a Unix socket.
    • toJSON returning undefined, a string or an array: test timeout, and Vitest reports the unhandled rejections (TypeError: Cannot read properties of undefined (reading 'length'), and twice RPC CliError response must satisfy RpcResponseSchema.).
    • An error whose message getter throws: test timeout and an unhandled rejection.
    • A 1,100,000-character CliError message, and the same message on a plain Error: "RPC response exceeds maximum buffer size.".
    • The throwing-getter details case passes on e7c7e1d and stays covered.
  • Green (bc36097, docs 74a2e47): vitest run test/unit/host/rpcServer.test.ts test/unit/host/rpcClient.test.ts: 26 passed. vitest run test/unit: 1949 passed.
  • tsc --noEmit, oxlint src test vitest.config.ts and oxfmt --check pass.

Refs #313


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: xhigh

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 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-04T02:41:06.572575Z 74a2e47 Manual request
ℹ️ 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 74a2e47ad7

ℹ️ 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".

@ThomasK33
ThomasK33 added this pull request to the merge queue Nov 4, 2026
Merged via the queue into main with commit 36ff4d1 Nov 4, 2026
17 checks passed
@ThomasK33
ThomasK33 deleted the fix/rpc-unexpected-failure branch November 4, 2026 03:11
@github-actions github-actions Bot mentioned this pull request Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant