fix: clarify structured prompt failures

This commit is contained in:
Miguel Palhas
2026-09-05 02:05:06 +01:00
parent be23a2b539
commit 3c638b08de
5 changed files with 124 additions and 35 deletions
+17 -7
View File
@@ -139,6 +139,14 @@ pub enum SessionError {
KillGuarded(maestro_protocol::InTheWay),
}
/// The result of claiming the next prompt turn for a structured ACP session.
#[derive(Debug)]
pub enum BeginAcpTurn {
Started(Arc<AcpSession>, u64),
InFlight,
Unavailable,
}
impl SessionError {
pub fn to_error_info(&self) -> ErrorInfo {
let code = match self {
@@ -476,25 +484,27 @@ impl SessionManager {
/// Begin an ACP turn only when the previous one has ended. The projection
/// lock makes the rejection and lifecycle update one indivisible action.
pub async fn begin_acp_turn(
&self,
id: Uuid,
) -> Result<Option<(Arc<AcpSession>, u64)>, SessionError> {
pub async fn begin_acp_turn(&self, id: Uuid) -> Result<BeginAcpTurn, SessionError> {
let (acp, stream) = {
let sessions = self.inner.sessions.lock().await;
let record = sessions.get(&id).ok_or(SessionError::NotFound(id))?;
if record.session.view != SessionView::Structured
|| record.session.status != SessionStatus::Running
{
return Ok(BeginAcpTurn::Unavailable);
}
(record.acp.clone(), record.acp_events.clone())
};
let (Some(acp), Some(stream)) = (acp, stream) else {
return Ok(None);
return Ok(BeginAcpTurn::Unavailable);
};
let mut stream = stream.lock().await;
if stream.projection.turn_active() {
return Ok(None);
return Ok(BeginAcpTurn::InFlight);
}
let (turn, update) = stream.projection.begin_turn();
let _ = stream.projected_live.send(update);
Ok(Some((acp, turn)))
Ok(BeginAcpTurn::Started(acp, turn))
}
/// Cancel an ACP turn and immediately clear its client-facing lifecycle.