| 63 | } |
| 64 | |
| 65 | pub(super) async fn save(&self) -> Result<()> { |
| 66 | let store = match &self.session_store { |
| 67 | Some(store) => store, |
| 68 | None => return Ok(()), |
| 69 | }; |
| 70 | |
| 71 | let history = read_or_recover(&self.history).clone(); |
| 72 | let verification_reports = read_or_recover(&self.verification_reports).clone(); |
| 73 | let data = build_session_data_snapshot(SessionDataSnapshotInput { |
| 74 | session_id: &self.session_id, |
| 75 | workspace: &self.workspace, |
| 76 | config: &self.config, |
| 77 | model_name: &self.model_name, |
| 78 | history, |
| 79 | tenant_id: self.tenant_id.as_deref(), |
| 80 | principal: self.principal.as_deref(), |
| 81 | agent_template_id: self.agent_template_id.as_deref(), |
| 82 | correlation_id: self.correlation_id.as_deref(), |
| 83 | }) |
| 84 | .await; |
| 85 | |
| 86 | store.save(&data).await?; |
| 87 | store |
| 88 | .save_artifacts(&self.session_id, &self.tool_executor.artifact_store()) |
| 89 | .await?; |
| 90 | store |
| 91 | .save_trace_events(&self.session_id, &self.trace_sink.events()) |
| 92 | .await?; |
| 93 | store |
| 94 | .save_run_records(&self.session_id, &self.run_store.records().await) |
| 95 | .await?; |
| 96 | store |
| 97 | .save_verification_reports(&self.session_id, &verification_reports) |
| 98 | .await?; |
| 99 | store |
| 100 | .save_subagent_tasks(&self.session_id, &self.subagent_tasks.list().await) |
| 101 | .await?; |
| 102 | tracing::debug!("Session {} saved", self.session_id); |
| 103 | Ok(()) |
| 104 | } |
| 105 | |
| 106 | pub(super) async fn auto_save_if_enabled(&self) { |
| 107 | if self.auto_save { |