Skip to content

fix(stdio): settle writer close and disconnection - #199

Open
Elon-Jiang wants to merge 1 commit into
agentclientprotocol:mainfrom
Elon-Jiang:fix/stdio-writer-close-notifications
Open

Elon-Jiang wants to merge 1 commit into
agentclientprotocol:mainfrom
Elon-Jiang:fix/stdio-writer-close-notifications

Conversation

@Elon-Jiang

Copy link
Copy Markdown

Summary

The StreamWriter returned by stdio_streams() cannot complete normal wait_closed() calls (_get_close_waiter is missing). If stdout is backpressured when its reader disconnects, drain() never wakes because the protocol ignores connection_lost. The Windows stdout adapter also logs write failures but leaves the writer apparently usable.

Use asyncio's existing flow-control implementation, add the writer's close waiter, and notify the same protocol when the Windows adapter closes or fails a write. Pending sends now fail on disconnection and normal buffered output can close cleanly. No public signatures, schema, or dependencies change.

Related issues

Found through the public stdio API on main 4fed584775d6a650cd669b63617049e5352297fe. This is separate from subprocess-stdin shutdown (#152) and the original Windows pipe setup report (#3); neither supplies this writer's missing close/error lifecycle.

Testing

  • The new four-case regression fails on unchanged main: normal POSIX and Windows-adapter close raise AttributeError; POSIX drain() times out under reader closure; the Windows adapter does not report its write error.
  • pytest tests/real_user/test_stdio_writer.py tests/real_user/test_stdio_limits.py tests/real_user/test_stdio_shutdown.py -q: 12 passed.
  • make check: passed (locked dependencies, actual prek checks, ty, deptry).
  • NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 make test: 544 passed, 1 skipped (optional Gemini), with one code-generation warning in unchanged code. The per-command loopback override allows the existing native WebSocket tests to bypass this machine's SOCKS proxy.

The POSIX tests use real subprocess stdio pipes, including 1 MiB buffered output and closing the actual receiving pipe. The Windows-specific adapter is exercised via the public stdio_streams() entry point with controlled standard handles on macOS; no native Windows execution is claimed.

Docs & screenshots

Expanded the public stdio_streams docstring to describe close/wait_closed and disconnection errors. No UI changes or schema regeneration.

Checklist

  • Conventional Commit title.
  • Tests cover the change.
  • Public docstring updated.
  • No schema regeneration needed.

AI assistance was used for investigation, implementation and local verification; no human review is claimed.

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