Skip to content

[BUG] A redirect on eval, source or a function call is ignored when the caller installed an output writer #379

Open

Description

@strandly-the-agent

Checks

  • I have updated to the latest minor and patch version of Strands Shell (built from main @ dbb6189)
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Binding

Rust

Strands Shell Version

main @ dbb6189

Language Runtime Version

Rust 1.100.0

Operating System

Linux 6.18 (aarch64)

Installation Method

built from source

Steps to Reproduce

Append to tests/shell_integration.rs (it uses the existing expect_writers! macro, which installs channel writers on fd 1 and 2 with shell.proc.set_channel_writer and then calls shell.run), then run cargo test --test shell_integration zz_writer:

expect_writers!(
    zz_writer_eval_devnull,
    "eval 'echo hidden' >/dev/null; echo done",
    "done\n",
    |stderr: &str| assert_eq!(stderr, "")
);
expect_writers!(
    zz_writer_eval_file,
    "eval 'echo hidden' > /tmp/f; echo \"[$(cat /tmp/f)]\"",
    "[hidden]\n",
    |stderr: &str| assert_eq!(stderr, "")
);
expect_writers!(
    zz_writer_function_devnull,
    "f() { echo hidden; }; f >/dev/null; echo done",
    "done\n",
    |stderr: &str| assert_eq!(stderr, "")
);
expect_writers!(
    zz_writer_source_devnull,
    "echo 'echo hidden' > /tmp/s.sh; . /tmp/s.sh >/dev/null; echo done",
    "done\n",
    |stderr: &str| assert_eq!(stderr, "")
);
expect_writers!(
    zz_writer_eval_stderr_to_stdout,
    "eval 'echo hidden' >&2; echo done",
    "done\n",
    |stderr: &str| assert_eq!(stderr, "hidden\n")
);

Expected Behavior

All five pass: the redirect takes the output away from the stdout writer, as it does for a plain builtin and for a brace group. These two controls pass on the same commit:

expect_writers!(zz_control_builtin, "echo hidden >/dev/null; echo done", "done\n", |stderr: &str| assert_eq!(stderr, ""));
expect_writers!(zz_control_group, "{ echo hidden; } >/dev/null; echo done", "done\n", |stderr: &str| assert_eq!(stderr, ""));

Actual Behavior

All five fail. The stdout writer still receives the output and the redirect target gets nothing:

Test stdout writer got expected
zz_writer_eval_devnull hidden\ndone\n done\n
zz_writer_eval_file hidden\n[]\n [hidden]\n
zz_writer_function_devnull hidden\ndone\n done\n
zz_writer_source_devnull hidden\ndone\n done\n
zz_writer_eval_stderr_to_stdout hidden\ndone\n done\n (and hidden\n on the stderr writer)

Additional Context

Only embedders that install their own writers are affected. The same scripts behave correctly through the CLI (-c), where no writer is installed.

Found while reviewing #346, which routes command -v/-V through the same helper. It is not caused by that PR, but after it merges command -v cd >/dev/null has the same gap in writer mode: on #346's head e16b5fc, if command -v cd >/dev/null 2>&1; then echo have; fi gives the writer cd\nhave\n.

Possible Solution

run_redirected (src/exec.rs:3260) turns proc.capture on while the body runs (src/exec.rs:3301) but leaves the caller's fd 1 and fd 2 writers on proc, and an installed writer wins over the capture buffer (for example Process::out_msg, src/os.rs:858-860). The brace-group path sets the caller's fds aside first (src/exec.rs:2604-2614, added in #245); the same step here would likely fix it. I haven't traced every write path. One thing to watch: stderr that the body writes and the command does not redirect must still reach the caller's stderr writer, and I found no existing test that asserts that for eval or a function.

Related Issues

#203, #245, #226, #196, #294, #346

Activity

  1. added
    bug
    on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Fields

    Language

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions