fix(io): catch ValueError in _SafeWriter for closed file handles - #2431
Closed
Bartok9 wants to merge 1 commit into
Closed
fix(io): catch ValueError in _SafeWriter for closed file handles#2431Bartok9 wants to merge 1 commit into
Bartok9 wants to merge 1 commit into
Conversation
…sResearch#2428) When subagents run in ThreadPoolExecutor threads, the shared stdout handle can close between thread teardown and KawaiiSpinner cleanup. Python raises ValueError (not OSError) for I/O operations on closed files: ValueError: I/O operation on closed file The _SafeWriter class was only catching OSError, missing this case. Changes: - Add ValueError to exception handling in write(), flush(), and isatty() - Update docstring to document the ThreadPoolExecutor teardown scenario Fixes NousResearch#2428
Contributor
|
Merged via PR #2466 — cherry-picked with authorship preserved. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2428 —
_SafeWriter.isatty()raises ValueError on closed file during subagent ThreadPoolExecutor teardown.Problem
When subagents run in
ThreadPoolExecutorthreads, the shared stdout handle can close between thread completion andKawaiiSpinner.stop()cleanup. Python raisesValueError(notOSError) for I/O operations on closed files:The
_SafeWriterclass (added in a8409a1) only catchesOSError, missing this case.Root Cause
Two commits that interact:
_SafeWriterto catchOSErrorfor broken pipesisatty()check inKawaiiSpinner.stop()The
isatty()call during spinner cleanup can fail withValueErrorwhen the underlying handle is already closed.Fix
Add
ValueErrorto exception handling inwrite(),flush(), andisatty()methods:This is a standard Python pattern —
ValueError: I/O operation on closed fileis the expected exception for operations on closed file descriptors, distinct fromOSErrorwhich covers broken pipes and device errors.Testing