Skip to content

Interrupt an agent with its correcting message - #116

Merged
mavam merged 2 commits into
mainfrom
topic/send-interrupt
Oct 21, 2026
Merged

mavam merged 2 commits into
mainfrom
topic/send-interrupt

Conversation

@mavam

@mavam mavam commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

🔍 Problem

Messages could only steer an agent's current work or wait for it to finish. Correcting a long-running or stuck agent required stopping it, which also withdrew its job and stopped the agents it spawned.

🛠️ Solution

  • agent_send takes mode: "steer" | "followUp" | "interrupt" (default steer) on both surfaces: Pi's tool and agents' own tool. Agents can interrupt whoever they can message; stopped, missing, and not-yet-started recipients are refused before anything is aborted.
  • An interrupt aborts the recipient's work under its turn, records the interrupt watermark, then sends the message. The job and spawned agents stay; owed results wait for the next answer, as with Esc. Results report how many queued messages were dropped.
  • Replay-safe correction for agents' sends: the message is logged only after the abort and watermark, so a resumed send that finds it logged or submitted never aborts the work the message started; one that crashed earlier aborts again, then logs.
  • Cancellation: the abort plus watermark run in the service, not bound to the sender's call, while the sender holds the recipient's turn. A cancelled sender stops waiting at once and logs nothing, so agents interrupting each other can't deadlock, and the watermark still lands, so the recipient's results don't restart it. Callers cancelled while queued for a turn give it up.
  • Compatibility: followUp: true still works when mode is absent, including in the call-line view.

💬 Review

  • Focus: turn holding in MessagingHub.turn and the ordering abort → watermark → log → submit.
  • Not crash-atomic: a crash between abort and Pi's request record leaves the agent interrupted without the correction; a cancelled agent sender leaves the recipient interrupted (results deferred) without the message.
  • Not guaranteed first: other agents' messages can't land in between, but user prompts and plain parent sends bypass the turn.
  • Aborts wait for the recipient's tools to stop; a tool ignoring cancellation holds up the send and that recipient's turn.
  • Tests: parent interrupt (dropped count, job and child kept), agent interrupt answering the job, crash replay without re-abort, mutual interrupts, a sender cancelled mid-interrupt keeping results deferred, legacy followUp.

mavam added 2 commits October 21, 2026 17:40
agent_send takes a mode instead of the followUp flag: steer, followUp,
or interrupt. An interrupt aborts the recipient's work under its turn,
drops its queued messages, and sends the message, keeping the job and
the agents it spawned. Pi and agents both get it; agents can interrupt
whoever they can message, and stopped agents still refuse.

An agent's interrupting send records its message together with the
interrupt after the abort, so a resumed send never aborts the work its
message started. Turns waited on by an aborted caller are given up, so
agents that interrupt each other can't deadlock. Calls that set
followUp keep working.
An agent's interrupting send aborted its recipient through its own call,
so cancelling that call while the recipient wound down skipped the
interrupt's watermark. The recipient's group results then restarted it
without the correction.

The service now aborts and records the watermark for the send, under the
recipient's turn, whether or not the sender still waits. A cancelled
sender stops waiting at once, so agents interrupting each other still
can't deadlock, and logs nothing. Also wait for the projection in the
crash replay test instead of reading it before it refreshed.
@mavam
mavam merged commit 9e2e3d0 into main Oct 21, 2026
3 checks passed
@mavam
mavam deleted the topic/send-interrupt branch October 21, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant