Skip to content

feat(job-output): add --follow flag for live log streaming#9

Merged
ultimatile merged 2 commits into
mainfrom
feat/4-job-output-follow
May 8, 2026
Merged

feat(job-output): add --follow flag for live log streaming#9
ultimatile merged 2 commits into
mainfrom
feat/4-job-output-follow

Conversation

@ultimatile
Copy link
Copy Markdown
Owner

@ultimatile ultimatile commented May 8, 2026

Summary

  • Add --follow / -f to hpc job-output that streams the running job's stdout (or stderr with --error) over SSH using tail -F.
  • Add SSHManager.run_streaming for non-capturing SSH command execution; mirrors run_command's shell-injection defenses (command-name validation + shlex.quote).
  • Add JobManager.tail_job_output with status-aware dispatch: terminal-state jobs fall back to the existing cat path so a missing output file surfaces the same error as before, instead of tail -F spinning forever.
  • Convert KeyboardInterrupt during 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 tests clean.
  • uv run ruff format --check src tests clean.
  • uv run pyright src/hpc/ 0 errors.
  • Live smoke on a real HPC cluster: hpc job-output -f <id> → Ctrl-C → confirm no residual remote tail (deferred probe; the conventional SSH-SIGINT propagation path is what is implemented).

Follow-up

Closes #4

ultimatile added 2 commits May 8, 2026 17:50
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.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 existing cat path; active/unknown streams via tail -F).
  • Wire --follow/-f into 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.

Comment thread src/hpc/job.py
@ultimatile ultimatile merged commit b56bb92 into main May 8, 2026
4 checks passed
@ultimatile ultimatile deleted the feat/4-job-output-follow branch May 8, 2026 19:18
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.

hpc job-output --follow for real-time log tailing

2 participants