Skip to content

Commit 2879815

Browse files
fix: clippy fixes for arithmetic safety and redundant wrapping
Use saturating_sub, checked_sub_signed, signed_duration_since instead of deprecated Sub ops in session_service. Flatten nested if-let in observation tombstone logic. Remove redundant Ok() wrapping in FTS and semantic search. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent 477e5b5 commit 2879815

4 files changed

Lines changed: 36 additions & 40 deletions

File tree

crates/service/src/observation_service/mod.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,30 +118,30 @@ impl ObservationService {
118118
let infinite_fut = self.store_infinite_memory(&tool_call, None);
119119
let compress_fut = async {
120120
let result = self.compress_and_save(id, &tool_call).await?;
121-
if let Some((ref obs, false)) = result {
122-
if obs.id.0 != id {
123-
let tombstone = Observation::builder(
124-
id.to_owned(),
125-
obs.session_id.clone(),
126-
obs.observation_type,
127-
format!("[merged into {}]", obs.id),
128-
)
129-
.noise_level(opencode_mem_core::NoiseLevel::Negligible)
130-
.noise_reason(format!("Tombstone: merged into {}", obs.id))
131-
.build();
132-
133-
let result = self
134-
.storage
135-
.guarded(|| self.storage.save_observation(&tombstone))
136-
.await;
137-
if let Err(e) = self.with_cb(result) {
138-
tracing::warn!(
139-
tombstone_id = %id,
140-
merged_into = %obs.id,
141-
error = %e,
142-
"Failed to save tombstone observation — stale original may remain visible"
143-
);
144-
}
121+
if let Some((ref obs, false)) = result
122+
&& obs.id.0 != id
123+
{
124+
let tombstone = Observation::builder(
125+
id.to_owned(),
126+
obs.session_id.clone(),
127+
obs.observation_type,
128+
format!("[merged into {}]", obs.id),
129+
)
130+
.noise_level(opencode_mem_core::NoiseLevel::Negligible)
131+
.noise_reason(format!("Tombstone: merged into {}", obs.id))
132+
.build();
133+
134+
let result = self
135+
.storage
136+
.guarded(|| self.storage.save_observation(&tombstone))
137+
.await;
138+
if let Err(e) = self.with_cb(result) {
139+
tracing::warn!(
140+
tombstone_id = %id,
141+
merged_into = %obs.id,
142+
error = %e,
143+
"Failed to save tombstone observation — stale original may remain visible"
144+
);
145145
}
146146
}
147147
Ok::<_, crate::ServiceError>(result)

crates/service/src/session_service.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ const STALE_PLACEHOLDER_MINUTES: i64 = 10;
2121
/// Returns a slice of the most recent observations.
2222
fn truncate_observations_for_summary(observations: &[Observation]) -> &[Observation] {
2323
if observations.len() > MAX_OBSERVATIONS_FOR_SUMMARY {
24-
&observations[observations.len() - MAX_OBSERVATIONS_FOR_SUMMARY..]
24+
let start = observations
25+
.len()
26+
.saturating_sub(MAX_OBSERVATIONS_FOR_SUMMARY);
27+
observations.get(start..).unwrap_or(observations)
2528
} else {
2629
observations
2730
}
@@ -257,12 +260,13 @@ impl SessionService {
257260
.learned
258261
.as_deref()
259262
.is_some_and(|l| l == "processing");
260-
let stale_threshold =
261-
Utc::now() - TimeDelta::minutes(STALE_PLACEHOLDER_MINUTES);
263+
let stale_threshold = Utc::now()
264+
.checked_sub_signed(TimeDelta::minutes(STALE_PLACEHOLDER_MINUTES))
265+
.unwrap_or_else(Utc::now);
262266
if is_processing && existing.created_at < stale_threshold {
263267
tracing::warn!(
264268
session_id = %session.session_id,
265-
age_minutes = (Utc::now() - existing.created_at).num_minutes(),
269+
age_minutes = Utc::now().signed_duration_since(existing.created_at).num_minutes(),
266270
"Deleting stale processing placeholder"
267271
);
268272
let _ = self

crates/storage/src/pg_storage/search/fts.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ pub(crate) async fn search(
2424
.bind(usize_to_i64(limit))
2525
.fetch_all(&storage.pool)
2626
.await?;
27-
Ok(collect_skipping_corrupt(
28-
rows.iter().map(row_to_search_result),
29-
)?)
27+
collect_skipping_corrupt(rows.iter().map(row_to_search_result))
3028
}
3129

3230
pub(crate) async fn search_with_filters(
@@ -92,9 +90,7 @@ pub(crate) async fn search_with_filters(
9290
q = q.bind(&tsquery);
9391
q = q.bind(usize_to_i64(limit));
9492
let rows = q.fetch_all(&storage.pool).await?;
95-
return Ok(collect_skipping_corrupt(
96-
rows.iter().map(row_to_search_result),
97-
)?);
93+
return collect_skipping_corrupt(rows.iter().map(row_to_search_result));
9894
}
9995

10096
let where_clause = if conditions.is_empty() {
@@ -115,7 +111,5 @@ pub(crate) async fn search_with_filters(
115111
}
116112
q = q.bind(usize_to_i64(limit));
117113
let rows = q.fetch_all(&storage.pool).await?;
118-
Ok(collect_skipping_corrupt(
119-
rows.iter().map(row_to_search_result),
120-
)?)
114+
collect_skipping_corrupt(rows.iter().map(row_to_search_result))
121115
}

crates/storage/src/pg_storage/search/semantic.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,5 @@ pub(crate) async fn semantic_search(
2525
.bind(usize_to_i64(limit))
2626
.fetch_all(&storage.pool)
2727
.await?;
28-
Ok(collect_skipping_corrupt(
29-
rows.iter().map(row_to_search_result),
30-
)?)
28+
collect_skipping_corrupt(rows.iter().map(row_to_search_result))
3129
}

0 commit comments

Comments
 (0)