Skip to content

fix(connection): prevent requests hanging after malformed error responses - #177

Open
HowieYin wants to merge 1 commit into
agentclientprotocol:mainfrom
HowieYin:fix/response-settlement
Open

HowieYin wants to merge 1 commit into
agentclientprotocol:mainfrom
HowieYin:fix/response-settlement

Conversation

@HowieYin

@HowieYin HowieYin commented Oct 22, 2026 •

Copy link
Copy Markdown

Summary

Fix requests hanging after a malformed error response.

Connection._handle_response() removes the request from _pending before reading the error payload. If a peer sends "error": ["malformed"], decoding raises before the future receives a result or exception. Disconnect cleanup can no longer find that future, so its caller keeps waiting while the other pending requests receive ConnectionError.

Changes

Keep the future in _pending until its result or exception has been set. If response handling fails, the existing disconnect cleanup can then reject the affected request as well.

Add regressions over real TCP streams for both automatic listening and main_loop(), plus compatibility tests for valid responses, cancellation, duplicate responses, and shutdown.

Testing

Local validation:

  • All 8 malformed-response cases fail before the fix and pass afterward. Each verifies that both outstanding requests receive ConnectionError before calling close().
  • make check: passed.
  • make test: 484 passed, 1 skipped. The skipped test is the optional Gemini integration test.

@HowieYin HowieYin changed the title fix(connection): settle responses before removing pending requests fix(connection): prevent requests hanging after malformed error responses Oct 22, 2026

This branch has not been deployed

No deployments
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