Skip to content

Peer: give a request handler the request's id - #14

Merged
odrobnik merged 1 commit into
mainfrom
claude/request-id-to-handlers
Sep 28, 2026
Merged

odrobnik merged 1 commit into
mainfrom
claude/request-id-to-handlers

Conversation

@odrobnik

Copy link
Copy Markdown
Contributor

Why

JSONRPCPeer hands its request handler only the method and params (RequestHandler). A handler therefore can't tell two inbound requests apart when their method and params are the same. It also can't tie a request to what it belongs to by its JSON-RPC id, even though the wire log (setWireLog) sees that id as the request is read.

This is Cocoanetics/SwiftACP#138. SwiftACP binds each request an ACP agent makes (a permission question, a file read or write, starting a command) to the prompt that was in flight when the request was read, as acpx does. The wire log sees the id, but the handler that serves the request has only method and params. So it claims "the first unclaimed request with this method and params", and two identical requests can swap owners when their handler tasks start out of order. The one belonging to an answered prompt then gets served, and the live one is answered Request cancelled. acpx has no such ambiguity, because the ACP SDK hands each handler its own request.

What

  • JSONRPCPeer.IdentifiedRequestHandler: (id, method, params) async -> Result<JSONValue, JSONRPCError>.
  • setHandlers(identifiedRequest:notification:): installs one. The peer passes the id of the request the handler answers, the same id its reply goes out with.
  • setHandlers(request:notification:) is unchanged: its handler is wrapped into the new form. The new method has its own label, so setHandlers(request: nil, notification: …) call sites stay unambiguous.

It's additive, so this can be a minor release.

Verification

  • A new test (givesAnIdentifiedRequestHandlerEachRequestsID) sends two requests with the same method and params, under an integer id and a string id. It expects each to be answered with what its own id gave. With the peer passing a fixed id instead, both expectations fail.
  • The whole suite passes, and swiftlint --strict is clean.

🤖 Generated with Claude Code

JSONRPCPeer handed its request handler only the method and params, so a handler
could not tell two requests with the same method and params apart, nor tie a
request to what it belongs to by its id. setHandlers(identifiedRequest:
notification:) installs an IdentifiedRequestHandler, which is given the id of
the request it answers as well. setHandlers(request:notification:) is
unchanged: its handler is wrapped into the new form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 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-09-28T19:04:57.001134Z 14b29f8 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.

@odrobnik
odrobnik merged commit faa74a0 into main Sep 28, 2026
6 checks passed
@odrobnik
odrobnik deleted the claude/request-id-to-handlers branch September 28, 2026 20:33
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