Skip to content

[BUG] A function used as a pipeline stage emits nothing once its output passes max_output, and replaces non-UTF-8 bytes #382

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

0.0.0 (main at dbb6189)

Language Runtime Version

Rust 1.100.0

Operating System

Debian 12 (aarch64)

Installation Method

built from source

Steps to Reproduce

Run with the CLI and default limits (max_output is 1 MiB), in an empty directory: strands-shell -c '<script>'.

l=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
l=$l$l$l$l$l$l$l$l
l=$l$l$l$l$l$l$l$l
i=0
while [ $i -lt 100 ]; do echo "$i$l"; i=$((i+1)); done > a
f() { cat; }
cat a a a | f | wc -c
echo "status=$?"
cat a a a | cat | wc -c
cat a | f | wc -c
printf '\377\376\n' | f | base64
printf '\377\376\n' | cat | base64

a is 409,890 bytes, so cat a a a sends 1,229,670 bytes through the stage.

Expected Behavior

A function stage passes its output on as a plain command stage does. bash 5.2.15 prints:

1229670
status=0
1229670
409890
//4K
//4K

Actual Behavior

      0
status=0
1229670
 409890
77+977+9Cg==
//4K

Over 1 MiB the function stage writes nothing downstream. The status is 0 and stderr is empty, so the caller cannot tell that data was lost. Below the limit the bytes arrive, but \377\376 becomes two U+FFFD characters.

Additional Context

Found while reviewing #357, which had the same symptom for command NAME stages until it stopped routing them through this path.

In src/exec.rs at dbb6189, a function stage runs its body with state_proc.capture = true (line 4278). The body's pipelines then drain into a String with os::read_to_string_lossy_limited(&mut reader, max_output).await.unwrap_or_default() (lines 4371-4377). read_to_string_lossy_limited (src/os.rs:1048) returns Err when the limit is passed, so unwrap_or_default() turns the whole output into an empty string, and it converts bytes that are not UTF-8 lossily. The captured text is written to the stage's stdout only after the body finishes.

I did not test the Python, Node.js or WASM bindings.

Possible Solution

Let the commands in a function stage's body write to the stage's stdout directly, as ordinary stages do, so the output streams and stays as bytes. If the capture has to stay, report the overflow on stderr with a non-zero status.

Related Issues

#357, #323

Activity

  1. added
    bug
    rust
    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

    bugrust

    Type

    Fields

    Language

    Rust

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions