Prevent shell-echo races in automation docs#709
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #709 +/- ##
==========================================
+ Coverage 52.44% 52.46% +0.02%
==========================================
Files 26 26
Lines 3726 3726
Branches 747 747
==========================================
+ Hits 1954 1955 +1
Misses 1468 1468
+ Partials 304 303 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Pushed a follow-up: The rest of the page now waits on The helper now takes the command's own output lines rather than a pane, so it cannot be handed the echo in the first place. One detail worth flagging, because it caught me: the tag has to survive wrapping. My first attempt sent Also added a CI green on all 8 tmux versions. Scope note: |
why: Shell echoes can contain literal markers, so substring polling can report completion before a command produces its output. what: - Use Server.wait_for() channels with explicit state handshakes - Poll echo-safe exact lines with monotonic deadlines for bounded waits - Stop retries and queues when foreground pane ownership is unknown
why: The rest of this page now waits on tmux channels and matches whole output lines, but check_for_errors was left scanning the joined pane for a substring. That is the same echo race the page warns about, in the one helper where it is easiest to walk into: send_keys types the command, the shell echoes it back, and `mytool --log-level=ERROR` is reported as a crash before the tool has printed anything. The tag also has to survive wrapping. A long command wraps, so a tag that merely sits mid-line in what you typed can still end up starting a continuation line. Letting printf assemble the tag from a format and an argument keeps the literal out of the echo entirely. what: - Scan only the lines the command tags as its own, via command_output() - Take those lines, not a pane, so the helper cannot be handed the echo - Show it both ways: a healthy command whose own arguments say ERROR is not flagged, and a command that really fails is - Record the fix in CHANGES; the racy recipes shipped in 0.61.0
3d0aae0 to
2aff5ac
Compare
Summary
Replace echo-prone completion polling with tmux
wait-forchannels when automation controls the command and does not need a timeout.For bounded waits, retries, queues, and state machines, match echo-safe complete output lines against monotonic deadlines. Stop retry and queue sequencing when a timed-out foreground process may still own the pane.
Update every affected executable example and the page guidance so doctests prove command output rather than shell input echo.
Verification
uv run ruff format --check .uv run ruff check .uv run mypy .just build-docsuv run py.test --reruns 0 -q docs/topics/automation_patterns.md(16 passed)uv run py.test --reruns 0 -q(1342 passed, 1 skipped)Closes #706