Skip to content

feat: add receive_timeout parameter to Connection class#1

Open
birdg0 wants to merge 8 commits intomainfrom
feat-add-receive-timeout
Open

feat: add receive_timeout parameter to Connection class#1
birdg0 wants to merge 8 commits intomainfrom
feat-add-receive-timeout

Conversation

@birdg0
Copy link
Copy Markdown
Owner

@birdg0 birdg0 commented Mar 26, 2026

Summary

Adds receive_timeout parameter to Connection class to prevent indefinite hangs when agents become unresponsive.

Related issues

None

Testing

Ran the following checks:

make check

Output:

  • ✓ Lock file consistency check passed
  • ✓ All pre-commit hooks passed (case conflicts, merge conflicts, toml, yaml, json, formatting, ruff check/format)
  • ✓ Static type checking passed (ty)
  • ✓ No dependency issues (deptry)
make test

Output:

  • ✓ 102 tests passed, 1 skipped in 1.39s
  • All existing tests continue to pass with the new optional parameter

Docs & screenshots

No documentation updates included in this PR. The parameter is optional and defaults to None, preserving existing behavior. Documentation can be added in a follow-up PR if needed.

dependabot Bot and others added 8 commits April 12, 2026 00:45
…rotocol#88)

Bumps the uv group with 1 update in the / directory: [uv](https://github.com/astral-sh/uv).


Updates `uv` from 0.9.7 to 0.11.6
- [Release notes](https://github.com/astral-sh/uv/releases)
- [Changelog](https://github.com/astral-sh/uv/blob/main/CHANGELOG.md)
- [Commits](astral-sh/uv@0.9.7...0.11.6)

---
updated-dependencies:
- dependency-name: uv
  dependency-version: 0.11.6
  dependency-type: indirect
  dependency-group: uv
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…tclientprotocol#89)

Bumps the uv group with 1 update in the / directory: [pytest](https://github.com/pytest-dev/pytest).


Updates `pytest` from 8.4.2 to 9.0.3
- [Release notes](https://github.com/pytest-dev/pytest/releases)
- [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst)
- [Commits](pytest-dev/pytest@8.4.2...9.0.3)

---
updated-dependencies:
- dependency-name: pytest
  dependency-version: 9.0.3
  dependency-type: direct:development
  dependency-group: uv
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…ientprotocol#86)

* fix: reject pending requests on EOF to prevent infinite hang

When the remote end closes the connection (e.g., subprocess crashes),
_receive_loop exits cleanly on EOF without raising an exception. This
means _on_receive_error is never called and pending outgoing request
futures hang forever.

Add reject_all_outgoing() after the receive loop breaks on EOF so
callers get a ConnectionError instead of an infinite hang.

Fixes agentclientprotocol#85

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: fail fast after connection EOF

---------

Co-authored-by: Debug Agent <debug@example.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Chojan Shang <psiace@apache.org>
agentclientprotocol#90)

Bumps the uv group with 1 update in the / directory: [python-dotenv](https://github.com/theskumar/python-dotenv).


Updates `python-dotenv` from 1.2.1 to 1.2.2
- [Release notes](https://github.com/theskumar/python-dotenv/releases)
- [Changelog](https://github.com/theskumar/python-dotenv/blob/main/CHANGELOG.md)
- [Commits](theskumar/python-dotenv@v1.2.1...v1.2.2)

---
updated-dependencies:
- dependency-name: python-dotenv
  dependency-version: 1.2.2
  dependency-type: direct:development
  dependency-group: uv
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: bump acp protocol to 0.12.2

Signed-off-by: Chojan Shang <psiace@apache.org>

* *: refine

Signed-off-by: Chojan Shang <psiace@apache.org>

---------

Signed-off-by: Chojan Shang <psiace@apache.org>
…tclientprotocol#92)

Some ACP clients (notably Zed) send a date string like "2024-11-05" as
the protocolVersion instead of an integer.  The Rust SDK already handles
this gracefully — its Deserialize impl maps any string to V0 with the
comment "Old versions used strings".  The Python SDK rejected strings
outright, causing the agent process to crash on the very first handshake.

Changes:
- Add `_coerce_protocol_version` field_validator to `InitializeRequest`
  in `src/acp/schema.py` that maps non-integer values to 1 (current
  stable version), mirroring the Rust SDK's lenient behaviour.
- Add `CLASS_VALIDATOR_INJECTIONS` table and `_inject_field_validators`
  post-processing step to `scripts/gen_schema.py` so the validator is
  re-applied automatically on future schema regenerations.
- Add `_ensure_pydantic_import` helper used by the injection step to
  add `field_validator` to the generated pydantic import line.

Ref: https://github.com/agentclientprotocol/rust-sdk/blob/main/crates/agent-client-protocol-schema/src/version.rs

Co-authored-by: liuyuan90 <liuyuan90@meituan.com>
Co-authored-by: Chojan Shang <psiace@apache.org>
…tocol#87)

_receive_loop only checked for EOF (b""), but blank lines like b"\n"
or b"\r\n" are truthy and reached json.loads(), causing JSONDecodeError.
Strip each line and skip when empty before parsing.
- Add optional receive_timeout parameter to Connection.__init__
- Implement timeout handling in _receive_loop using asyncio.wait_for
- Raise RequestError.internal_error on timeout for graceful error handling

This allows users to configure a timeout for receiving messages from
agents, preventing indefinite hangs when an agent becomes unresponsive.
@PsiACE PsiACE force-pushed the feat-add-receive-timeout branch from af5eae4 to 3cfbcb9 Compare May 7, 2026 19:07
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.

5 participants