| 441 | } |
| 442 | |
| 443 | pub async fn cancel(&self) -> bool { |
| 444 | let current_run_id = self.current_run_id.lock().await.clone(); |
| 445 | if current_run_id.as_deref() != Some(self.id.as_str()) { |
| 446 | return false; |
| 447 | } |
| 448 | |
| 449 | let token = self.cancel_token.lock().await.clone(); |
| 450 | if let Some(token) = token { |
| 451 | token.cancel(); |
| 452 | let _ = self.store.mark_cancelled(&self.id).await; |
| 453 | if let Some(executor) = &self.hook_executor { |
| 454 | executor |
| 455 | .record_run_cancelled(&self.id, &self.session_id, Some("cancelled by host")) |
| 456 | .await; |
| 457 | } |
| 458 | true |
| 459 | } else { |
| 460 | false |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | fn apply_event_to_snapshot(run: &mut RunSnapshot, event: &AgentEvent) { |