Conversation
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
A line that parses as JSON but is not a JSON object —
[],123,"x", ornull— currently kills an ACP connection permanently.NdjsonTransport.receive()returns whateverjson.loadsproduced, andConnection._process_message()then callsmessage.get(...)on it, so theAttributeErrorescapes_receive_loop(),_disconnect()never runs, and the process dies.nullfails one step earlier and differently: it parses toNone, whichreceive()uses as its EOF signal, so the connection is closed as if the peer had hung up.Malformed JSON is already tolerated (
_transport.py:83-85logs and skips it), and both web transports already refuse non-object frames (ws/server.py:42-43returns only dicts;http/server.py:242-245answers 501 for a batch and 400 otherwise). This makes the stdio path behave the same: ignore a frame that is not an object, and keep the connection alive for the frames behind it.Related issues
Relates to #62 / #72, which fixed the same failure mode for a different input (an oversized frame) with the rationale that "the connection should degrade gracefully rather than crash."
No issue covers non-object frames — I searched open and closed issues and PRs for
isinstance dict,non-object frame,AttributeError,batch JSON-RPC,malformed frame,message.get,null frame.Testing
Reproduced end-to-end on Windows (Python 3.12.14) by spawning a real
run_agentchild overspawn_stdio_transport, writing one non-object frame followed by a validinitialize:[]AttributeError: 'list' object has no attribute 'get'atconnection.py:153initializeanswered123AttributeError: 'int' ...initializeanswered"x"AttributeError: 'str' ...initializeanswerednullinitializeansweredthis is not json{"jsonrpc":"2.0","method":"noop"}The regression test added here is red without the source change:
Full suite:
uv run python -m pytest --doctest-modules -q→ 2 failed, 356 passed, 1 skipped. Both failures pre-exist onmainon this machine and are unrelated to this change:tests/test_gen_all.py::test_codegen_check_is_clean_and_read_only— the Windows codegen encoding issue already tracked by fix: make the schema codegen host-independent #151.tests/real_user/test_stdio_limits.py::test_spawn_stdio_transport_custom_limit_handles_large_line— Windows-only CRLF artefact: the child'ssys.stdout.write("\n")becomes\r\n, so the line is 71682 bytes and the test's ownlen(line) == LARGE_LINE_SIZE + 1assertion fails. Upstream CI is ubuntu-only, so CI does not see it.I did not run
make checkend to end.Docs & screenshots
No user-facing docs change.
receive()is already annotateddict[str, Any] | None, which this change makes true.Checklist
feat:,fix:).make gen-all) are called out if applicable.Scope note.
WsClientTransport.receive()(src/acp/ws/client.py:56) has the same shape —return json.loads(frame)with no object guard — while the WebSocket server transport does guard. I deliberately did not change it here: I verified the stdio path end to end, but I did not stand up a live WebSocket connection to demonstrate the client path, and I would rather leave that visible than claim a fix I did not test. Say the word and I will add it here or in a follow-up.