feat(job-output): add --follow flag for live log streaming#9
Merged
Conversation
Add `--follow` / `-f` to `hpc job-output` that pipes the running job's stdout (or stderr with `--error`) over SSH using `tail -F`. The flag accepts the same run_id / job_id resolution as the non-follow form, and `tail -F`'s retry semantics let the user attach before the output file exists. For terminal-state jobs the command falls back to the existing cat-based path so a missing output file surfaces the same error as before instead of `tail -F` spinning forever. Closes #4
`subprocess.run` re-raises `KeyboardInterrupt` rather than returning a `CompletedProcess` when the user presses Ctrl-C, so `--follow`'s caller never received the streaming exit status and Typer aborted the command instead of propagating it cleanly. Catch `KeyboardInterrupt` in `SSHManager.run_streaming` and return the conventional shell exit code 130. The `with Popen` block inside `subprocess.run` already kills and reaps the SSH child before re-raising.
There was a problem hiding this comment.
Pull request overview
Adds live log streaming to the hpc job-output CLI via a new --follow/-f flag, implemented using a non-capturing SSH execution path so tail -F output is streamed directly to the local terminal.
Changes:
- Add
SSHManager.run_streaming()to execute remote commands without capturing output and return an exit code (including mapping Ctrl-C to 130). - Add
JobManager.tail_job_output()with status-aware behavior (terminal-state jobs use the existingcatpath; active/unknown streams viatail -F). - Wire
--follow/-finto the CLI and document it in the README; add focused unit tests across SSH, job manager, and CLI layers.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_ssh.py | Adds unit tests validating streaming SSH execution behavior (no capture, quoting, ctrl-master options, Ctrl-C mapping). |
| tests/test_job.py | Adds tests for tail_job_output() branching between streaming vs. cat fallback and exit code propagation. |
| tests/test_cli.py | Adds CLI regression tests for job-output --follow help text, flag wiring, and exit code propagation. |
| src/hpc/ssh.py | Implements SSHManager.run_streaming() for non-capturing remote execution with Ctrl-C → 130 behavior. |
| src/hpc/job.py | Implements JobManager.tail_job_output() that decides between tail -F streaming and cat fallback based on job status. |
| src/hpc/cli.py | Adds --follow/-f option to job-output and dispatches to tail_job_output(). |
| README.md | Documents hpc job-output --follow/-f usage and stderr-following via --error/-e. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
--follow/-ftohpc job-outputthat streams the running job's stdout (or stderr with--error) over SSH usingtail -F.SSHManager.run_streamingfor non-capturing SSH command execution; mirrorsrun_command's shell-injection defenses (command-name validation +shlex.quote).JobManager.tail_job_outputwith status-aware dispatch: terminal-state jobs fall back to the existingcatpath so a missing output file surfaces the same error as before, instead oftail -Fspinning forever.KeyboardInterruptduring streaming to exit code 130 so Ctrl-C propagates cleanly through Typer.Test plan
uv run pytest— 136 tests pass (was 119 before this PR; 17 new).uv run ruff check src testsclean.uv run ruff format --check src testsclean.uv run pyright src/hpc/0 errors.hpc job-output -f <id>→ Ctrl-C → confirm no residual remotetail(deferred probe; the conventional SSH-SIGINT propagation path is what is implemented).Follow-up
scheduler.parse_statusmis-classifies empty status output asFAILED; surfaced by codex-review on this branch but pre-existing in the scheduler layer.Closes #4