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:
- PowerShell scripts fail - Scripts return error exit codes, but the agent doesn’t detect them or cannot read error logs
- Build processes are interrupted - When a user interrupts a long-running process (Ctrl+C), the agent continues waiting indefinitely
- Commands fail silently - Scripts execute but produce no visible output, and the agent assumes success
- Exit codes are ignored - The
run_terminal_cmdtool 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
-
Create a PowerShell script that executes a failing command:
# test-error.ps1 cargo check --package nonexistent_package -
Execute the script via agent:
Execute: "C:\Program Files\PowerShell\7\pwsh.exe" -File "test-error.ps1" -
Expected: Agent detects error exit code and reads error message
-
Actual: Agent may not detect the error or cannot read the error log
Scenario 2: Interruption Not Detected
-
Start a long-running build process:
cargo build --release --package large_crate # This can take 20+ minutes -
Interrupt the process manually (Ctrl+C)
-
Expected: Agent detects interruption and stops waiting
-
Actual: Agent continues waiting indefinitely for the process to complete
Scenario 3: Output Not Captured
-
Create a PowerShell script with
Clear-Host:Clear-Host Write-Host "Starting build..." cargo build -
Execute via agent
-
Expected: Agent sees “Starting build…” message
-
Actual: Agent doesn’t see output, especially after
Clear-Host
Expected Behavior
- Real-time output streaming: Agent should receive output chunks as they are produced
- Interruption detection: Agent should detect when processes are interrupted and stop waiting
- Exit code verification: Agent should always check exit codes and treat non-zero as errors
- Error log reading: Agent should be able to read error logs generated by scripts
- 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:
- Read the error logs that scripts generate
- Detect when processes are interrupted
- See real-time output from long-running processes
Proposed Solutions
-
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 }) -
Process interruption detection:
- Periodically check if process is still running
- Detect interruption signals (SIGINT, SIGTERM)
- Return specific status when interrupted
-
Configurable timeout:
- Allow timeout per command
- Return specific error when timeout reached
- Allow agent to cancel long operations
-
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
-
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
-
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 } -
Ask the AI agent to execute the script:
Execute: "C:\Program Files\PowerShell\7\pwsh.exe" -File "test-error.ps1" -
Observe: The script will fail with exit code 1 (package doesn’t exist)
-
Expected Behavior:
- Agent receives exit code 1
- Agent reads the error message from cargo output
- Agent reports the error and suggests a fix
-
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
-
Start a long-running build process via agent:
Execute: cargo build --release --package large_crate # This can take 20+ minutes -
Wait for the build to start (you’ll see “Compiling…” messages in terminal)
-
Manually interrupt the process by pressing
Ctrl+Cin the terminal -
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
-
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
-
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" -
Execute the script via agent:
Execute: "C:\Program Files\PowerShell\7\pwsh.exe" -File "test-silent.ps1"
Expected Behavior
-
Expected Behavior:
- Agent sees “Starting build process…” message
- Agent sees “Build failed with exit code: 1” message
- Agent detects the failure and reports it
-
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
- Agent doesn’t see any output (especially after
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