fix: bind approvals to prompt turns
This commit is contained in:
@@ -457,7 +457,7 @@ async fn structured_prompt(
|
||||
return error_response(session_error_status(&info.code), &info.code, &info.message);
|
||||
}
|
||||
};
|
||||
match acp.prompt(body.prompt) {
|
||||
match acp.prompt(body.prompt, turn) {
|
||||
Ok(done) => {
|
||||
let manager = s.manager.clone();
|
||||
tokio::spawn(async move {
|
||||
|
||||
@@ -159,7 +159,7 @@ impl Projection {
|
||||
/// reduced state, which is the client control surface, never in ACP data.
|
||||
pub fn request_approval(&mut self, nonce: String, request: Value) -> ProjectionUpdate {
|
||||
let row = self.append(
|
||||
format!("approval:{nonce}"),
|
||||
format!("approval:{}", uuid::Uuid::new_v4()),
|
||||
TranscriptRowKind::Approval,
|
||||
request.clone(),
|
||||
);
|
||||
@@ -698,6 +698,11 @@ mod tests {
|
||||
};
|
||||
assert_eq!(row.kind, TranscriptRowKind::Approval);
|
||||
assert!(row.data.get("nonce").is_none());
|
||||
assert!(!row.id.contains("secret"));
|
||||
let persisted =
|
||||
serde_json::to_string(&crate::sidecar::PersistedEvent::Approval { row: row.clone() })
|
||||
.unwrap();
|
||||
assert!(!persisted.contains("secret"));
|
||||
assert_eq!(
|
||||
projection.state().pending_approval.unwrap()["nonce"],
|
||||
"secret"
|
||||
@@ -725,5 +730,25 @@ mod tests {
|
||||
);
|
||||
assert!(update.state.pending_approval.is_none());
|
||||
assert_eq!(recovered.snapshot(0).rows, vec![row]);
|
||||
let replay = serde_json::to_string(&recovered.snapshot(1).rows).unwrap();
|
||||
assert!(!replay.contains("daemon-nonce"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stale_terminal_turn_cannot_clear_newer_approval() {
|
||||
let mut projection = Projection::default();
|
||||
let (first, _) = projection.begin_turn();
|
||||
projection.turn_lifecycle(TurnLifecycle::Cancel, first);
|
||||
let (second, _) = projection.begin_turn();
|
||||
projection.request_approval("second-nonce".into(), serde_json::json!({"tool":"bash"}));
|
||||
|
||||
assert!(projection
|
||||
.turn_lifecycle(TurnLifecycle::Finish, first)
|
||||
.is_none());
|
||||
assert_eq!(projection.active_turn(), Some(second));
|
||||
assert_eq!(
|
||||
projection.state().pending_approval.unwrap()["nonce"],
|
||||
"second-nonce"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1791,7 +1791,17 @@ fn start_acp_permission_pump(acp: &Arc<AcpSession>, events: Arc<Mutex<AcpEventSt
|
||||
return;
|
||||
};
|
||||
tokio::spawn(async move {
|
||||
while let Some(PermissionRequest { request, response }) = requests.recv().await {
|
||||
while let Some(PermissionRequest {
|
||||
turn,
|
||||
request,
|
||||
response,
|
||||
}) = requests.recv().await
|
||||
{
|
||||
let mut events = events.lock().await;
|
||||
if events.projection.active_turn() != Some(turn) {
|
||||
let _ = response.send(maestro_acp::schema::RequestPermissionOutcome::Cancelled);
|
||||
continue;
|
||||
}
|
||||
let nonce = Uuid::new_v4().to_string();
|
||||
let data = match serde_json::to_value(&request) {
|
||||
Ok(value) => value,
|
||||
@@ -1800,7 +1810,6 @@ fn start_acp_permission_pump(acp: &Arc<AcpSession>, events: Arc<Mutex<AcpEventSt
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let mut events = events.lock().await;
|
||||
// ACP requests serialize through its connection. Keep the newest
|
||||
// one authoritative if an adapter nonetheless overlaps them.
|
||||
cancel_pending_approvals(&mut events);
|
||||
|
||||
Reference in New Issue
Block a user