Skip to content

Add memory quality proof loop and ambient ring fullness#35

Merged
TerminallyLazy merged 19 commits into
mainfrom
optimize-for-use
Jul 9, 2026
Merged

Add memory quality proof loop and ambient ring fullness#35
TerminallyLazy merged 19 commits into
mainfrom
optimize-for-use

Conversation

@TerminallyLazy

@TerminallyLazy TerminallyLazy commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • add a strict, portable memory-quality scenario model and evaluator with seven reviewable fixtures
  • run scenarios through real temporary SQLite stores and resilient strict-first recall
  • integrate quality artifacts and exact pass gates into repository certification
  • add recall, trust, and write guidance to generated agent-awareness surfaces
  • render ambient TUI rings as dull-to-light fullness indicators while keeping warning and activity states separate
  • include the approved memory-quality and shared-action design and implementation plans carried by this branch

Proof integrity

  • require a primary observation for every quality category
  • aggregate only applicable observations and apply strict defaults only to observed dimensions
  • reject unknown fields and irrelevant explicit thresholds
  • sanitize parse, validation, storage, recall, report, and command failure messages
  • require every forbidden-recall selector to match seeded memory so suppression cannot pass vacuously
  • retain legacy quality-report deserialization compatibility

Verification

  • cargo fmt --all -- --check
  • git diff --check
  • cargo test --locked --workspace --all-targets (223 tests passed)
  • cargo clippy --locked --workspace --all-targets -- -D warnings
  • seven-scenario quality executable: 7 passed, 0 errors, top-level quality_pass: true
  • sh scripts/certify-tree-ring.sh
  • certification artifact gates for JSON, Markdown, metrics, and summary output

Review

Independent whole-branch review found no Critical or Important issues. Remaining non-blocking risk is direct fault-injection coverage for internal failure branches that already emit fixed sanitized error classes.

Summary by CodeRabbit

  • New Features

    • Added a new memory quality-check flow that evaluates fixture scenarios and produces both JSON and markdown reports.
    • Expanded the certification process to include quality scenario results and surface them in the final summary.
    • Added clearer agent and skill guidance around memory quality gates.
  • Bug Fixes

    • Improved memory recall handling so fallback searches find relevant results more reliably.
    • Updated the TUI to show ring fullness more accurately and reflect it in ambient coloring.
  • Documentation

    • Updated README and integration docs with the new quality report locations and certification outputs.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@TerminallyLazy, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 37 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b32b5f43-ddf6-4d27-81f0-93bab979b09e

📥 Commits

Reviewing files that changed from the base of the PR and between 06f3808 and 10c153f.

📒 Files selected for processing (4)
  • crates/tree-ring-memory-cli/examples/quality_scenarios.rs
  • crates/tree-ring-memory-cli/src/agent_awareness.rs
  • crates/tree-ring-memory-core/src/quality.rs
  • scripts/certify-tree-ring.sh
📝 Walkthrough

Walkthrough

Introduces a quality-scenario evaluation pipeline with fixture-based certification reports, managed memory-quality guidance, filtered FTS recall fallback, and fullness-aware TUI ring brightness.

Changes

Quality proof loop

Layer / File(s) Summary
Quality contracts and evaluator
crates/tree-ring-memory-core/src/quality.rs, crates/tree-ring-memory-core/src/lib.rs, docs/superpowers/specs/*, docs/superpowers/plans/*
Adds validated scenario models, recall/write expectations, thresholded metrics, reports, aggregation, parsing, and public exports.
Fixture runner and reports
crates/tree-ring-memory-cli/examples/quality_scenarios.rs, fixtures/quality/*
Runs fixture scenarios in temporary SQLite stores, evaluates recalls, records sanitized failures, and writes JSON/Markdown artifacts.
Certification output integration
scripts/certify-tree-ring.sh, README.md
Runs quality scenarios during certification, validates quality_pass, and includes quality results in certification outputs.
Quality gate guidance and backfill
crates/tree-ring-memory-cli/src/agent_awareness.rs, skills/tree-ring-memory/SKILL.md, docs/integrations/agent-skill.md
Adds recall, trust, and write gates to guidance and backfills missing managed sections in recognized generated files.

Filtered recall fallback

Layer / File(s) Summary
Filtered FTS fallback
crates/tree-ring-memory-sqlite/src/lib.rs
Adds OR-based FTS fallback after strict recall misses while preserving filters and candidate limits.

TUI ring fullness

Layer / File(s) Summary
Fullness-aware ring rendering
crates/tree-ring-memory-cli/src/tui/model.rs, crates/tree-ring-memory-cli/src/tui/rings.rs
Computes relative ring fullness and applies it to ambient animated ring brightness.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Certification
  participant QualityRunner
  participant SQLiteStore
  participant MemoryRetriever
  participant QualityEvaluator
  Certification->>QualityRunner: Execute fixture pack
  QualityRunner->>SQLiteStore: Seed scenario memories
  QualityRunner->>MemoryRetriever: Recall scenario query
  MemoryRetriever-->>QualityRunner: Return recall candidates
  QualityRunner->>QualityEvaluator: Evaluate scenario
  QualityEvaluator-->>QualityRunner: Produce quality report
  QualityRunner-->>Certification: Write JSON and Markdown artifacts
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the two main themes of the changeset: the memory quality proof loop and ambient ring fullness updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch optimize-for-use

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a deterministic memory quality proof loop for Tree Ring Memory, adding a quality scenario model and evaluator to tree-ring-memory-core, default quality fixtures, and a certification-only runner. It also integrates quality metrics into the certification suite, updates generated agent guidance with explicit quality gates, and adds relative fullness styling to the TUI. The reviewer feedback highlights several valuable improvement opportunities, including ensuring Windows compatibility for skill file recognition, optimizing memory allocations in scenario validation, using idiomatic slice methods, disabling unused ranking explanations in the runner, and making the certification script's JSON parsing more robust.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +225 to +227
fn is_generated_skill_file(content: &str) -> bool {
content.starts_with("---\n") && content.contains(SKILL_FRONT_MATTER_MARKER)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

On Windows systems, files are often checked out with CRLF (\r\n) line endings. Checking content.starts_with("---\n") will fail to recognize these files as generated skill files. It is safer and more portable to support both LF and CRLF line endings.

fn is_generated_skill_file(content: &str) -> bool {
    (content.starts_with("---
") || content.starts_with("---
")) && content.contains(SKILL_FRONT_MATTER_MARKER)
}

Comment on lines +596 to +619
let candidate_index_by_id = scenario
.write_candidates
.iter()
.enumerate()
.map(|(index, candidate)| (candidate.id.as_str(), index))
.collect::<HashMap<_, _>>();
let mut decision_index_by_id = HashMap::new();

for (index, decision) in scenario.expected_write_decisions.iter().enumerate() {
if let Some(previous_index) =
decision_index_by_id.insert(decision.memory_id.as_str(), index)
{
return Err(TreeRingError::Validation(format!(
"quality scenario {} expected_write_decisions[{index}] duplicates memory_id {} from expected_write_decisions[{previous_index}]",
scenario.name, decision.memory_id
)));
}
if !candidate_index_by_id.contains_key(decision.memory_id.as_str()) {
return Err(TreeRingError::Validation(format!(
"quality scenario {} expected_write_decisions[{index}] memory_id {} does not match any write_candidate",
scenario.name, decision.memory_id
)));
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The candidate_index_by_id map is constructed solely to check for the presence of decision.memory_id using contains_key. However, the unique candidate IDs are already collected in the candidate_ids set on lines 586-594. We can reuse candidate_ids directly, which avoids the redundant allocation and construction of candidate_index_by_id entirely.

    let mut decision_index_by_id = HashMap::new();

    for (index, decision) in scenario.expected_write_decisions.iter().enumerate() {
        if let Some(previous_index) =
            decision_index_by_id.insert(decision.memory_id.as_str(), index)
        {
            return Err(TreeRingError::Validation(format!(
                "quality scenario {} expected_write_decisions[{index}] duplicates memory_id {} from expected_write_decisions[{previous_index}]",
                scenario.name, decision.memory_id
            )));
        }
        if !candidate_ids.contains(decision.memory_id.as_str()) {
            return Err(TreeRingError::Validation(format!(
                "quality scenario {} expected_write_decisions[{index}] memory_id {} does not match any write_candidate",
                scenario.name, decision.memory_id
            )));
        }
    }

Comment on lines +769 to +776
if !required_evidence_refs.is_empty()
&& candidate.event_type.starts_with("evaluation_")
&& !required_evidence_refs
.iter()
.any(|required| required == &candidate.source.ref_)
{
return "require_evidence".to_string();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of manually iterating over required_evidence_refs with .iter().any(...), you can use the more idiomatic and concise .contains(...) method on slices.

    if !required_evidence_refs.is_empty()
        && candidate.event_type.starts_with("evaluation_")
        && !required_evidence_refs.contains(&candidate.source.ref_)
    {
        return "require_evidence".to_string();
    }

Comment on lines +198 to +210
let recalls = MemoryRetriever::new(&store)
.recall(
prompt,
None,
None,
None,
None,
None,
false,
false,
RECALL_LIMIT,
true,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The explain_ranking parameter (the last argument to recall) is set to true. However, the returned RecallResult is immediately mapped to QualityRecall which only retains the memory and score fields, discarding the ranking explanation. Setting this to false avoids the unnecessary overhead of calculating and populating the ranking explanation map.

Suggested change
let recalls = MemoryRetriever::new(&store)
.recall(
prompt,
None,
None,
None,
None,
None,
false,
false,
RECALL_LIMIT,
true,
)
let recalls = MemoryRetriever::new(&store)
.recall(
prompt,
None,
None,
None,
None,
None,
false,
false,
RECALL_LIMIT,
false,
)

Comment thread scripts/certify-tree-ring.sh Outdated
Comment on lines +212 to +213
grep -Fx ' "quality_pass": true,' "$QUALITY_OUT/quality-report.json" > /dev/null \
|| fail "memory quality scenarios did not pass"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using grep -Fx with an exact string like ' "quality_pass": true,' is fragile because any change in the struct field order, serialization formatting (e.g., indentation, spacing), or line endings (e.g., CRLF on Windows) will break the certification script. It is much more robust to use grep -F '"quality_pass": true' to check for the presence of the field anywhere in the JSON.

Suggested change
grep -Fx ' "quality_pass": true,' "$QUALITY_OUT/quality-report.json" > /dev/null \
|| fail "memory quality scenarios did not pass"
grep -F '"quality_pass": true' "$QUALITY_OUT/quality-report.json" > /dev/null \
|| fail "memory quality scenarios did not pass"

@TerminallyLazy TerminallyLazy merged commit 012b499 into main Jul 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant