Originally created by: kumaakh
Originally owned by: kumaakh
Once a background agent is launched via the Agent tool, there is no way to cancel or stop it. The only interaction mechanism is SendMessage which resumes the agent — it cannot be used to stop it.
This becomes a problem when:
execute_prompt multiple times)execute_prompt calls to time outexecute_prompt calls against the same memberTwo background agents simultaneously pointing at the same member, both capable of calling execute_prompt. The PM has no way to stop either one.
The Agent tool (or a companion tool) should support a cancel or stop signal — e.g. SendMessage(to: '<agent_id>', stop: true) — that causes the agent to exit cleanly after its current tool call completes, without starting new ones.
Alternatively, background agents should have a TTL or a way to be listed and stopped via a fleet-level list_agents / stop_agent command.
Originally posted by: kumaakh
Technical direction: This is a Claude Code / Agent framework limitation — there is no cancel API today. The practical mitigation is fleet-server-side:
Approach:
cancel_taskoperation tosrc/tools/monitor-task.ts(or a newcancel-task.tstool): given atask_id, look up the PID from~/.fleet-tasks/<taskId>/task.pidandSIGTERM/process.killit. Update the task status tocancelled.execute_prompt, before launching a new task on a member, check if a previous task for that member is still alive (by PID). If so, kill it first (or return an error ifforceis not set). This covers the 'PM killed fleet sessions but dispatch agent retries' scenario.max_turnsbudget and a self-termination instruction in their prompt ('if you have retried more than N times, stop'). This is the only lever available until the Agent tool gains native cancellation.Key files:
src/tools/monitor-task.tsor newsrc/tools/cancel-task.tssrc/tools/execute-prompt.ts— add member-level previous-task kill before new dispatch~/.fleet-tasks/<taskId>/task.pid— already written by the long-running task infrastructureTicket changed by: kumaakh