Skip to content

fix: cap the RPC request id and keep surrogate pairs whole in a shortened message - #319

Merged
ThomasK33 merged 3 commits into
mainfrom
fix/rpc-request-id-cap
Nov 4, 2026
Merged

ThomasK33 merged 3 commits into
mainfrom
fix/rpc-request-id-cap

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Why

The advisor on #315 found two gaps in the RPC error response caps:

  1. RpcRequestSchema accepts a request id of any length, and the server echoes the id in every response. So the size invariant that fix: keep the host running when an RPC error response cannot be built #315 added for error responses did not cover the id.
  2. sendableMessage cuts a long error message at a fixed index. That index can fall between the two halves of a surrogate pair. Then the message ends with a lone high surrogate.

What changed

  • src/protocol/messages.ts: RpcRequestSchema accepts an id of at most MAX_RPC_REQUEST_ID_CHARS (128) characters. sendRpc sends a UUID, which has 36.
  • src/host/rpcServer.ts:
    • extractRequestId returns unknown for an id over the cap. So the error response for such a request does not echo the id.
    • The module-load size invariant now counts the id at its cap, at 6 characters per escaped character.
    • sendableMessage steps back one character when the cut would keep a high surrogate without its low surrogate.
  • Docs: src/protocol/README.md and src/host/README.md.

Behavior changes for CLI and JSON users

None for the CLI, which always sends a UUID. A raw client that sends an id over 128 characters gets RPC_ERROR with the id unknown. A shortened message never ends with half of an emoji or another character outside the Basic Multilingual Plane.

Verification

  • Red first (814ef21), on main 36ff4d1 (fix: keep the host running when an RPC error response cannot be built #315 merged):
    • test/unit/protocol/messages.test.ts: RpcRequestSchema accepts a 129-character id.
    • test/unit/host/rpcServer.test.ts: the server accepts a raw socket request with a 129-character id and echoes that id in its response.
    • A message of a plus 40,000 😀 ends with a lone \ud83d before [message truncated].
  • Green (cf826bf, docs 78ac00b): those tests pass. vitest run test/unit: 1956 passed. tsc --noEmit, oxlint src test vitest.config.ts and oxfmt --check pass.

Refs #315


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-04T03:14:20.198389Z 78ac00b 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. Swish!

Reviewed commit: 78ac00b878

ℹ️ 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 c7ef603 Nov 4, 2026
17 checks passed
@ThomasK33
ThomasK33 deleted the fix/rpc-request-id-cap branch November 4, 2026 03:49
@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