Repository navigation
Conversation
`_handle_response` looks the message id up in `_pending` without checking it first. The same file validates a request id with `_is_request_id` in `_track_incoming` and `_cancel_incoming`, but not here, so a peer's frame can do two things: - An unhashable id (an array or an object) raises `TypeError` on the lookup. The exception escapes `_receive_loop`, the connection disconnects, and the valid frame queued behind it is never handled. - `true` and `1.0` are equal to the integer `1`, so they resolve the future of the integer-1 request -- the same aliasing `_track_incoming` already refuses. Ignore a response whose id is not a JSON-RPC `RequestId`, matching the two existing call sites.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Connection._handle_responseuses the messageidas a dictionary key without checking it first:The same file already validates a request id in two other places with
_is_request_idin_track_incomingand_cancel_incoming-- but not here. A peer's response frame can therefore do two things.An unhashable id escapes the receive loop.
{"id": [], ...}raisesTypeErroron the lookup, the exception leaves_receive_loop, and the connection disconnects with the valid frame queued behind it never handled:trueand1.0alias onto the integer1. They hash and compare equal, so they resolve a different request's future:That second case is the one
_track_incomingalready comments on: "Python would alias an invalid one such astrueor1.0with the integer1." The guard exists for the outgoing direction and is missing for the incoming one.Change
src/acp/connection.py: ignore a response whose id is not a JSON-RPCRequestId, matching the two existing call sites._is_request_idis unchanged: it acceptsnull, an integer and a string, which is exactly the protocol'sRequestId.Testing
New case in
tests/test_connection_recovery.py, beside the #153 frame-shape test: four responses carrying[],{},trueand1.0, followed by a valid request. It asserts the integer-1 request is still pending, the pending map is untouched, and the frame behind the bad ids was still handled.Written against the defect: removing only the new guard fails the case, because the
TypeErrorstops the loop before the following frame is processed.Full suite, and the lint pass:
The one failure is pre-existing on this machine and unrelated:
tests/real_user/test_stdio_limits.py::test_spawn_stdio_transport_custom_limit_handles_large_linecompares a line length of 71682 against 71681, which is a CRLF artefact of Windows stdio rather than anything in this change.Checklist
fix:)