Repository navigation
fix(embed): pin stdin to DEVNULL when spawning the daemon - #4464
Merged
nicoloboschi merged 2 commits intoSep 25, 2026
Merged
Conversation
The POSIX branch of `_detach_popen_kwargs` left `stdin` unset, so the daemon child inherited the caller's fd 0. A caller can hold an fd 0 that is a socket opened with FD_CLOEXEC (e.g. a TUI/gateway that wires its IPC channel onto fds 0-2); the kernel closes an inherited fd 0 at exec, so the child starts with `sys.stdin = None` and dies in `_redirect_stdio_to_log()` with `AttributeError: 'NoneType' object has no attribute 'fileno'`. The Windows branch already pinned stdin, and so does the sibling helper in hindsight-api-slim/hindsight_api/daemon.py — the two copies had drifted.
Review fix: assert kwargs["stdin"] instead of kwargs.get("stdin"), so a
missing key fails loudly as a KeyError.
nicoloboschi
force-pushed
the
fix/embed-daemon-spawn-stdin
branch
from
September 25, 2026 12:20
e9233ad to
13e165d
Compare
Collaborator
|
Thanks! Rebased onto main and pushed one small review fix: the regression test now indexes |
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.
_detach_popen_kwargspinsstdinon Windows but not on POSIX, so the daemon child inherits the caller's fd 0. When that fd 0 is a socket opened withFD_CLOEXEC(e.g. a TUI/gateway parent that wires its IPC channel onto fds 0-2), the kernel closes it at exec: the child starts withsys.stdin = Noneand dies in_redirect_stdio_to_log()withThe manager then waits out its startup timeout and reports "Daemon failed to start". The sibling helper in
hindsight-api-slim/hindsight_api/daemon.pyalready pins stdin; only this copy had drifted.Repro (no daemon involved):
Pins
stdinon both platforms and adds a regression test (test_detach_popen_kwargs_pins_stdin, fails on main, passes with the fix). Verified on macOS / Python 3.11: a daemon start from a CLOEXEC-fd0 parent comes up healthy.