Skip to content

Windows: bash tool with piped POSIX commands (e.g. | cat) causes "Not enough memory resources are available to process this command" #467

Description

@euxaristia

Summary

On Windows, the agent frequently emits shell commands using POSIX-style pipes to utilities that don't exist in cmd.exe (or cause parse failures):

gh pr view 465 --json reviews,comments -q '.reviews | length' 2>&1 | cat
gh api repos/.../pulls/465/reviews 2>&1 | cat
go test -run 'TestFoo|Bar' ...

These fail with the unhelpful error:

Not enough memory resources are available to process this command.
exit 1

Root cause

  • The model defaults to Unix idioms (| cat / | head to control output or bypass pagers, single quotes around args containing |).
  • cmd.exe has no cat/head. Pipes to missing commands + unquoted metachars in the remainder passed to cmd /d /c lead to command-line parse errors that surface as this memory warning.
  • Pre-flight detection only caught bare ls and cd /... paths. Piped utilities ran straight through.

This was reported via multiple TUI screenshots during PR review work (inspecting large review threads, etc.).

Fix on this branch

  • Extended detectShellCommandIssue (with regex + string fallbacks) to flag piped POSIX utilities (head|tail|grep|cat|wc|...) before execution on Windows.
  • Significantly improved guidance in the bash/exec_command tool descriptions and system <environment> block:
    • On Windows, wrap arguments containing | (or & > < ^) in double quotes: gh --jq ".foo | bar" (single quotes do not protect metachars in cmd.exe).
    • Prefer gh --jq / -q for server-side filtering, PowerShell Select-Object -First N for limiting output, or Zero's native tools (grep, read_file, glob, etc.).
  • Better error suggestions when bad commands slip through.
  • Complementary quoting fixes (/d /c raw command line, no temp script, no /s) so properly-quoted commands reach cmd.exe intact.

This prevents the bad patterns from ever being executed and teaches the model correct Windows shell usage going forward.

Changes

internal/tools/shell_runtime.go

  • Added windowsPosixUtilityPattern (and kept/expanded coverage) to catch piped utilities early.
  • Updated detectShellCommandIssue and suggestions.
  • Enhanced shellGuidanceForGOOS with explicit Windows quoting advice for metachars in args.

internal/tools/bash_tool_test.go

  • Added/updated tests for the new detection (piped POSIX, avoiding false positives on filenames like tail-log.sh).

internal/agent/system_prompt.go

  • Improved the Windows shell syntax guidance in the environment block.

(Plus minor related cleanups in safe_command suggestions for Windows.)

Test plan

  • go test ./internal/tools -run 'TestDetectShellCommandIssue' -count=1 — all pass (including new cases and "unrelated" filename cases).
  • Manual: on Windows, ask the agent to inspect a PR with many comments or run go test -run 'A|B'. It now uses --jq or double-quoted filters and avoids | cat.
  • The "memory" errors and wasted turns on | cat / | head no longer occur.

Fixes the class of issues seen in the attached screenshots during work on PRs #464/#465.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions