Skip to content

hack/hero-demo: redirect stdin from /dev/null in wait_for_file - #673

Merged
mayawang merged 1 commit into
google:mainfrom
mayawang:fix/hero-demo-ssh-stdin
Nov 20, 2026
Merged

mayawang merged 1 commit into
google:mainfrom
mayawang:fix/hero-demo-ssh-stdin

Conversation

@mayawang

Copy link
Copy Markdown
Collaborator

Summary

  • Redirect stdin from /dev/null on the ax ssh poll inside wait_for_file in hack/hero-demo/run.sh.

Why

When ./hack/hero-demo/run.sh runs in an interactive terminal, wait_for_file runs AX_TIMEOUT=10 run_ax ssh .... GNU timeout puts ax ssh in a background process group, and ax ssh (Stdin: os.Stdin in cmd/ax/main.go) reads from stdin. Reading from the controlling terminal in a background process group raises SIGTTIN, putting ax ssh into stopped state (T) with SIGTERM pending and leaving its child kubectl port-forward open indefinitely.

Verification

  • bash -n hack/hero-demo/run.sh (exit 0)
  • ./hack/hero-demo/run.sh dry-run (exit 0)
  • Controlling-PTY regression test (pty.openpty() + TIOCSCTTY) with mock ax reading stdin (cat >/dev/null):
    • Before fix: blocked until 1.5s watchdog kill (rc=-9)
    • With </dev/null: completed cleanly (rc=0, 0.02s)

When ./hack/hero-demo/run.sh runs in an interactive terminal, wait_for_file
invokes `AX_TIMEOUT=10 run_ax ssh ...` without redirecting stdin. GNU timeout
places `ax ssh` in a background process group, and `ax ssh` (`Stdin: os.Stdin`
in cmd/ax/main.go) reads from stdin. Reading from the controlling terminal in
a background process group raises SIGTTIN, stopping `ax ssh` with SIGTERM
pending and leaving its child `kubectl port-forward` open indefinitely.

Redirect stdin from `/dev/null` on the `ax ssh` poll inside `wait_for_file`
so interactive hero-demo runs do not stall on SIGTTIN.

Verification:
1. Syntax check: `bash -n hack/hero-demo/run.sh` (exit 0).
2. Harness dry-run: `./hack/hero-demo/run.sh` (exit 0, prints scoreboard).
3. Controlling-PTY test (`pty.openpty()` + `TIOCSCTTY`) with mock `ax` calling
   `cat >/dev/null`:
   - Before fix: blocked until 1.5s watchdog kill (`rc=-9`).
   - After fix: completed cleanly (`rc=0`, `0.02s`).
@mayawang

Copy link
Copy Markdown
Collaborator Author

@yongruilin quick one if you have a sec? 3-line fix in wait_for_file, it hangs when run.sh is run from an interactive terminal

@yongruilin yongruilin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fix!

@mayawang
mayawang merged commit 2aa2c93 into google:main Nov 20, 2026
10 checks passed
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.

2 participants