Skip to content

fix(api): answer a missing memory with MEMORY_NOT_FOUND - #311

Merged
nathanschmid08 merged 1 commit into
Open-Glassbeetle:mainfrom
shounakjoshi88-a11y:fix/api/memory-not-found-code
Nov 11, 2026
Merged

nathanschmid08 merged 1 commit into
Open-Glassbeetle:mainfrom
shounakjoshi88-a11y:fix/api/memory-not-found-code

Conversation

@shounakjoshi88-a11y

Copy link
Copy Markdown
Contributor

What changed

A missing memory now answers with its own code, MEMORY_NOT_FOUND, instead of the generic NOT_FOUND that the router also emits for a route that does not exist.

Every resource in the API answers a missing row with its own code. The two memory services did not: they threw the bare-string form of NotFoundException, so the envelope fell back to the generic NOT_FOUND:

GET /api/v1/memories/<ghost>                   404  NOT_FOUND   <- before
GET /api/v1/memories/<ghost>/nonsense          404  NOT_FOUND   (the route does not exist)

The only thing separating "this memory does not exist" from "this endpoint does not exist" was prose in message, the one field a client is not supposed to branch on.

All seven throw sites now use the object form, like the sibling resources and like the agent check one function up in the same service:

throw new NotFoundException({
  code: 'MEMORY_NOT_FOUND',
  message: `Memory with ID "${memoryId}" not found`,
});
  • memory/shared-memories/shared-memories.service.ts: findOne, update, remove
  • memory/agent-memories/agent-memories.service.ts: findOne, update, remove

The agent in the path keeps its own code (AGENT_NOT_FOUND): the agent in the path and the memory under it are different misses, and keeping them apart is the point.

The six service methods that can answer a missing memory now document the code they raise, and the specs assert the code and not only the status, which is what let this slip through.

Why

Closes #308

How it was tested

$ npm run test -w @glassbeetle/api -- src/modules/memory
 Test Files  11 passed (11)
      Tests  195 passed (195)

The eight new assertions fail without the change:

FAIL  src/modules/memory/agent-memories/agent-memories.service.spec.ts > AgentMemoriesService > findOne > throws 404 with MEMORY_NOT_FOUND when memory does not exist for an existing agent
-     "code": "MEMORY_NOT_FOUND",
 421|         response: { code: 'MEMORY_NOT_FOUND' },
$ npm run lint -w @glassbeetle/api
$ npm run format:check -w @glassbeetle/api
$ npm run build -w @glassbeetle/api

The lint, the format check and the build are clean for the four changed files. npm run format:check also reports three files I did not touch (agent-memory.mapper.ts, shared-memory.mapper.ts, tag-helpers.spec.ts), which are already unformatted on main.

Anything left out, or worth a second opinion

  • docs/api-conventions.md does not list the codes, so it needs no change; it says a code is stable and machine-readable and that an exception may supply a more specific one, which is what this does.
  • The two controllers have no @ApiNotFoundResponse on the memory routes, so there is no description to name the code in. The one that exists (agent-memories.controller.ts, on removeAll) is about the agent and keeps AGENT_NOT_FOUND.
  • The wrong-owner case (a memory of another agent) reports MEMORY_NOT_FOUND now, as the issue asks; no separate code was invented for it.

Every resource in the API answers a missing row with its own code. The two
memory services did not: they threw the bare-string form of
NotFoundException, so the envelope fell back to the generic NOT_FOUND, the
same code the router emits for a route that does not exist. A client could
not tell "this memory does not exist" from "this endpoint does not exist"
except by reading prose in the message, the one field a client is not
supposed to branch on.

All seven throw sites now use the object form, like the sibling resources
and like the agent check one function up in the same service:

    throw new NotFoundException({
      code: 'MEMORY_NOT_FOUND',
      message: `Memory with ID "${memoryId}" not found`,
    });

The agent in the path keeps its own code (AGENT_NOT_FOUND): the agent in the
path and the memory under it are different misses, and keeping them apart
is the point.

The six service methods that can answer a missing memory now document the
code they raise, and the specs assert the code and not only the status,
which is what let this slip through.

Signed-off-by: Shounak Joshi <shounakjoshi88@gmail.com>
@nathanschmid08

Copy link
Copy Markdown
Contributor

@all-contributors please add @shounakjoshi88-a11y for code

@allcontributors

Copy link
Copy Markdown
Contributor

@nathanschmid08

I've put up a pull request to add @shounakjoshi88-a11y! 🎉

@nathanschmid08

Copy link
Copy Markdown
Contributor

Hi @shounakjoshi88-a11y , Thanks for the PR. It is very much appreciated.
I just finished looking through everything and it looks really good, therefore I will merge it now.
Enjoy the day!

@nathanschmid08
nathanschmid08 merged commit 3ba2e11 into Open-Glassbeetle:main Nov 11, 2026
@shounakjoshi88-a11y

Copy link
Copy Markdown
Contributor Author

Thank you for the review and the merge, and for the all-contributors entry - much appreciated.

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.

A missing memory answers the generic NOT_FOUND, the same code the router uses for a missing route

2 participants