fix(smart-search): findObservation returns empty for bare expand obsIds#840
fix(smart-search): findObservation returns empty for bare expand obsIds#840MarvinFS wants to merge 1 commit into
Conversation
findObservation's batched session scan selected hits with `.find((r) => r !== null)`, but `StateKV.get` returns the raw `state::get` value, which is `undefined` for a missing key (not null); the `.catch(() => null)` only normalizes rejections. Most sessions miss a given obsId (and some session records are partial without an `id`), so each scan batch contains `undefined` before the real hit -- `.find` returns the first `undefined` and `if (found)` discards it as falsy, so the observation is never returned. Bare `memory_smart_search` expandIds therefore returned empty while the hint path and hybrid-search enrich (both truthy `if (obs)`) worked. - Use `.find((r) => r != null)` so undefined misses are skipped. - Resolve saved memories from KV.memories before the scan, since mem::remember stores them outside KV.observations(*); preserve agentId/imageRef/imageData in memoryToObservation so agent-scope filtering stays correct, and route the legacy BM25 backfill through memoryToObservation too. - Add a regression test whose KV mock returns undefined on miss (mocks that coalesce to null hide the bug) with a partial session ordered before the real one in the same scan batch. Signed-off-by: MarvinFS <7998636+MarvinFS@users.noreply.github.com>
|
@MarvinFS is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR enhances observation resolution to support saved memories by enriching the memory-to-observation mapping helper with optional fields, updating smart-search to check saved memories first before falling back to KV scans, centralizing BM25 backfill to use the shared mapping logic, and adding regression tests for the undefined-on-miss failure mode. ChangesSaved Memories Observation Resolution
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Problem
memory_smart_searchwithexpandIdsreturns an emptyresultsarray for abare obsId, even when the observation exists and a session-hinted lookup
resolves it.
Root cause
findObservationscans sessions in batches and selects the hit with.find((r) => r !== null). ButStateKV.getreturns the rawstate::getvalue, which is
undefinedfor a missing key (notnull); the surrounding.catch(() => null)only normalizes rejections. Most sessions don't hold agiven obsId (and some session records are partial, without an
id), so eachbatch contains
undefinedbefore the real observation. Sinceundefined !== nullistrue,.findreturns the firstundefined, andif (found)discards it as falsy — so the real observation later in the batchis never returned. The hint path and the hybrid-search enrich path are
unaffected because they use a truthy
if (obs)check.Separately,
findObservationonly consultsKV.observations(sessionId)andnever
KV.memories, so observations saved viamem::remember(stored inKV.memoriesunder a synthetic session) cannot be resolved by a bare obsId.Fix
.find((r) => r != null)soundefinedmisses are skipped.KV.memories(viamemoryToObservation) beforethe session scan. Preserve
agentId/imageRef/imageDatainmemoryToObservationso agent-scope filtering stays correct, and route theexisting BM25 backfill through
memoryToObservationfor consistency.undefinedon a miss (mocks thatcoalesce misses to
nullmask the bug), with a partial session orderedbefore the real one in the same scan batch.
Complements #837, which forwards
expandIdsfrom the MCP proxy to the daemon.Summary by CodeRabbit
Bug Fixes
Improvements