Repository navigation
fix: report the timeout, not recursion, for a substitution after the deadline - #358
Conversation
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Changes requested. The fix does what it says for the five tested shapes, but it relies on "the command it feeds" reporting the timeout, and several commands never do. For those, stderr goes from the wrong message on main to no message at all.
- 🔴 Silent timeout (inline): with a 1 s timeout,
strands-shell -c '[[ $(sleep 5) != $(echo second) ]]'exits 1 with empty stderr. Same class forexit,return,command -v, and nested substitutions underShell::execute. - 🟡 Test coverage (inline): every tested shape ends in a pipeline or
forlist, and nothing pins the recursion-message de-dup.
The part that is in scope works: the recursion mislabel is gone and the generic timeout line prints exactly once for all five shapes.
What I verified, and non-blocking notes
Verified (head 94f16e1 vs base dbb6189, aarch64 Linux, rustc 1.100.0, debug build)
cargo test --workspace --all-targetson head: 20 suites, 2734 passed, 0 failed.- The new test fails on base at the first shape (two recursion lines before the timeout line) and passes on head.
cargo fmt --all -- --checkclean;cargo clippy --workspace --all-targetshas no warnings on the changed lines.- Differential probe of base vs head over about 140 command shapes (plain, quoted, assignments,
for,case,[/test,$(( )), here-docs, redirect targets, parameter defaults,eval,source, functions, subshells, background jobs,xargs,find -exec): exit statuses are identical everywhere; stderr differs only by the removed recursion lines. - Real depth limit with
max_depth(1)andecho $(echo x): 2 recursion lines on base, 1 on head, as described.
Not tested: wasm target, Python and Node bindings (not built here), and real 30 s timeouts (probes used 200 ms to 1 s).
Appendix: non-blocking (4)
- ⚪
src/exec.rs:1832matches on the text of the messagecheck_limitsreturns. Adeadline_expired()predicate onProcesswould avoid coupling to the wording; it may fall out of fixing the 🔴 anyway. - ⚪ A compound piped into a failing tail also goes silent:
for i in $(while :; do :; done) $(echo second); do echo $i; done | grep -q zzzprints the timeout line plus two recursion lines on base and nothing on head. The strip atsrc/exec.rs:2493-2497assumes the parent reports, which it only does when the tail exits 0. - ⚪ Dropping
captured_stderr.push_strloses the real recursion message when the stage's 64-slot stderr channel is already full (64 earlier diagnostics in the same pipeline stage, then a too-deep$(...)): 1 recursion line on base, 0 on head. Contrived. - Pre-existing, not filed since they sit next to the 🔴 and are probably fixed with it: on base too,
strands-shell -c 'echo $(echo $(sleep 5))'exits 1 with empty stderr, andwhile :; do :; done | grep -q zzzreturns status 1 with empty stderr.
|
@strandly-the-agent Please review this PR |
There was a problem hiding this comment.
Approve. Both findings from my last review are fixed on f521647.
- 🔴 Silent timeout: fixed. Every shape that was silent now prints
strands-shell: execution timeout exceeded, and no shape prints the recursion line for a timeout. - 🟡 Test coverage: fixed. The four shapes are in the test, which fails on main and on the previous head and passes here.
The repeated timeout line is not new noise. In the 35 timeout shapes I ran, stderr has the same number of lines as on main, or one fewer; only the label changed from recursion to timeout. Leaving "exactly once" as a follow-up is reasonable.
All build and test checks pass on this head. The rollup shows red only because one superseded 2 Approvers for Bots run was cancelled.
What I verified, and notes for the follow-up
Verified (head f521647 vs base dbb6189, aarch64 Linux, rustc 1.100.0, debug build)
cargo test --workspace --all-targetson head: 20 suites, 2734 passed, 0 failed.- The new test, copied onto
dbb6189, fails atecho $(sleep 5) $(echo second)with two recursion lines. Copied onto94f16e1, it fails at[[ $(sleep 5) != $(echo second) ]]with only the sleep line. cargo fmt --all -- --checkclean;cargo clippy --workspace --all-targetshas no warnings on the changed lines.Shell::run, 200 ms timeout, 35 shapes, 3 runs each with identical output: plain, quoted, assignment,exec,for,[[ ]],exit,return,command -v, nested, five later substitutions, pipeline stage,2>/dev/null, here-doc,$(( )),${x:-…}, redirect target, background +wait,xargs … sh -c, and nine compound-into-failing-tail shapes. Every exit status matches main. Every shape that printed a recursion line on main prints at least one timeout line and no recursion line here.- CLI with
[limits] timeout = 1, 8 commands:[[ $(sleep 5) != $(echo second) ]],echo $(echo $(sleep 5)) $(echo second),exit $(sleep 5)$(echo 0), thereturnandcommand -vshapes and three compound-into-grep -qshapes all print the timeout line where main printed the recursion line. - Real depth limit (
max_depth(1),echo $(echo x); and the full-stderr-channel case from my last appendix): identical to main. - #352 is the open PR for the
execdouble expansion, as the description says.
Not tested: wasm target, Python and Node bindings, real 30 s timeouts.
For whoever picks up "exactly once"
- Under
Shell::run,echo $(sleep 5) $(echo second)prints the generic line 3 times, not 2: the substitution writes it to bothcaptured_stderranderr_msg, and the pipeline's post-expansion check adds one. From the CLI it is 2. Each further substitution on the line adds 2 underShell::run(11 lines for five later substitutions, same as main's 10 recursion lines plus 1).
Previous appendix
- String match on the message text: gone with the new approach.
- Compound piped into a failing tail going silent: no longer silent in the nine shapes I ran.
- Recursion message lost when the stderr channel is full: gone, the captured write is back.
- Still present on main and here, and not part of this PR:
strands-shell -c 'echo $(echo $(sleep 5))'exits 1 with empty stderr, andwhile :; do :; done | grep -q zzzreturns status 1 with empty stderr. I have not filed an issue for these; tell me if you want one.
Description
When a command ran past the deadline and a later command substitution on the same line tried to start, the shell told you the recursion limit was hit. No recursion limit was involved; it was just the timeout. Anyone reading stderr, an agent especially, got the wrong cause.
Now that substitution prints whichever limit it actually hit, so a timeout says timeout. That's the fix the issue suggests. The timeout line can show up more than once on one command line; reporting it exactly once would be a possible follow-up. The part where
execruns its substitutions twice is covered by #352.I added a test over a few shapes, including
[[ ]],exit,returnandcommand -v, which don't report the timeout on their own. On main it failed with the recursion message. An earlier version of this PR made those four go silent; the test now catches that. With the change it passes, and so does the full suite.Related Issues
Fixes #260
Documentation PR
N/A
Type of Change
Bug fix
Testing
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.