thedotmack/claude-mem · error
not_found
not_found
Error message
not_found
What it means
DELETE /v1/observations/:id returns 404 with a bare { error: 'not_found' } body when deleteObservationForScope deletes nothing — either no observation with that id exists for the caller's team, or it exists but belongs to a project the caller's project-scoped key cannot touch. Note this route uses lowercase 'not_found' and no message field, unlike other 404s in the same file.
Solutions
- Confirm the observation id exists and belongs to the team/project bound to your key before deleting
- Make deletion idempotent: treat 404 as 'already deleted' and succeed silently in cleanup workflows
- List observations first to obtain valid, in-scope ids
Example fix
// before
await api.delete(`/v1/observations/${id}`); // crashes workflow on 404
// after
const res = await api.delete(`/v1/observations/${id}`);
if (res.status === 404) return; // already deleted — idempotent cleanup
if (!res.ok) throw new Error(`delete failed: ${res.status}`); Defensive patterns
Strategy: try-catch
Validate before calling
const list = await listObservations({ projectId });
if (!list.some(o => o.id === id)) {
return; // nothing to delete for this team/project
} Try / catch
const res = await api.delete(`/v1/observations/${id}`);
if (res.status === 404) return; // already deleted or out of scope — idempotent
if (!res.ok) throw new Error(`observation delete failed: ${res.status}`); Prevention
- Make delete workflows idempotent (queue consumers may double-deliver)
- Only delete ids listed with the same key/team
- Watch for the lowercase 'not_found' body on this route when parsing errors
When it happens
Trigger: Deleting an observation id that was already deleted, an id from another team, or using a project-scoped key on an observation belonging to a different project.
Common situations: Double-invocation of delete in a queue consumer; syncing deletion by IDs harvested from another environment; scope-mismatched keys after project re-org.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17).
Data as JSON: /api/errors/58594df66d96f8fe.
Report an issue: GitHub.
Appendix: source
Thrown at src/server/routes/v1/ServerV1PostgresRoutes.ts:1093
await server.connect(transport);
await transport.handleRequest(req, res, req.body);
});
// MCP streamable-HTTP only uses POST (JSON-RPC) and GET (SSE). Scope the
// route to those instead of app.all, so DELETE/PUT/PATCH/OPTIONS don't run
// auth + transport only to be rejected.
app.post('/v1/mcp', readAuth, mcpHandler);
app.get('/v1/mcp', readAuth, mcpHandler);
// DELETE /v1/memories/:id — forget a single observation (sources cascade).
app.delete('/v1/memories/:id', writeAuth, this.asyncHandler(async (req, res) => {
const teamId = this.requireTeamId(req, res);
if (!teamId) return;
const id = String(req.params.id);
const projectScope = req.authContext?.projectId ?? null;
try {
const deleted = await this.deleteObservationForScope(id, teamId, projectScope);
if (!deleted) {
res.status(404).json({ error: 'not_found' });
return;
}
await this.auditWrite(req, 'observation.deleted', id, projectScope, { via: 'api' });
res.status(200).json({ deleted: true, id });
} catch (error) {
const err = error instanceof Error ? error : new Error(String(error));
logger.warn('SYSTEM', 'observation.delete failed', { requestId: req.requestId ?? null }, err);
this.handleDbError(err, res, 'observation.delete');
}
}));
// DELETE /v1/projects/:projectId/memory — forget EVERYTHING captured for a
// project (observations, raw events, sessions, jobs). Keeps the project shell.
app.delete('/v1/projects/:projectId/memory', writeAuth, this.asyncHandler(async (req, res) => {
const teamId = this.requireTeamId(req, res);
if (!teamId) return;
const projectId = String(req.params.projectId);
if (!this.ensureProjectAllowed(req, res, projectId)) return;View on GitHub (pinned to d8bc9755e7)