Mohamed Boudra b1bcb8e6df Fix send_agent_prompt to interrupt running agent before sending new prompt
Problem: When calling send_agent_prompt on an agent that already has an
active run, it errored with "Agent {id} already has an active run"
instead of interrupting and sending the prompt (like the app does).

Solution: Modified the send_agent_prompt MCP handler in mcp-server.ts to:
- Check if agent has an active run (lifecycle === "running" || pendingRun)
- If running, call cancelAgentRun() to interrupt the current run
- Poll wait (max 5s, 50ms interval) for agent to become idle
- Then start the new run

This matches the behavior of session.ts:interruptAgentIfRunning().

The polling wait is necessary because cancelAgentRun() only initiates
cancellation (fires and forgets via void promise.catch()) and doesn't
wait for the pendingRun to be cleared.

Added E2E test "send_agent_prompt interrupts running agent and processes
new message" that verifies the fix works correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 20:10:44 +07:00
2025-12-25 11:31:56 +07:00
Description
Languages
TypeScript 98.1%
JavaScript 1.3%
Shell 0.1%
Swift 0.1%