Skip to content

fix(find): forward -exec child stderr - #227

Merged
ferdingler merged 4 commits into
strands-agents:mainfrom
ferdingler:fix/find-exec-stderr
Nov 12, 2026
Merged

ferdingler merged 4 commits into
strands-agents:mainfrom
ferdingler:fix/find-exec-stderr

Conversation

@ferdingler

@ferdingler ferdingler commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Description

find -exec passed on the command's stdout but quietly dropped its stderr. So if the command failed you saw nothing, where GNU find shows the error:

$ find d -name x -exec cat /nope \;
$

Now find writes each command's stderr right after its stdout, for both \; and +. Redirects on the find itself apply to it too, so 2>/dev/null, 2>file and 2>&1 | all work. This is the same fix as #213 for xargs. I didn't touch find's exit status. GNU returns 1 when a + command fails and we still return 0, so that's left for a separate fix.

I added tests for both forms, a missing command, the three redirects, stdout staying the same, and the order of output when two -execs run on each file. On main the forwarding tests fail, and with the change everything passes. The example above now prints strands-shell: cat: no such file or directory: /nope. I also tried a smaller version that sends the stderr through the shell's error-message path, but it lost messages once a second -exec ran, and the ordering test caught that.

Related Issues

Part of #207

Documentation PR

N/A

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.

  • 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
ferdingler marked this pull request as ready for review November 9, 2026 23:51
@ferdingler
ferdingler requested a review from a team as a code owner November 9, 2026 23:51
@ferdingler

Copy link
Copy Markdown
Collaborator Author

@strandly-the-agent please review

@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. The fix is correct and matches #213 (xargs) line for line: io::stderr().ok(), with the child's stderr written right after its stdout. I found no blocking issues.

Taking fd 2 is safe here. proc.err_msg writes through err_tx, not the fd table, and find's only err_msg (the parse error, find.rs:365) runs before the take. Children that write to >&2 themselves (functions, sourced scripts) still forward correctly, and I saw no bad fd 2 errors.

What I verified
  • Head b1286d2. cargo test --test shell_integration find_exec gives 13 passed. With the source reverted, 6 of those fail, so the new tests catch the bug. The full shell_integration suite passes (1595).
  • I compared PR and main binaries by hand. The PR now forwards stderr through 2>&1, $(… 2>&1), 2>/dev/null, 2>file, 2>&1 >/dev/null |, function and { } group redirects, two -execs per file (ordering), + (a b err, same as GNU), and nested find -exec find -exec. 2>&- and >&- behave the same as on main. 10k lines of child stderr give no hang or truncation.
  • Probe log: strands-agents/shell/pr/227/find-exec-stderr-probes.txt (artifacts).
Non-blocking (2)
  • ⚪ Inside one child, stdout and stderr are buffered separately, so g(){ echo o1; echo e1 >&2; echo o2; }; find f -exec g \; 2>&1 gives o1 o2 e1 where GNU gives o1 e1 o2. This comes from capture = true in exec_fork, and #213 does the same. It's still a strict improvement over dropping e1, and it might be worth a line in the PR body.
  • ⚪ Because the stderr write uses ?, find stops at the first failed write when the stderr reader has gone away (find d -exec g {} \; 2>&1 >o.txt | true leaves 1 line in o.txt; main leaves 10). This is how find's stdout writes already behave, and how GNU find behaves under SIGPIPE, so I'd leave it.

Newly visible, and already broken on main (not caused by this PR): -exec xargs … now shows xargs: bad fd 0, and -exec sh -c … shows -c: no such file or directory. Main hid both of these because it dropped stderr.

@ferdingler
ferdingler merged commit 2cd0212 into strands-agents:main Nov 12, 2026
30 checks passed
@ferdingler
ferdingler deleted the fix/find-exec-stderr branch November 12, 2026 17: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.

2 participants