Skip to content

fix(recall): page a ranked section past hits its exclusions drop - #212

Merged
M3gA-Mind merged 1 commit into
tinyhumansai:mainfrom
CodeGhost21:fix/recall-fetch-pages-past-exclusions
Oct 7, 2026
Merged

M3gA-Mind merged 1 commit into
tinyhumansai:mainfrom
CodeGhost21:fix/recall-fetch-pages-past-exclusions

Conversation

@CodeGhost21

@CodeGhost21 CodeGhost21 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #206, which merged one commit early: GitHub never synced its last push to the PR, so this fix was reviewed on #206 but not merged. A ranked (fetch) section now pages past hits its exclusions drop, as latest already does since #206.

Related issue

Part of tinyhumansai/openhuman#7023 / tinyhumansai/openhuman#6718. Addresses the CodeRabbit finding on #206 ("Apply exclusions before limiting fetched hits").

The bug

fetch asked for one ranked page of wanted hits and let settle drop the excluded ones afterwards: the prompt's thread window, and ids already shown. If that page was mostly in-window turns, the section came back short or empty even when eligible hits sat on the next page.

The fix

  • fetch applies the request's exclusions page by page.
  • It follows next_cursor only when a page lost hits to them and fewer than limit remain. It is capped at FETCH_MAX_PAGES = 5.
  • The common case is still one request, which matters on a hosted engine, where each page is a round trip.
  • Built on Keep the recall future Send: the keep predicate must be Sync #211's &(dyn Fn(&Hit) -> bool + Sync) predicate, so the recall future stays Send; a_recall_future_can_cross_threads still passes.

API or behavior changes

None to the public API. Behaviour: a ranked section can now return eligible hits from later pages instead of fewer or none.

Validation

  • cargo fmt --all -- --check: pass
  • cargo clippy --all-targets --all-features -- -D warnings: pass
  • cargo build --all-targets --all-features: covered by clippy and test
  • cargo test --all-features: pass (1132 passed, 0 failed)

Tests

recall::tests::a_ranked_section_reads_past_a_page_the_thread_window_empties: the in-window turns outrank the eligible ones, so the first three pages are all in-window; the section must still find turn 0 or 1. Revert-checked: fails without the page-by-page filter, passes with it.

Documentation

Not needed: internal recall behaviour; the doc comments on fetch and FETCH_MAX_PAGES explain it.

Checklist

  • The change is focused on one logical change
  • No new #[allow(...)], #[ignore], or relaxed lints
  • No secrets, tokens, or .env contents in the diff or the description

Summary by CodeRabbit

  • Bug Fixes
    • Ranked recall now continues through additional pages when excluded results leave fewer matches than requested, helping return available results instead of an empty result set.

Per review: a fetch section took one ranked page of `wanted` hits and let
settle drop the excluded ones (the prompt's thread window, shown ids), so a
page made of in-window turns left the section empty even when eligible hits
sat on the next page. Exclusions now apply page by page, and only when a
page lost hits to them and too few remain is the next page read (cap 5), so
the common case is still one request. Revert-checked test.
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9ed33959-2e9b-49bd-8d01-a3cfaa242c13
📥 Commits

Reviewing files that changed from the base of the PR and between 581a2bc and aa3e058.

📒 Files selected for processing (2)
  • crates/tinymemory-tools/src/recall/gather.rs
  • crates/tinymemory-tools/src/recall/mod_tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Ranked recall can fetch up to five pages when exclusions leave fewer hits than requested. It requests beliefs on the first page only. A regression test covers recall returning an eligible turn after earlier results are excluded.

Changes

Ranked Recall

Layer / File(s) Summary
Filtered ranked fetch
crates/tinymemory-tools/src/recall/gather.rs, crates/tinymemory-tools/src/recall/mod_tests.rs
Ranked fetch filters hits and continues to another page when exclusions leave fewer hits than requested and a cursor is available. Fetching stops after five pages at most. Beliefs are requested and retained from the first page. A regression test verifies that recall returns an eligible turn after higher-ranked turns are excluded.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Suggested reviewers: senamakel

Merge Risk: ⚪ Minimal · up to aa3e0

Ranked recall can continue past excluded hits, and no actionable merge-blocking risk remains after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to aa3e0

Pagination preserves the existing access scope and exclusions and stops after at most five pages. No access-control regression was identified. Additional reads increase load, and consistency during concurrent updates is not guaranteed.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The expanded exposure is additional eligible memory and read work within the existing section filter, not a new namespace authority. Cortex can perform multiple backend reads per page across admitted scopes; its per-pack event and token ceilings complement, but do not replace, the new per-section page ceiling.

Trust Boundaries and Controls

  • observed — The public memory-fetch route confines caller-supplied reach through the host-owned ToolScope before engine dispatch. Holistic recall supplies section filters to gathering, and pagination preserves those filters. Cortex uses granular scope reads and reapplies the full metadata filter to decoded events.

Resilience and Maintainability Implications

  • inferred — A later-page error discards that section's accumulated results and is reported as a skipped section; other sections can still form the pack. Dropping the recall future does not publish its local partial pack or leave a consumer-owned persistent transition to recover. Backend cancellation behavior is not established by these source paths.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: paging ranked recall sections when exclusions remove hits.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files.
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.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the ranked page,
And hops ahead when hits fall short.
Five pages mark the bounds it keeps,
First-page beliefs ride in its pouch,
Then turn zero greets the waiting hare.

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

@M3gA-Mind
M3gA-Mind merged commit a40f1ec into tinyhumansai:main Oct 7, 2026
18 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.

2 participants