Skip to content

Commit 653d99b

Browse files
committed
v0.6.0 - hardening: restore daemon rustfmt
Apply rustfmt to daemon admin, compaction, and embedding code that drifted during earlier v0.6.0 work. Validation: rtk cargo fmt --manifest-path daemon-rs/Cargo.toml -- --check; rtk cargo check --manifest-path daemon-rs/Cargo.toml --tests.
1 parent a2b5913 commit 653d99b

3 files changed

Lines changed: 30 additions & 24 deletions

File tree

daemon-rs/src/admin.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,26 +267,39 @@ mod tests {
267267
// Older memory predating the session — must not be touched.
268268
seed_memory(&conn, "claude", "old", "2026-04-23T23:59:00Z", "active");
269269
// Another agent's memory in the same time window — must not be touched.
270-
seed_memory(&conn, "codex", "other-agent", "2026-04-24T00:05:00Z", "active");
270+
seed_memory(
271+
&conn,
272+
"codex",
273+
"other-agent",
274+
"2026-04-24T00:05:00Z",
275+
"active",
276+
);
271277
// In-session memories + one already-rolled-back row to confirm we only
272278
// touch active rows.
273279
seed_memory(&conn, "claude", "m1", "2026-04-24T00:05:00Z", "active");
274280
seed_memory(&conn, "claude", "m2", "2026-04-24T00:10:00Z", "active");
275-
seed_memory(&conn, "claude", "pre-rolled", "2026-04-24T00:07:00Z", ROLLED_BACK_STATUS);
281+
seed_memory(
282+
&conn,
283+
"claude",
284+
"pre-rolled",
285+
"2026-04-24T00:07:00Z",
286+
ROLLED_BACK_STATUS,
287+
);
276288
seed_decision(&conn, "claude", "d1", "2026-04-24T00:06:00Z");
277289

278290
let stats = rollback_session_by_id(&conn, "sess-1", true).unwrap();
279-
assert_eq!(stats.memories_affected, 2, "only the 2 active in-session memories");
291+
assert_eq!(
292+
stats.memories_affected, 2,
293+
"only the 2 active in-session memories"
294+
);
280295
assert_eq!(stats.decisions_affected, 1);
281296
assert!(stats.applied);
282297

283298
// Pre-existing rows preserved
284299
let old_status: String = conn
285-
.query_row(
286-
"SELECT status FROM memories WHERE text = 'old'",
287-
[],
288-
|r| r.get(0),
289-
)
300+
.query_row("SELECT status FROM memories WHERE text = 'old'", [], |r| {
301+
r.get(0)
302+
})
290303
.unwrap();
291304
assert_eq!(old_status, "active");
292305
let other_status: String = conn

daemon-rs/src/compaction.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,7 @@ fn run_compaction_with_options(conn: &Connection, allow_vacuum: bool) -> Compact
404404
+ result.stale_embeddings_pruned
405405
+ result.co_occurrence_pruned
406406
+ result.legacy_embeddings_migrated;
407-
if allow_vacuum
408-
&& (freelist_pages > VACUUM_FREELIST_THRESHOLD_PAGES || result.fts_optimized)
409-
{
407+
if allow_vacuum && (freelist_pages > VACUUM_FREELIST_THRESHOLD_PAGES || result.fts_optimized) {
410408
let _ = conn.execute_batch("VACUUM;");
411409
}
412410

@@ -556,9 +554,7 @@ fn migrate_legacy_blob_column_to_pq8(
556554
let mut stmt = match conn.prepare(&select_sql) {
557555
Ok(stmt) => stmt,
558556
Err(err) => {
559-
eprintln!(
560-
"[compaction] PQ8 migration prepare failed for {table}.{column}: {err}"
561-
);
557+
eprintln!("[compaction] PQ8 migration prepare failed for {table}.{column}: {err}");
562558
return 0;
563559
}
564560
};
@@ -1804,10 +1800,7 @@ mod tests {
18041800
.collect();
18051801
assert_eq!(rows.len(), 2);
18061802
for (label, blob) in &rows {
1807-
assert!(
1808-
blob.len() >= 2,
1809-
"{label} centroid too short to carry magic"
1810-
);
1803+
assert!(blob.len() >= 2, "{label} centroid too short to carry magic");
18111804
assert_eq!(
18121805
blob[0],
18131806
crate::embeddings::PQ8_MAGIC_BYTE,
@@ -1923,8 +1916,7 @@ mod tests {
19231916
// Recall fidelity: re-reading via blob_to_vector should match the
19241917
// original within the per-vector quantization scale.
19251918
let recovered = crate::embeddings::blob_to_vector(&new_blob);
1926-
let scale =
1927-
f32::from_le_bytes([new_blob[2], new_blob[3], new_blob[4], new_blob[5]]);
1919+
let scale = f32::from_le_bytes([new_blob[2], new_blob[3], new_blob[4], new_blob[5]]);
19281920
let max_err = legacy_vec
19291921
.iter()
19301922
.zip(recovered.iter())

daemon-rs/src/embeddings.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -674,9 +674,7 @@ pub fn vector_to_pq8_blob(vec: &[f32]) -> Vec<u8> {
674674

675675
/// True iff the blob is a PQ8-encoded vector (magic + version match).
676676
pub fn is_pq8_blob(blob: &[u8]) -> bool {
677-
blob.len() >= PQ8_HEADER_BYTES
678-
&& blob[0] == PQ8_MAGIC_BYTE
679-
&& blob[1] == PQ8_FORMAT_VERSION
677+
blob.len() >= PQ8_HEADER_BYTES && blob[0] == PQ8_MAGIC_BYTE && blob[1] == PQ8_FORMAT_VERSION
680678
}
681679

682680
/// Decode a PQ8 blob back to Vec<f32>. Returns None if the blob is not a
@@ -1193,6 +1191,9 @@ mod tests {
11931191
);
11941192
// Top-3 may permute slightly; require at least 2/3 overlap.
11951193
let overlap = raw_top.iter().filter(|i| q_top.contains(i)).count();
1196-
assert!(overlap >= 2, "top-3 overlap < 2: raw={raw_top:?}, q={q_top:?}");
1194+
assert!(
1195+
overlap >= 2,
1196+
"top-3 overlap < 2: raw={raw_top:?}, q={q_top:?}"
1197+
);
11971198
}
11981199
}

0 commit comments

Comments
 (0)