docs: record why a resumed turn's send cannot hang an agent

Review asked twice whether `permit.send` can leave an agent Running with
no turn on its way. It cannot, and the reasoning is not local to the call,
so state it there.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bryan Helmkamp 2026-08-01 10:17:10 -04:00
parent 8c19b1e94a
commit a617eaa5eb
No known key found for this signature in database

View file

@ -775,6 +775,14 @@ impl SubAgentSupervisor {
if let Some((permit, generation)) = resumed {
self.publish();
// This send cannot fail: `OwnedPermit::send` returns `()`, and the
// capacity it needs was reserved above while the state lock was
// held. Should a concurrent close drop the receiver first, the
// command is discarded and the agent still cannot hang, because
// every path that stops the runner -- `run_shutdown` and the two
// drop impls -- is reached only after `begin_shutdown` has set
// `Closing` under this same lock. A waiter then observes the close
// and stops instead of waiting on a turn that will never run.
permit.send(StartTurn {
generation,
prompt: message.to_string(),