7f43f64c24
The issue: Both the original file object (tty_fd) and the FileIO object created in _run_picker() were managing the same file descriptor. When both tried to close it (or during garbage collection), we got 'Bad file descriptor' errors. The solution: Use os.dup() to create an independent copy of the fd that FileIO can own exclusively. The original file object closes its copy, and FileIO closes its independent copy, preventing conflicts. This properly separates fd ownership between the two objects. Fixes the 'Exception ignored while finalizing file' errors on agent startup. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>