Skip to content

[BUG] After an expansion error on an exec line, the next command in the same session is silently skipped #363

Open

Description

@strandly-the-agent

Checks

  • I have updated to the latest minor and patch version of Strands Shell
  • 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 (crate version 0.0.0); also present on #352 head b92a56e

Language Runtime Version

Rust 1.100.0

Operating System

Debian 12 (aarch64)

Installation Method

built from source

Steps to Reproduce

Send three shell tool calls to one MCP session (cargo build --features cli --bin strands-shell):

cat > leak.jsonl <<'EOF'
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{}}
{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"shell","arguments":{"command":"exec echo \"${PORT:?PORT is required}\""}}}
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"shell","arguments":{"command":"echo important > important.txt; echo \"wrote st=$?\""}}}
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"shell","arguments":{"command":"cat important.txt"}}}
EOF
strands-shell --mcp < leak.jsonl

Expected Behavior

Call 1 fails with the PORT is required message. Call 2 runs normally: it prints wrote st=0 and creates the file. Call 3 prints important.

That is what happens when call 1 is the same line without exec (echo "${PORT:?PORT is required}").

Actual Behavior

Call stdout stderr exit_code
1 empty strands-shell: PORT is required (printed twice on main, once on #352) 2
2 empty empty 2
3 empty cat: no such file or directory: /home/lash/important.txt 1

Call 2 does not run at all: nothing is printed, the file is not written, and the only sign is exit code 2 with no message.

Additional Context

The expansion error sets proc.nounset_error. The normal path clears it after the pipeline (src/exec.rs:3569-3570, main @ dbb6189), but the exec arm returns before that (src/exec.rs:3508-3510), so the flag is still set when the next call starts and run_pipeline aborts on it (src/exec.rs:3802):

if shell_proc.nounset_error {
    shell_proc.last_exit = 2;
    return (2, String::new());
}

exec app "${PORT:?...}" and set -u with an unset variable on an exec line are common entrypoint idioms, and both trigger it. I reproduced this through --mcp only; I did not run the Python or Node.js bindings. The other builtin arms that expand arguments and return early (exit, ., command, break) may leave the flag set the same way; I did not verify each one myself.

Possible Solution

Clear proc.nounset_error on the early-return paths in execute_pipeline_checked, or reset it at the start of each top-level run.

Related Issues

Found while reviewing #352.

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