Skip to content

Bash tool discards captured partial output on runner error (timeout/cancel), returning only the error reason #153

Closed

Description

@JAORMX

Summary

When the Bash command runner returns an error (timeout, cancellation, no-shell), the Bash tool throws away the partial stdout/stderr the runner already captured and returns only command failed to run: <err>. A command that produced useful output before being killed by its timeout tells the model nothing actionable.

The non-zero-exit path is fine (it returns full output + exit code) — only the runner-error path loses information.

Where it happens

The runner does return the captured output alongside the error:

internal/adapter/osfs/osfs.go — CommandRunner.Run:

res := tool.CommandResult{
	Stdout:   stdout.String(),   // captured-so-far (capped buffers)
	Stderr:   stderr.String(),
	ExitCode: 0,
}
if cerr := ctx.Err(); cerr != nil {
	return res, cerr   // res HAS the partial output
}

But the Bash tool discards res entirely on any error:

internal/adapter/tools/bash.go — Execute:

res, err := bt.runner.Run(ctx, args.Command, ws.Root())
if err != nil {
	// res (with partial Stdout/Stderr) is dropped here
	return session.NewToolError(in.ID, fmt.Sprintf("command failed to run: %v", err)), nil
}

So a command that times out after emitting output returns only command failed to run: context deadline exceeded.

Proposed fix

On a runner error, still surface the captured res.Stdout/res.Stderr (same combined-output formatting as the success path), then append a clear reason line, e.g.:

<partial stdout/stderr captured so far>
[command timed out after <N>ms; output above is partial]

Distinguish timeout vs cancel vs no-shell in the trailer. Keep it a tool error (is_error: true) so the model knows it failed, but give it the recoverable output to adapt (re-run with a longer timeout_ms, narrow the command, etc.).

Acceptance

  • A Bash command that produces output then hits its timeout_ms returns that output plus a clear timeout reason, as a tool error.
  • The success and non-zero-exit paths are byte-for-byte unchanged.
  • Test covers the timeout-with-partial-output case (innocuous command, e.g. echo hi; sleep 5 with a short timeout — assert the captured hi survives).

Related: sibling Subagent empty-return issue #152 — both are the same anti-pattern of a failure path discarding recoverable information.

Activity

  1. added
    bug
    on Jun 23, 2026
  2. added a commit that references this issue on Jun 23, 2026
    dfee4ac
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

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions