Skip to content

[Bug] exec tool emits empty text content block when command produces no stdout #73117

@agentbuilder1999

Description

@agentbuilder1999

Summary

When an exec command produces no stdout (e.g. grep with no matches, mkdir, cp, silent git commands), the exec runtime constructs a tool_result content block with text: "". Anthropic's API rejects empty text content blocks, causing the session to error out — typically after bulk operations that include several silent commands.

Root Cause

In bash-tools.exec-runtime:

const tailText = session.tail || session.aggregated;
const warningText = opts.warnings.length ? `${opts.warnings.join("\n")}\n\n` : "";
opts.onUpdate({
  content: [{
    type: "text",
    text: warningText + (tailText || "")  // ← empty string when no output
  }],
  ...
});

When both warningText and tailText are empty, text becomes "".

Fix

text: warningText + (tailText || "(no output)")

Single-character change. Falls back to a non-empty placeholder only when the command produced no output, keeping existing behaviour for all non-empty cases.

Reproduction

# Any silent command with no stdout
mkdir /tmp/test-dir
grep 'nonexistent' /dev/null

Run several in sequence in a session — subsequent API call fails with content block validation error.

Environment

  • OpenClaw v2026.4.11
  • Provider: Anthropic (amazon-bedrock)
  • Surface: telegram direct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions