Terminal Command Approval Flow Broken in Agent Mode

Issue Description

When in the chat with Agent Mode enabled and Auto-run terminal commands set to “Ask every time”, the terminal command approval flow intermittently breaks. The agent gets stuck waiting for approval, but the command never appears in the chat interface for the user to approve.

Steps to Reproduce

  1. Make sure Auto-run terminal commands in settings is set to “Ask every time”

  2. Ask the agent to perform a Git-related task (e.g., git status, git commit).

  3. Observe that:

    • The agent appears to be waiting for terminal command approval.

    • No terminal command is shown in the chat for the user to approve.

  4. Stop the agent manually.

  5. The terminal command then appears in the chat, but is marked as “Cancelled”, making it impossible to approve or retry.

Expected Behavior

  • The terminal command should appear in the chat immediately when the agent requests approval.

  • The user should be able to approve or deny the command without needing to stop the agent.

Actual Behavior

  • The agent gets stuck waiting for approval.

  • The terminal command is not shown in the chat.

  • Stopping the agent reveals the command, but it’s already cancelled and cannot be approved.

Additional Observations

  • This issue does not occur consistently.

  • It seems more frequent when the chat history is long, possibly due to UI or memory handling.

  • It also appears more often with short terminal commands (e.g., git status) than with longer ones (e.g., a detailed git commit message).

  • This suggests a possible timing or rendering issue in the chat interface when handling quick command requests.