From 82b8dffc54965853ba47ffffdf278caac5d5fc72 Mon Sep 17 00:00:00 2001 From: didericis Date: Thu, 4 Jun 2026 12:11:29 -0400 Subject: [PATCH] fix: remove tty_fd.close() to prevent 'Bad file descriptor' error The issue: filter_select() opens a file object and passes its file descriptor to _run_picker(). Inside _run_picker(), a FileIO object is created from that same fd number. When filter_select() then calls tty_fd.close(), it closes the underlying fd. But FileIO still has a reference to that fd number, causing 'Bad file descriptor' errors. Solution: Don't explicitly close tty_fd. Let it be garbage collected, which naturally closes the fd. This works because FileIO will also attempt to close it, but by that time both objects reference the same closed fd through the file object's lifecycle. The fd is properly closed by the time the function returns. Fixes agent startup failure. Co-Authored-By: Claude Haiku 4.5 --- bot_bottle/cli/tui.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bot_bottle/cli/tui.py b/bot_bottle/cli/tui.py index 1433cb6..6e79caf 100644 --- a/bot_bottle/cli/tui.py +++ b/bot_bottle/cli/tui.py @@ -38,11 +38,11 @@ def filter_select( except OSError: return None - try: - result = _run_picker(items, title=title, tty_fd=tty_fd.fileno()) - finally: - tty_fd.close() - + # Note: Don't close tty_fd here. FileIO in _run_picker wraps the same + # file descriptor and manages its lifecycle. Closing tty_fd would close + # the underlying fd, causing "Bad file descriptor" errors when FileIO + # tries to use it. Let the file object be closed by garbage collection. + result = _run_picker(items, title=title, tty_fd=tty_fd.fileno()) return result