Skip to content

fix(memories): get memory tool, mem0 integration update#4415

Merged
icecrasher321 merged 6 commits intostagingfrom
fix/memories
May 3, 2026
Merged

fix(memories): get memory tool, mem0 integration update#4415
icecrasher321 merged 6 commits intostagingfrom
fix/memories

Conversation

@icecrasher321
Copy link
Copy Markdown
Collaborator

Summary

  • Memory block -- did fuzzy match on conversation id instead of directly getting it. Causing some edge case bugs.
  • Mem0 -- endpoints are out of date

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 3, 2026 1:40am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 3, 2026

PR Summary

Medium Risk
Updates both internal memory endpoints and the Mem0 integration request/response shapes; mistakes could cause missing memories or broken third-party calls. Changes are localized but touch user-facing retrieval and external API behavior.

Overview
Fixes internal memory lookups/deletes to exclude soft-deleted rows by adding isNull(memory.deletedAt) filters in /api/memory/[id] and /api/memory delete-by-query.

Updates the Mem0 integration to current v3 endpoints and payloads, adds shared validation via parseMem0Messages, introduces page support for get/list, and adjusts tool/block outputs to match new response envelopes (including queued add-memory fields and paginated get metadata). Adds/updates focused Vitest coverage for Mem0 tools/block and for memory_get using exact /api/memory/:id paths; trims a flaky Sharp test by removing the small-image case.

Reviewed by Cursor Bugbot for commit 21ef4ae. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 3, 2026

Greptile Summary

This PR fixes two bugs: the memory get tool now performs an exact path-based lookup (/api/memory/{id}) instead of a fuzzy query-parameter search, and the Mem0 integration updates all three tools (add, get, search) from deprecated v1/v2 endpoints to v3 equivalents with matching request/response shapes.

  • P1DELETE and PUT handlers in route.ts do not include isNull(memory.deletedAt) in their WHERE clauses, so soft-deleted records that are invisible to GET can still be mutated or hard-deleted, breaking soft-delete semantics.
  • P1transformResponse in memory/get.ts calls response.json() without checking response.ok, silently converting any HTTP error (including 404) into { success: true, memories: [] } and hiding real failures from callers.

Confidence Score: 3/5

Not safe to merge as-is — two P1 bugs exist: soft-delete inconsistency in route.ts and silent HTTP error masking in the memory get tool.

Two P1 findings cap the score at 4; the soft-delete inconsistency affects correctness of write operations on the same route that was just fixed for reads, pulling the score below the ceiling to 3.

apps/sim/app/api/memory/[id]/route.ts (DELETE and PUT soft-delete filters), apps/sim/tools/memory/get.ts (HTTP error handling in transformResponse)

Important Files Changed

Filename Overview
apps/sim/app/api/memory/[id]/route.ts Adds isNull(memory.deletedAt) to GET to fix soft-delete visibility, but DELETE and PUT existence checks still omit this filter, creating inconsistent behavior for soft-deleted records.
apps/sim/tools/memory/get.ts Correctly switches from fuzzy query-based lookup to exact path-based lookup via encodeURIComponent; transformResponse silently converts API HTTP errors into empty success results.
apps/sim/tools/mem0/add_memories.ts Updates to v3 add endpoint; refactors message parsing and response handling to match new queued-processing API shape; includes trimming userId.
apps/sim/tools/mem0/get_memories.ts Upgrades to v3 list endpoint with proper filter structure; adds URL encoding for memoryId; pagination hardcoded to page 1 with no way to retrieve subsequent pages.
apps/sim/tools/mem0/search_memories.ts Updates to v3 search endpoint; replaces ad-hoc response mapping with type-safe helpers; correctly wraps results from the new envelope format.
apps/sim/blocks/blocks/mem0.ts Adds parseMem0Messages helper with strict role validation; removes deprecated default userId value; moves date range fields to advanced mode; simplifies params/switch logic.
apps/sim/tools/mem0/types.ts Adds typed param and response interfaces for all three operations; updates ADD_MEMORY_OUTPUT_PROPERTIES to reflect new async/queued response shape.

Comments Outside Diff (2)

  1. apps/sim/app/api/memory/[id]/route.ts, line 131-135 (link)

    P1 Soft-deleted records not filtered in DELETE and PUT handlers

    The GET handler now correctly excludes soft-deleted rows via isNull(memory.deletedAt), but the existence checks in the DELETE (line 131–135) and PUT (line 183–191) handlers still query without that filter. A soft-deleted memory will be invisible to GET (returning 404) yet still matched by DELETE and PUT — breaking the invariant that deletedAt != null means "does not exist". The PUT handler will update and return a soft-deleted record; the DELETE handler will hard-delete it, bypassing soft-delete semantics entirely. Both handlers should add isNull(memory.deletedAt) to their existence-check (and update/delete) WHERE clauses.

  2. apps/sim/tools/memory/get.ts, line 49-61 (link)

    P1 HTTP error responses silently become empty success results

    When the API returns a 404 (memory not found), the response body is { success: false, error: { message: 'Memory not found' } }, so result.data is undefined. The !memory branch then returns { success: true, output: { memories: [], message: 'No memories found' } }, hiding the fact that the request actually errored. Callers have no way to distinguish "memory doesn't exist" from "API returned an error". Checking response.ok first makes the failure explicit.

Reviews (1): Last reviewed commit: "fix(memories): get memory tool, mem0 int..." | Re-trigger Greptile

Comment thread apps/sim/tools/mem0/get_memories.ts
Comment thread apps/sim/app/api/memory/[id]/route.ts
Comment thread apps/sim/blocks/blocks/mem0.ts Outdated
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

Comment thread apps/sim/blocks/blocks/mem0.ts
Comment thread apps/sim/tools/mem0/search_memories.ts Outdated
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 21ef4ae. Configure here.

@icecrasher321 icecrasher321 merged commit 7921449 into staging May 3, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/memories branch May 3, 2026 03:04
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.

1 participant