fix: defensive null guards on Memory.sessionIds#684
Conversation
…paths Memory.sessionIds is declared as string[] but JSONL imports + older on-disk records can carry undefined for it. Four read-side callsites accessed memory.sessionIds[0] directly, which would throw when sessionIds is missing. Switched to optional-chaining (memory.sessionIds?.[0] ?? "memory") in: src/index.ts (BM25 rebuild), src/state/memory-utils.ts (memoryToObservation), src/functions/remember.ts (vector add), src/functions/search.ts (rebuild loop). Import side in src/functions/export-import.ts now normalises Memory.sessionIds to [] when it arrives non-array, so downstream readers can rely on the field being present after import.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR adds defensive handling for missing or non-array ChangesSessionIds resilience
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 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 docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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 |
There was a problem hiding this comment.
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 `@src/functions/export-import.ts`:
- Around line 378-381: Remove the explanatory "WHAT" comment block above the
normalization of the sessionIds field (the three-line comment describing that
imported JSONL may carry malformed Memory entries and normalising to an empty
array); delete those lines and, if you feel a comment is still necessary,
replace them with a short WHY note (e.g., "preserve compatibility with
older/hand-edited exports") but do not restate what the code does—locate the
code that normalises the sessionIds field and remove the comment there.
🪄 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: a6500ca8-2d88-4d36-905f-b752b5ad2f9d
📒 Files selected for processing (5)
src/functions/export-import.tssrc/functions/remember.tssrc/functions/search.tssrc/index.tssrc/state/memory-utils.ts
Bug-fix-triage pass: five callsites assumed
Memory.sessionIdsis alwaysstring[], which the type says — but JSONL imports + older on-disk records can deliverundefined. Touchingmemory.sessionIds[0]would then throwTypeError: Cannot read properties of undefined.Read-side (now
memory.sessionIds?.[0] ?? "memory"):src/index.ts:485— BM25 rebuild loopsrc/state/memory-utils.ts:14—memoryToObservationhelpersrc/functions/remember.ts:145—vectorIndexAddGuardedcallsrc/functions/search.ts:264— rebuild loopImport side (
src/functions/export-import.ts): normalise to[]before persisting, so downstream code never has to defend against the missing-field shape.Full suite locally: 1227 pass, 1 pre-existing integration-test failure (needs running server, unrelated).
Summary by CodeRabbit