Skip to content

fix(stdio): close owned agent stdio streams on shutdown - #218

Merged
PsiACE merged 2 commits into
mainfrom
fix/close-owned-agent-stdio-streams
Nov 30, 2026
Merged

PsiACE merged 2 commits into
mainfrom
fix/close-owned-agent-stdio-streams

Conversation

@PsiACE

@PsiACE PsiACE commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Closes owned stdio transports created by agent runners on exit without closing the process's sys.stdin / sys.stdout handles, eliminating ResourceWarnings after stdin EOF.

Summary

  • Duplicate POSIX sys.stdin / sys.stdout descriptors via os.dup() so asyncio pipe transports own and close only the duplicated fds while leaving process standard streams open (matching Windows _StdoutTransport).
  • Add internal _owned_stdio_streams() context manager in src/acp/stdio.py that closes owned stdin/stdout transports with bounded stdout flush (timeout=2.0, aborting on timeout), restores original POSIX blocking modes on exit or setup failure, and leaves caller-owned streams untouched.
  • Use _owned_stdio_streams() in v1 run_agent(), v2.run_agent(), and AgentProtocolRouter.run() when no streams are passed.
  • Add real-subprocess EOF, post-shutdown sys.stdin/sys.stdout usability, and full-unread-stdout tests under -W error::ResourceWarning in tests/real_user/test_stdio_shutdown.py.

Verification

  • make gen-check
  • make check
  • make test (694 passed, 1 skipped, 0 warnings)

@PsiACE
PsiACE force-pushed the fix/close-owned-agent-stdio-streams branch from f91c050 to 42ce4c0 Compare November 29, 2026 06:38
@PsiACE
PsiACE force-pushed the fix/close-owned-agent-stdio-streams branch from 32e61c3 to cdbb6be Compare November 30, 2026 07:55
@PsiACE
PsiACE merged commit 839fb76 into main Nov 30, 2026
9 checks passed
@PsiACE
PsiACE deleted the fix/close-owned-agent-stdio-streams branch November 30, 2026 09:54
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