Skip to content

fix(memory): return 200 with null data when memory key not found on GET#4421

Merged
waleedlatif1 merged 2 commits intostagingfrom
fix/memory-get-404-regression
May 3, 2026
Merged

fix(memory): return 200 with null data when memory key not found on GET#4421
waleedlatif1 merged 2 commits intostagingfrom
fix/memory-get-404-regression

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • The `memory_get` tool was changed in fix(memories): get memory tool, mem0 integration update #4415 to call `GET /api/memory/{id}` instead of the list endpoint
  • When a memory key doesn't exist yet, the `[id]` route returned 404 — but the executor throws on any non-2xx response before `transformResponse` is ever called
  • This broke workflows using Memory blocks with `get` on first run (key doesn't exist yet), causing a "Memory not found" error instead of returning an empty memories array
  • Fix: return `200` with `{ success: true, data: null }` when the key isn't found, so `transformResponse` can handle it gracefully and return `{ memories: [], message: 'No memories found' }`
  • DELETE and PUT handlers correctly keep their 404 behavior — only GET needed this change

Type of Change

  • Bug fix

Testing

Tested by tracing executor flow through `executeToolRequest` — non-2xx responses throw before `transformResponse`, 200+null flows through correctly.

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 9:41am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 3, 2026

PR Summary

Medium Risk
Changes GET /api/memory/[id] semantics from 404 to 200+null for missing keys, which could affect any callers that relied on a 404 for control flow.

Overview
Updates GET /api/memory/[id] to return 200 with { success: true, data: null } when no memory exists for the given key/workspace, instead of a 404 error.

Adds a memory_get tool test to assert that null data is transformed into an empty memories array with the message No memories found.

Reviewed by Cursor Bugbot for commit 840b9dc. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 3, 2026

Greptile Summary

This PR fixes a regression introduced in #4415 where the memory_get tool's switch to GET /api/memory/{id} broke first-run workflows: the [id] route returned 404 when no memory existed, which caused the executor to throw before transformResponse could handle the empty case. The fix returns 200 { success: true, data: null } for missing keys and adds a regression test covering that path.

Confidence Score: 5/5

Safe to merge — targeted, well-reasoned single-line fix with a new regression test.

The change is minimal and correct: the GET handler now returns HTTP 200 with null data instead of 404 for missing keys, which allows transformResponse (guarded by if (!memory)) to return the expected empty-memories shape. DELETE and PUT correctly retain 404. The new test directly exercises the null-data path. No P0 or P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/app/api/memory/[id]/route.ts Single-line fix: GET handler now returns 200 with null data instead of 404 when a memory key is not found, allowing the executor's transformResponse to handle the empty-state gracefully.
apps/sim/tools/memory/get.test.ts Adds a regression test for the { success: true, data: null } response shape, directly covering the null-data path introduced by this fix.

Sequence Diagram

sequenceDiagram
    participant Executor
    participant MemoryRoute as GET /api/memory/[id]
    participant DB

    Executor->>MemoryRoute: GET request for memory key
    MemoryRoute->>DB: SELECT WHERE key matches, deletedAt IS NULL
    DB-->>MemoryRoute: empty result set

    note over MemoryRoute: Before fix
    MemoryRoute-->>Executor: 404 Memory not found
    Executor->>Executor: throws — transformResponse never called

    note over MemoryRoute: After fix
    MemoryRoute-->>Executor: 200 with null data
    Executor->>Executor: calls transformResponse
    Executor-->>Executor: returns empty memories array
Loading

Reviews (2): Last reviewed commit: "test(memory): add null-data path test fo..." | Re-trigger Greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

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 840b9dc. Configure here.

@waleedlatif1 waleedlatif1 merged commit f76a10c into staging May 3, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/memory-get-404-regression branch May 3, 2026 09:48
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