MCPcopy Create free account
hub / github.com/AI45Lab/Code / replace_records

Method replace_records

core/src/run.rs:235–260  ·  view source on GitHub ↗
(&self, records: Vec<RunRecord>)

Source from the content-addressed store, hash-verified

233 }
234
235 pub async fn replace_records(&self, records: Vec<RunRecord>) {
236 // Preserve creation-order in the FIFO eviction queue so a
237 // restored session honours its `max_runs` cap consistently
238 // with newly-created runs.
239 let mut sorted = records;
240 sorted.sort_by_key(|r| r.snapshot.created_at_ms);
241 let mut run_map = HashMap::new();
242 let mut event_map = HashMap::new();
243 let mut order = VecDeque::with_capacity(sorted.len());
244 for record in sorted {
245 let id = record.snapshot.id.clone();
246 // Trust the persisted `event_count` — it is the CUMULATIVE total
247 // ever recorded and is deliberately not decremented when the
248 // per-run event buffer is FIFO-trimmed by `max_events_per_run`.
249 // Overwriting it with `record.events.len()` here would corrupt
250 // the cumulative count for any restored run whose buffer was
251 // trimmed (restoring a 100-event run with a 50-cap buffer as
252 // event_count=50).
253 event_map.insert(id.clone(), record.events);
254 run_map.insert(id.clone(), record.snapshot);
255 order.push_back(id);
256 }
257 *self.runs.write().await = run_map;
258 *self.events.write().await = event_map;
259 *self.insertion_order.write().await = order;
260 }
261}
262
263#[cfg(test)]

Calls 4

writeMethod · 0.80
lenMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected