AI Agent Cannot Detect Errors and Interruptions in CMD/PowerShell Scripts

Where does the bug appear (feature/product)?

Cursor IDE

Describe the Bug

AI Agent Cannot Detect Errors and Interruptions in PowerShell Scripts

Category: Bug Reports


Where does the bug appear (feature/product)?

Cursor IDE - AI Agent Terminal / run_terminal_cmd tool


Describe the Bug

The AI agent (Claude Sonnet) cannot reliably detect when:

  1. PowerShell scripts fail - Scripts return error exit codes, but the agent doesn’t detect them or cannot read error logs
  2. Build processes are interrupted - When a user interrupts a long-running process (Ctrl+C), the agent continues waiting indefinitely
  3. Commands fail silently - Scripts execute but produce no visible output, and the agent assumes success
  4. Exit codes are ignored - The run_terminal_cmd tool returns exit codes, but the agent doesn’t consistently check them

This affects:

  • Integrated terminal execution
  • Agent terminal execution
  • Long-running build processes (Rust cargo build, etc.)
  • PowerShell scripts that execute multiple commands sequentially

Steps to Reproduce

Scenario 1: Error Detection Failure

  1. Create a PowerShell script that executes a failing command:

    # test-error.ps1
    cargo check --package nonexistent_package
    
  2. Execute the script via agent:

    Execute: "C:\Program Files\PowerShell\7\pwsh.exe" -File "test-error.ps1"
    
  3. Expected: Agent detects error exit code and reads error message

  4. Actual: Agent may not detect the error or cannot read the error log

Scenario 2: Interruption Not Detected

  1. Start a long-running build process:

    cargo build --release --package large_crate
    # This can take 20+ minutes
    
  2. Interrupt the process manually (Ctrl+C)

  3. Expected: Agent detects interruption and stops waiting

  4. Actual: Agent continues waiting indefinitely for the process to complete

Scenario 3: Output Not Captured

  1. Create a PowerShell script with Clear-Host:

    Clear-Host
    Write-Host "Starting build..."
    cargo build
    
  2. Execute via agent

  3. Expected: Agent sees “Starting build…” message

  4. Actual: Agent doesn’t see output, especially after Clear-Host


Expected Behavior

  1. Real-time output streaming: Agent should receive output chunks as they are produced
  2. Interruption detection: Agent should detect when processes are interrupted and stop waiting
  3. Exit code verification: Agent should always check exit codes and treat non-zero as errors
  4. Error log reading: Agent should be able to read error logs generated by scripts
  5. Timeout mechanism: Long-running processes should have configurable timeouts

Operating System

Windows 10/11

  • Build: 10.0.26220
  • Shell: PowerShell Core 7 (C:\Program Files\PowerShell\7\pwsh.exe)

For AI issues: which model did you use?

Claude 3.5 Sonnet (via Cursor IDE)


For AI issues: add Request ID with privacy disabled

[If available, add Request ID from failed operations]


Additional Information

Real-World Impact

Project Context:

  • Developing a Rust project (fork of Zed Editor)
  • Using PowerShell scripts to automate cargo build, cargo check, cargo test
  • Build times: 15-30 minutes for release builds
  • Scripts detect errors correctly, but agent cannot read error logs

Example from our project:

# Script: project-mini/scripts/run-fase-2.ps1
# Executes: cargo test --package mini_ui

# Script output (correctly detects error):
[2/3] Executando 'FASE 2: Testes Unitários (cargo test)'...
✗ O comando retornou um erro, verifique o log em: D:\proj\mini\project-mini\logs\fase2-cargo-test.log
[Tipo de erro: exit-code]

# Agent behavior:
# - Script correctly detects error ✅
# - Script correctly cancels next command ✅
# - BUT agent cannot read the log to identify specific error ❌
# - User must manually execute script and send log to agent ❌

Productivity Impact:

  • Each compilation error requires manual intervention
  • Time lost: ~5-10 minutes per error
  • Project phases taking 2x longer than estimated
  • Agent gets “stuck” waiting for interrupted processes

Technical Details

Affected Commands:

  • cargo build --release (15-30 minutes)
  • cargo check --workspace (2-5 minutes)
  • cargo test --workspace (3-10 minutes)
  • Any PowerShell script executing long processes

Script Structure:
Our scripts use:

  • Exit code checking
  • Error keyword detection in logs
  • Cascading cancellation (stop subsequent commands if one fails)
  • Individual log files per command

The scripts work correctly - the problem is that the agent cannot:

  1. Read the error logs that scripts generate
  2. Detect when processes are interrupted
  3. See real-time output from long-running processes

Proposed Solutions

  1. Real-time output streaming:

    run_terminal_cmd({
      command: "cargo build --release",
      streamOutput: true,
      onOutput: (chunk: string) => {
        // Agent receives output chunks in real time
      },
      timeout: 3600000 // 1 hour
    })
    
  2. Process interruption detection:

    • Periodically check if process is still running
    • Detect interruption signals (SIGINT, SIGTERM)
    • Return specific status when interrupted
  3. Configurable timeout:

    • Allow timeout per command
    • Return specific error when timeout reached
    • Allow agent to cancel long operations
  4. Mandatory exit code verification:

    • Always check exit code after execution
    • Throw exception or return error when exit code != 0
    • Clearly document that exit code 0 doesn’t guarantee success
  5. Capture output even with Clear-Host:

    • Capture all process output, including before Clear-Host
    • Or disable Clear-Host when executed via run_terminal_cmd
    • Provide flag to control screen clearing behavior

Workaround (Current)

We are currently using a workaround:

  • User executes scripts manually
  • User reads error logs and sends them to agent
  • Agent fixes errors based on provided logs

Limitations:

  • Requires constant manual intervention
  • Not scalable
  • Significantly impacts productivity

Does this stop you from using Cursor?

Sometimes - I can sometimes use Cursor, but this significantly impacts productivity and requires constant manual intervention for build/compilation tasks.


Priority

HIGH - This problem significantly impacts productivity and reliability of the AI agent in projects involving long builds and compilation processes.


Note: This issue was identified during development of the “mini editor” project (fork of Zed Editor) using Cursor IDE with Claude Sonnet agent on Windows 10/11.

Steps to Reproduce

Scenario 1: Error Detection Failure

  1. Create a PowerShell script (test-error.ps1) that executes a failing command:

    # test-error.ps1
    $ErrorActionPreference = "Stop"
    cargo check --package nonexistent_package_xyz
    if ($LASTEXITCODE -ne 0) {
        Write-Host "Error detected: Exit code $LASTEXITCODE"
        exit $LASTEXITCODE
    }
    
  2. Ask the AI agent to execute the script:

    Execute: "C:\Program Files\PowerShell\7\pwsh.exe" -File "test-error.ps1"
    
  3. Observe: The script will fail with exit code 1 (package doesn’t exist)

  4. Expected Behavior:

    • Agent receives exit code 1
    • Agent reads the error message from cargo output
    • Agent reports the error and suggests a fix
  5. Actual Behavior:

    • Agent may not detect the error exit code
    • Agent cannot read the error log/output
    • Agent assumes success or gets stuck waiting
    • User must manually check the terminal to see the error

Scenario 2: Interruption Not Detected

  1. Start a long-running build process via agent:

    Execute: cargo build --release --package large_crate
    # This can take 20+ minutes
    
  2. Wait for the build to start (you’ll see “Compiling…” messages in terminal)

  3. Manually interrupt the process by pressing Ctrl+C in the terminal

  4. Expected Behavior:

    • Agent detects that the process was interrupted
    • Agent stops waiting for the command to complete
    • Agent reports that the process was interrupted
    • Agent can continue with next steps
  5. Actual Behavior:

    • Agent continues waiting indefinitely
    • Agent doesn’t detect the interruption
    • Agent appears “frozen” or “stuck”
    • User must manually cancel the agent’s operation
    • Agent may wait for hours before user notices

Scenario 3: Output Not Captured / Silent Failures

  1. Create a PowerShell script (test-silent.ps1) that fails silently:

    # test-silent.ps1
    Clear-Host
    Write-Host "Starting build process..."
    cargo check --package nonexistent_package 2>&1 | Out-Null
    if ($LASTEXITCODE -ne 0) {
        Write-Host "Build failed with exit code: $LASTEXITCODE"
        exit $LASTEXITCODE
    }
    Write-Host "Build completed successfully"
    
  2. Execute the script via agent:

    Execute: "C:\Program Files\PowerShell\7\pwsh.exe" -File "test-silent.ps1"
    

Expected Behavior

  1. Expected Behavior:

    • Agent sees “Starting build process…” message
    • Agent sees “Build failed with exit code: 1” message
    • Agent detects the failure and reports it
  2. Actual Behavior:

    • Agent doesn’t see any output (especially after Clear-Host)
    • Agent doesn’t detect the failure
    • Agent assumes success because no error was visible
    • Script may have failed, but agent continues as if it succeeded

Operating System

Windows 10/11

Current Cursor Version (Menu → About Cursor → Copy)

Versão: 2.1.50 (system setup)
Confirmar: 1.105.1
Data: 56f0a83df8e9eb48585fcc4858a9440db4cc7770
Electron: 2025-12-06T23:39:52.834Z
ElectronBuildId: 37.7.0
Chromium: undefined
Node.js: 138.0.7204.251
V8: 22.20.0
SO: 13.8.258.32-electron.0

For AI issues: which model did you use?

(AUTO), most common are Sonnet 3.5, 4 and 4.5

Does this stop you from using Cursor

No - Cursor works, but with this issue

Hey, thanks for the report. This is part of a known issue with the new terminal on Windows that affects error detection, command output, and process interruption.

Details and discussion: Agent Terminal not working

This topic was automatically closed 22 days after the last reply. New replies are no longer allowed.