From a892e783f8676aaa9113b66715d7d470e71b4d4f Mon Sep 17 00:00:00 2001 From: aien Date: Mon, 21 Sep 2026 18:22:21 -0500 Subject: [PATCH 1/2] fix(cortex): rustfmt session handler tests for CI Sovereign CI on a9809d2 failed cargo fmt --check in handlers.rs. --- crates/cortex-rs/src/handlers.rs | 43 ++++++++++++++------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/crates/cortex-rs/src/handlers.rs b/crates/cortex-rs/src/handlers.rs index 1000f2d1..8610e47c 100644 --- a/crates/cortex-rs/src/handlers.rs +++ b/crates/cortex-rs/src/handlers.rs @@ -654,9 +654,10 @@ mod tests { metadata: json!({"task": "concurrency_test"}), }; - let (status, Json(session)) = create_session_handler(State(state.clone()), Json(session_input)) - .await - .unwrap(); + let (status, Json(session)) = + create_session_handler(State(state.clone()), Json(session_input)) + .await + .unwrap(); assert_eq!(status, StatusCode::CREATED); assert_eq!(session.status, "active"); assert_eq!(session.agent_id, Some("agent-atlas".to_string())); @@ -664,9 +665,10 @@ mod tests { let session_id = session.id; // 2. Get session - let Json(fetched_session) = get_session_handler(State(state.clone()), AxumPath(session_id.clone())) - .await - .unwrap(); + let Json(fetched_session) = + get_session_handler(State(state.clone()), AxumPath(session_id.clone())) + .await + .unwrap(); assert_eq!(fetched_session.id, session_id); assert_eq!(fetched_session.status, "active"); @@ -779,20 +781,16 @@ mod tests { assert_eq!(get_wm["watermarkSeq"], 2); // 7. Close session - let Json(close_res) = close_session_handler( - State(state.clone()), - AxumPath(session_id.clone()), - ) - .await - .unwrap(); + let Json(close_res) = + close_session_handler(State(state.clone()), AxumPath(session_id.clone())) + .await + .unwrap(); assert_eq!(close_res["status"], "closed"); - let Json(closed_session) = get_session_handler( - State(state.clone()), - AxumPath(session_id.clone()), - ) - .await - .unwrap(); + let Json(closed_session) = + get_session_handler(State(state.clone()), AxumPath(session_id.clone())) + .await + .unwrap(); assert_eq!(closed_session.status, "closed"); assert!(closed_session.closed_at.is_some()); } @@ -912,12 +910,9 @@ mod tests { minimum_verification: None, }; - let Json(context) = compile_context_handler( - State(state.clone()), - Json(mem_query), - ) - .await - .unwrap(); + let Json(context) = compile_context_handler(State(state.clone()), Json(mem_query)) + .await + .unwrap(); assert!(!context.episodic.is_empty()); assert!(!context.canonical.is_empty()); From a2cad5b500f60c1d17fc2aeebb4b9434b1cd6b20 Mon Sep 17 00:00:00 2001 From: aien Date: Mon, 21 Sep 2026 18:27:00 -0500 Subject: [PATCH 2/2] fix(cortex): clear clippy -D warnings on ledger compiler --- crates/cortex-rs/src/compiler.rs | 9 ++----- crates/cortex-rs/src/db.rs | 40 ++++++++++++++++++-------------- crates/cortex-rs/src/workers.rs | 30 ++++++++++++------------ 3 files changed, 39 insertions(+), 40 deletions(-) diff --git a/crates/cortex-rs/src/compiler.rs b/crates/cortex-rs/src/compiler.rs index 1e290a5a..f1ce4a45 100644 --- a/crates/cortex-rs/src/compiler.rs +++ b/crates/cortex-rs/src/compiler.rs @@ -6,9 +6,10 @@ use crate::db::Database; use crate::models::{ClaimStatus, VerificationTier}; use crate::security::SecurityMembrane; -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)] #[serde(rename_all = "snake_case")] pub enum MemoryIntent { + #[default] Conversation, Coding, Planning, @@ -18,12 +19,6 @@ pub enum MemoryIntent { MemoryAdjudication, } -impl Default for MemoryIntent { - fn default() -> Self { - Self::Conversation - } -} - #[derive(Debug, Clone, Deserialize)] #[serde(rename_all = "camelCase")] pub struct MemoryQuery { diff --git a/crates/cortex-rs/src/db.rs b/crates/cortex-rs/src/db.rs index 7a193826..1ce3d9b6 100644 --- a/crates/cortex-rs/src/db.rs +++ b/crates/cortex-rs/src/db.rs @@ -216,7 +216,7 @@ pub struct LegacyConnAdapter { } impl LegacyConnAdapter { - pub fn lock(&self) -> std::sync::LockResult { + pub fn lock(&self) -> Result>> { let conn = self .reader_pool .acquire() @@ -249,6 +249,17 @@ fn ensure_space_internal(conn: &Connection, slug: &str) -> Result { Ok(new_id) } +pub struct SessionSummaryWrite<'a> { + pub session_id: &'a str, + pub branch_id: &'a str, + pub level: i64, + pub start_seq: i64, + pub end_seq: i64, + pub summary_text: &'a str, + pub source_hash: &'a str, + pub processor_version: &'a str, +} + impl Database { pub fn open>(path: P) -> Result { let path_buf = path.as_ref().to_path_buf(); @@ -1236,7 +1247,7 @@ impl Database { input: &SessionEventInput, ) -> Result { let branch = input.branch_id.as_deref().unwrap_or("main"); - let results = self.batch_append_events(session_id, branch, &[input.clone()])?; + let results = self.batch_append_events(session_id, branch, std::slice::from_ref(input))?; results.into_iter().next().ok_or_else(|| { rusqlite::Error::SqliteFailure( rusqlite::ffi::Error::new(rusqlite::ffi::SQLITE_INTERNAL), @@ -1476,24 +1487,17 @@ impl Database { // Summaries, Candidates & Provenance (Phases 2 & 3) // ========================================================================= - pub fn insert_session_summary( - &self, - session_id: &str, - branch_id: &str, - level: i64, - start_seq: i64, - end_seq: i64, - summary_text: &str, - source_hash: &str, - processor_version: &str, - ) -> Result { + pub fn insert_session_summary(&self, input: &SessionSummaryWrite) -> Result { let id = Uuid::new_v4().to_string(); let now = Utc::now().to_rfc3339(); - let sid = session_id.to_string(); - let bid = branch_id.to_string(); - let text = summary_text.to_string(); - let hash = source_hash.to_string(); - let ver = processor_version.to_string(); + let sid = input.session_id.to_string(); + let bid = input.branch_id.to_string(); + let level = input.level; + let start_seq = input.start_seq; + let end_seq = input.end_seq; + let text = input.summary_text.to_string(); + let hash = input.source_hash.to_string(); + let ver = input.processor_version.to_string(); let summary = SessionSummary { id: id.clone(), diff --git a/crates/cortex-rs/src/workers.rs b/crates/cortex-rs/src/workers.rs index efe10e62..f434960f 100644 --- a/crates/cortex-rs/src/workers.rs +++ b/crates/cortex-rs/src/workers.rs @@ -1,7 +1,7 @@ use sha2::{Digest, Sha256}; use std::sync::Arc; -use crate::db::Database; +use crate::db::{Database, SessionSummaryWrite}; use crate::models::{CandidateWriteInput, MemoryCandidate, SessionSummary, VerificationTier}; use crate::security::{SafeEventView, SecurityMembrane}; @@ -72,16 +72,16 @@ impl SummaryWorker { }; // Insert Level-0 summary - let summary = self.db.insert_session_summary( + let summary = self.db.insert_session_summary(&SessionSummaryWrite { session_id, branch_id, - 0, + level: 0, start_seq, end_seq, - &summary_text, - &source_hash, - SUMMARY_PROCESSOR_VERSION, - )?; + summary_text: &summary_text, + source_hash: &source_hash, + processor_version: SUMMARY_PROCESSOR_VERSION, + })?; // Advance summary watermark self.db @@ -105,16 +105,16 @@ impl SummaryWorker { let h_hash = format!("SHA256:{:x}", h_hasher.finalize()); let h_text = format!("Hierarchical Summary (L1): {}", h_text_parts.join(" => ")); - let _ = self.db.insert_session_summary( + let _ = self.db.insert_session_summary(&SessionSummaryWrite { session_id, branch_id, - 1, - h_start, - h_end, - &h_text, - &h_hash, - SUMMARY_PROCESSOR_VERSION, - ); + level: 1, + start_seq: h_start, + end_seq: h_end, + summary_text: &h_text, + source_hash: &h_hash, + processor_version: SUMMARY_PROCESSOR_VERSION, + }); } Ok(Some(summary))