Skip to content

Conversation

@Rakshit-gen
Copy link

@Rakshit-gen Rakshit-gen commented Dec 18, 2025

Description

This PR removes the use of private asyncio internals (_buffer attribute and _maybe_resume_transport() method) from the monitor_stream() function in libs/cli/langgraph_cli/exec.py.

Problem

The current implementation directly accesses asyncio.StreamReader._buffer and calls _maybe_resume_transport() when handling LimitOverrunError. These are private implementation details that:

  • Are not guaranteed to exist in future Python versions
  • Can change behavior between minor Python releases
  • Have no documented API contract
  • Require # type: ignore comments due to accessing private members

Solution

Refactored the LimitOverrunError handling to use only public asyncio APIs:

  • Replaced _buffer access with stream.read(e.consumed) to read available data
  • Removed the _maybe_resume_transport() call (handled automatically by public read methods)
  • Implemented proper handling for cases where the separator is not immediately after the consumed bytes
  • Added nested LimitOverrunError handling for edge cases

Benefits

  • Future-proof: Won't break when Python's asyncio implementation changes
  • Maintainable: Uses only documented, stable APIs
  • Type-safe: No need for # type: ignore comments
  • Backwards compatible: Maintains identical external behavior

Issue

Fixes potential breakage in future Python versions where asyncio internals may change.

Dependencies

None - uses only standard library asyncio public APIs.


Testing

  • Verified no references to _buffer or _maybe_resume_transport remain in the codebase
  • Maintains same behavior for normal stream reading and buffer overrun scenarios
  • No breaking changes to external API

Replace direct access to asyncio.StreamReader._buffer and
_maybe_resume_transport() with public API calls. This improves
forward compatibility with future Python versions and eliminates
reliance on undocumented internal implementation details.

The LimitOverrunError handling now uses stream.read() to consume
data up to the limit, then continues reading until a newline is
found, maintaining the same behavior without accessing private
attributes.

Fixes potential breakage in future Python versions where asyncio
internals may change.
@vercel
Copy link

vercel bot commented Dec 18, 2025

@Rakshit-gen is attempting to deploy a commit to the LangChain Team on Vercel.

A member of the Team first needs to authorize it.

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