fix(ffi): graph cache also keys on total synapse weight (flaky cache test)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Opus 5.5 committed 2026-10-26 16:34:25 +01:00
1 parent ada391a88e
commit 5e5e1ba925
1 file changed
+14 -3
+14 -3
View File
@@ -19,6 +19,9 @@ pub struct CacheKey {
seq: i64,
synapses: i64,
synapse_last: i64,
/// Total weight (micro-units): a visit can strengthen an existing synapse within the same
/// millisecond as its last firing, which leaves count and `last_fired` unchanged.
synapse_weight: i64,
/// Synapse weights decay with time: rebuild at least hourly.
hour: i64,
}
@@ -47,15 +50,23 @@ impl SynapseGraph {
}
fn cache_key(g: &Graph) -> Result<CacheKey> {
let (synapses, synapse_last) = g.conn().query_row(
"SELECT count(*), coalesce(max(last_fired), 0) FROM synapses",
let (synapses, synapse_last, synapse_weight) = g.conn().query_row(
"SELECT count(*), coalesce(max(last_fired), 0),
coalesce(CAST(sum(weight) * 1000000 AS INTEGER), 0) FROM synapses",
[],
|r| Ok((r.get::<_, i64>(0)?, r.get::<_, i64>(1)?)),
|r| {
Ok((
r.get::<_, i64>(0)?,
r.get::<_, i64>(1)?,
r.get::<_, i64>(2)?,
))
},
)?;
Ok(CacheKey {
seq: g.last_seq()?,
synapses,
synapse_last,
synapse_weight,
hour: g.now_ms() / 3_600_000,
})
}