fix: move sleep to only occur when recv returns empty, avoid message delivery delay

This commit is contained in:
damocles 2026-05-16 13:48:04 +02:00
parent 4ceae6cf67
commit d99e0812d0

View file

@ -166,7 +166,13 @@ async fn serve(
turn::emit_turn_end(&bus, &outcome);
bus.set_state(TurnState::Idle);
}
Ok(AgentResponse::Empty) => {}
Ok(AgentResponse::Empty) => {
// Idle: brief sleep before next poll to avoid busy-looping
// on consecutive Empty responses. The recv() call already
// waits up to 180s for messages, so this is just for
// responsiveness if recv() times out.
tokio::time::sleep(interval).await;
}
Ok(AgentResponse::Ok
| AgentResponse::Status { .. }
| AgentResponse::Recent { .. }
@ -180,7 +186,6 @@ async fn serve(
tracing::warn!(error = ?e, "recv failed; retrying");
}
}
tokio::time::sleep(interval).await;
}
}