Skip to content

fix: report the timeout, not recursion, for a substitution after the deadline - #358

Merged
ferdingler merged 4 commits into
strands-agents:mainfrom
ferdingler:fix-260-cmdsub-deadline
Nov 24, 2026
Merged

ferdingler merged 4 commits into
strands-agents:mainfrom
ferdingler:fix-260-cmdsub-deadline

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

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 exec runs its substitutions twice is covered by #352.

I added a test over a few shapes, including [[ ]], exit, return and command -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

  • I ran the relevant test suites for the bindings I touched (cargo test --workspace --all-targets, pytest tests/python, npm test)
  • If I touched Rust, I ran cargo fmt and cargo clippy

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ferdingler

Copy link
Copy Markdown
Collaborator Author

@strandly-the-agent Please review this PR

@github-actions github-actions Bot added the bug Something isn't working label Nov 21, 2026

@strandly-the-agent strandly-the-agent 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.

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 for exit, return, command -v, and nested substitutions under Shell::execute.
  • 🟡 Test coverage (inline): every tested shape ends in a pipeline or for list, 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-targets on 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 -- --check clean; cargo clippy --workspace --all-targets has 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) and echo $(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:1832 matches on the text of the message check_limits returns. A deadline_expired() predicate on Process would 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 zzz prints the timeout line plus two recursion lines on base and nothing on head. The strip at src/exec.rs:2493-2497 assumes the parent reports, which it only does when the tail exits 0.
  • ⚪ Dropping captured_stderr.push_str loses 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, and while :; do :; done | grep -q zzz returns status 1 with empty stderr.

Comment thread src/exec.rs Resolved
Comment thread tests/shell_integration.rs Resolved
@ferdingler

Copy link
Copy Markdown
Collaborator Author

@strandly-the-agent Please review this PR

@strandly-the-agent strandly-the-agent 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.

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-targets on head: 20 suites, 2734 passed, 0 failed.
  • The new test, copied onto dbb6189, fails at echo $(sleep 5) $(echo second) with two recursion lines. Copied onto 94f16e1, it fails at [[ $(sleep 5) != $(echo second) ]] with only the sleep line.
  • cargo fmt --all -- --check clean; cargo clippy --workspace --all-targets has 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), the return and command -v shapes and three compound-into-grep -q shapes 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 exec double 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 both captured_stderr and err_msg, and the pipeline's post-expansion check adds one. From the CLI it is 2. Each further substitution on the line adds 2 under Shell::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, and while :; do :; done | grep -q zzz returns status 1 with empty stderr. I have not filed an issue for these; tell me if you want one.

@ferdingler
ferdingler merged commit a901678 into strands-agents:main Nov 24, 2026
37 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] A command substitution that starts after the deadline reports "maximum recursion depth exceeded"

4 participants