Skip to content

Fix smart-search durable expansion and project scoping#1091

Open
ErikBPF wants to merge 1 commit into
rohitg00:mainfrom
ErikBPF:fix/1078-smart-search-durable-scope
Open

Fix smart-search durable expansion and project scoping#1091
ErikBPF wants to merge 1 commit into
rohitg00:mainfrom
ErikBPF:fix/1078-smart-search-durable-scope

Conversation

@ErikBPF

@ErikBPF ErikBPF commented Jul 20, 2026

Copy link
Copy Markdown

Fix smart-search durable expansion and project scoping

Summary

  • expand durable mem_* records through smart-search.expandIds
  • preserve durable-memory agent identity during expansion
  • enforce project on compact and expanded results
  • over-fetch before project/agent filtering to avoid underfilled pages
  • resolve durable records before scanning session observations

Why

Smart search can return compact durable-memory hits, but expansion only scans
session observations. Its project argument is also forwarded to lesson recall
without consistently scoping hybrid or expanded results.

This makes compact-to-expanded recall work for durable memories while keeping
project and agent isolation fail-closed.

Fixes #1080.

Validation

  • npx vitest run test/smart-search.test.ts: 17 passed
  • npm run build: passed
  • npm run skills:check: 15 skills passed
  • npm test under Node 20: 1,419 passed
  • npm test under Node 22: 1,419 passed
  • npm run test:integration: 17 passed
  • git diff --check main...HEAD: passed

Review notes

  • one signed-off commit
  • no generated build artifacts committed
  • no changelog changes

Summary by CodeRabbit

  • New Features

    • Added project-based filtering to smart search results and expanded memories.
    • Durable memory searches now preserve full narrative content when expanded.
    • Expanded results respect agent ownership filtering.
  • Bug Fixes

    • Improved search accuracy by excluding observations and memories from unrelated projects.
    • Ensured project filtering works consistently across standard, hybrid, compact, and expanded searches.

Signed-off-by: Erik Bogado <erikbogado@gmail.com>
@vercel

vercel Bot commented Jul 20, 2026

Copy link
Copy Markdown

@ErikBPF is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

mem::smart-search now expands durable memories through KV.memories, preserves their agentId, and applies normalized project filtering to expanded and hybrid-search results. Tests cover durable content, project scoping, agent scoping, and compact results.

Changes

Smart-search project scoping

Layer / File(s) Summary
Durable memory resolution
src/functions/smart-search.ts, src/state/memory-utils.ts
Durable memory IDs are loaded and converted into observations, preserving full content and agentId.
Project filtering across search paths
src/functions/smart-search.ts
Expanded and hybrid results are filtered by project, then agent scope and result limits are applied with project-aware over-fetching.
Smart-search behavior coverage
test/smart-search.test.ts
Tests cover durable expansion content, project filtering, agent scoping, and compact-mode project filtering.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant SmartSearch
  participant KVmemories
  Client->>SmartSearch: request expandIds
  SmartSearch->>KVmemories: load durable Memory
  KVmemories-->>SmartSearch: return Memory
  SmartSearch->>SmartSearch: convert with memoryToObservation
  SmartSearch-->>Client: filtered expanded observation
Loading

Possibly related issues

Possibly related PRs

Suggested reviewers: rohitg00

🚥 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 summarizes the main change: durable smart-search expansion and project scoping.
Linked Issues check ✅ Passed The changes address #1080 by expanding durable memories, preserving agent scope, enforcing project scope, and over-fetching to keep pages filled.
Out of Scope Changes check ✅ Passed The added test coverage and memory conversion tweak are directly related to the durable expansion and scoping objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/smart-search.test.ts`:
- Around line 166-168: Remove the duplicate results property from the type
assertion in test/smart-search.test.ts at lines 166-168, and remove the
duplicated type-assertion lines at lines 197 and 226. Leave one valid
declaration/assertion at each site so the test file compiles.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 647ceae8-2529-40e8-9236-0b433b90a10f

📥 Commits

Reviewing files that changed from the base of the PR and between a8e7d19 and ac9e922.

📒 Files selected for processing (3)
  • src/functions/smart-search.ts
  • src/state/memory-utils.ts
  • test/smart-search.test.ts

Comment thread test/smart-search.test.ts
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.

Smart search cannot expand or consistently scope durable memories

1 participant