Skip to content

fix: run_command() timeout via reader thread#6

Merged
fazxes merged 2 commits intomainfrom
fix/run-command-timeout
Apr 3, 2026
Merged

fix: run_command() timeout via reader thread#6
fazxes merged 2 commits intomainfrom
fix/run-command-timeout

Conversation

@fazxes
Copy link
Copy Markdown
Member

@fazxes fazxes commented Apr 3, 2026

Summary

  • Replaced blocking readline() loop with a daemon reader thread
  • Main thread enforces timeout via thread.join() with monotonic deadline
  • Hung processes are now reliably terminated/killed when timeout expires
  • Partial output captured before timeout

Test plan

  • 6 new tests: output capture, exit codes, log writing, timeout kill, partial output, normal completion
  • All 134 tests pass
  • Dry-run works for both codex and claude
  • mypy strict passes
  • Manual: run python3 -m nightshift run --agent claude against a repo and interrupt

fazxes added 2 commits April 3, 2026 18:49
readline() blocked indefinitely on hung processes, making timeout_seconds
useless. Now a daemon reader thread handles I/O while the main thread
enforces a monotonic deadline. Process is terminated/killed when the
deadline expires. Partial output is captured before timeout.

+6 tests covering output capture, exit codes, log writing, timeout kill,
partial output, and normal completion with timeout set.
@fazxes fazxes merged commit 9610691 into main Apr 3, 2026
6 checks passed
@fazxes fazxes deleted the fix/run-command-timeout branch April 3, 2026 22:52
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0a410ac325

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread nightshift/shell.py
# Main thread enforces the timeout — reader thread cannot block us.
deadline = time.monotonic() + timeout_seconds if timeout_seconds else None
timed_out = False
while reader.is_alive():
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep enforcing timeout after reader thread exits

The timeout logic is gated by while reader.is_alive(), so if a child process closes or redirects both stdout/stderr early (e.g., daemonizes to /dev/null) the reader thread exits immediately even though the process is still running. In that case this path falls through to process.wait() with no timeout and can block indefinitely, which reintroduces a hang despite timeout_seconds being set. Timeout enforcement should be independent of reader-thread liveness.

Useful? React with 👍 / 👎.

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