fix: guard against null sessionIds on Memory objects#644
Conversation
|
@washi4 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)
📝 WalkthroughWalkthroughNormalize incoming memory.sessionIds to an array during import and read sessionId defensively across utilities, remember, and search code paths, defaulting to "memory" when none exists. ChangesSessionIds Field Robustness
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 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-379: Remove the WHAT-style inline comment above the sessionIds
normalization; instead either delete the comment entirely or replace it with a
brief WHY-focused note (e.g., "Ensure downstream code can safely iterate
sessionIds from older exports") near the sessionIds normalization logic in
export-import.ts so the code relies on clear naming (sessionIds,
normalizeSessionIds or the surrounding block) rather than explaining what the
code is doing.
🪄 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: 25b4c11e-fbc7-4c76-9448-75431fcecd13
📒 Files selected for processing (4)
src/functions/export-import.tssrc/functions/remember.tssrc/functions/search.tssrc/state/memory-utils.ts
Memory.sessionIds can be null/undefined when loaded from KV store (via import, migration, or corrupted data), causing runtime crashes on `memory.sessionIds[0]` access. Changes: - src/state/memory-utils.ts: guard in memoryToObservation() - src/functions/search.ts: guard in rebuildIndex() - src/functions/remember.ts: guard in vectorIndexAddGuarded call - src/functions/export-import.ts: normalize sessionIds during import Signed-off-by: washi4 <wayne.shi1@ingka.ikea.com>
3b15154 to
e5eedc6
Compare
Problem
memory.sessionIds[0]crashes at runtime whensessionIdsisnullorundefined. This happens when Memory objects are loaded from KV store via import, migration, or corrupted data — the TypeScript type declaressessionIds: string[]but runtime doesn't enforce this.Error:
Root Cause
mem::importwrites memory objects directly to KV without normalizing thesessionIdsfield. External data or older export formats may havesessionIds: nullinstead ofsessionIds: [].Fix
Two-pronged approach:
(memory.sessionIds ?? [])[0] ?? "memory"patternsessionIdsduring import to prevent null from persisting in the KV storeChanged Files
src/state/memory-utils.tsmemoryToObservation()src/functions/search.tsrebuildIndex()src/functions/remember.tsvectorIndexAddGuardedcallsrc/functions/export-import.tssessionIdsduring importTesting
npm run build)Summary by CodeRabbit