Repository navigation
feat(#351): orphan detection — find disconnected memories - #389
Merged
Merged
Conversation
Detect memories that have no graph edges (incoming or outgoing), have never been recalled, are not pinned, and fall below an importance threshold. Such memories dilute recall quality and are prime candidates for cleanup via the dream cycle (#353). Core (uteke-core): - New orphans.rs module: - OrphanMemory struct with orphan_score (0.0..=1.0) - compute_orphan_score(): (1-edge_density)*0.4 + (1-access_freq)*0.3 + (1-importance)*0.3 - Store::find_orphans(): single SQL pass via LEFT JOIN on memory_edges twice — no O(n^2) scan - Uteke::find_orphans() with namespace scoping - DEFAULT_ORPHAN_THRESHOLD = 0.3 - Leverages #350 backlinks: any referenced memory is automatically excluded CLI (uteke-cli): - New 'uteke orphans [--threshold 0.3] [--limit 50]' command Tests (+7 new): - orphan_score: disconnected/low vs connected/high - find_orphans: returns isolated low-importance, excludes connected - respects threshold (low vs high) - excludes pinned and accessed memories - namespace-scoped detection - limit cap Closes #351
🔍 Cora AI Code Review❌ Blocked — critical issues found. 🔴 Error (1)
Review powered by cora-cli · BYOK · MIT |
CodeCora #389: the previous loop broke out as soon as orphans.len() >= limit, but the subsequent sort_by(orphan_score desc) could reorder the truncated subset — a higher-score orphan that appeared later in the SQL result set would be dropped. Fix: collect all candidates first, compute orphan_score, sort, THEN truncate to limit. Orphan result sets are typically small (each match has zero edges + zero accesses), so the full fetch is cheap.
CodeCora #389 found two issues in compute_orphan_score: 1. access_count.max(1) made access_count=0 and access_count=1 produce the same log10(1)/3 = 0.0 score. Never-accessed memories were treated identically to accessed-once. Fix: use log10(n+1) so access_count=1 produces a non-zero normalized frequency. 2. importance was cast to f32 and used as (1-importance)*0.3 without clamping. Out-of-range values (>1.0 or <0.0) would skew the score or produce negative results. Fix: clamp to [0, 1]. Added 2 regression tests: never-accessed vs once-accessed, and importance bounds clamping.
CodeCora #389 round 2: find_orphans SQL didn't filter m.deprecated = 0, so superseded memories could appear as orphan candidates even though they were intentionally retired. Fix: add 'AND m.deprecated = 0' to the WHERE clause. Also: fix clippy manual_range_contains warning in test assertion.
lib.rs: added orphans module alongside salience_recency and timeline. cli.rs: added Orphans command alongside Timeline. commands/mod.rs: added orphans dispatch alongside timeline. CHANGELOG: added #351 orphan detection section.
| ns: Option<&str>, | ||
| threshold: Option<f64>, | ||
| limit: usize, | ||
| ) -> Result<(), String> { |
ajianaz
added a commit
that referenced
this pull request
Aug 13, 2026
* feat(#351): orphan detection — find disconnected memories Detect memories that have no graph edges (incoming or outgoing), have never been recalled, are not pinned, and fall below an importance threshold. Such memories dilute recall quality and are prime candidates for cleanup via the dream cycle (#353). Core (uteke-core): - New orphans.rs module: - OrphanMemory struct with orphan_score (0.0..=1.0) - compute_orphan_score(): (1-edge_density)*0.4 + (1-access_freq)*0.3 + (1-importance)*0.3 - Store::find_orphans(): single SQL pass via LEFT JOIN on memory_edges twice — no O(n^2) scan - Uteke::find_orphans() with namespace scoping - DEFAULT_ORPHAN_THRESHOLD = 0.3 - Leverages #350 backlinks: any referenced memory is automatically excluded CLI (uteke-cli): - New 'uteke orphans [--threshold 0.3] [--limit 50]' command Tests (+7 new): - orphan_score: disconnected/low vs connected/high - find_orphans: returns isolated low-importance, excludes connected - respects threshold (low vs high) - excludes pinned and accessed memories - namespace-scoped detection - limit cap Closes #351 * fix(#351): fetch all orphan candidates before sort + truncate CodeCora #389: the previous loop broke out as soon as orphans.len() >= limit, but the subsequent sort_by(orphan_score desc) could reorder the truncated subset — a higher-score orphan that appeared later in the SQL result set would be dropped. Fix: collect all candidates first, compute orphan_score, sort, THEN truncate to limit. Orphan result sets are typically small (each match has zero edges + zero accesses), so the full fetch is cheap. * fix(#351): differentiate access_count=0 vs 1 + clamp importance CodeCora #389 found two issues in compute_orphan_score: 1. access_count.max(1) made access_count=0 and access_count=1 produce the same log10(1)/3 = 0.0 score. Never-accessed memories were treated identically to accessed-once. Fix: use log10(n+1) so access_count=1 produces a non-zero normalized frequency. 2. importance was cast to f32 and used as (1-importance)*0.3 without clamping. Out-of-range values (>1.0 or <0.0) would skew the score or produce negative results. Fix: clamp to [0, 1]. Added 2 regression tests: never-accessed vs once-accessed, and importance bounds clamping. * fix(#351): exclude deprecated memories + clippy manual_range_contains CodeCora #389 round 2: find_orphans SQL didn't filter m.deprecated = 0, so superseded memories could appear as orphan candidates even though they were intentionally retired. Fix: add 'AND m.deprecated = 0' to the WHERE clause. Also: fix clippy manual_range_contains warning in test assertion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #351. See CHANGELOG entry for full details. All tests pass, clippy + fmt clean.