mastra-ai/mastra · error · HTTPException
resourceId is required for observational memory lookup
Error message
resourceId is required for observational memory lookup
What it means
The GET observational-memory handler requires a resourceId query parameter, because OM records are always keyed by resource. The request omitted it (or it was an empty string), so the lookup was rejected before touching storage.
Solutions
- Add the resourceId query parameter identifying the OM resource you want the record for.
- If resourceId isn't known yet, defer the call until the chat/resource is established (mirror the gateway branch which returns an empty record for /chat/new).
- Validate params in the client and skip the request when resourceId is missing.
Example fix
// before
fetch(`/api/memory/observational-memory?agentId=${agentId}&threadId=${threadId}`);
// after
fetch(`/api/memory/observational-memory?agentId=${agentId}&threadId=${threadId}&resourceId=${resourceId}`); Defensive patterns
Strategy: validation
Validate before calling
if (!resourceId) {
// skip the request entirely
return { record: null, history: undefined };
}
const url = `/api/memory/observational-memory?agentId=${agentId}&resourceId=${encodeURIComponent(resourceId)}${threadId ? `&threadId=${threadId}` : ''}`; Try / catch
try {
const res = await fetch(url);
if (res.status === 400) return { record: null, history: undefined };
return await res.json();
} catch (e) {
return { record: null, history: undefined };
} Prevention
- Treat resourceId as mandatory for all OM routes
- Don't render the OM panel until a resource id exists
- Encode query params and check for empty strings
- Add a client-side param schema check before fetching
When it happens
Trigger: GET /api/memory/observational-memory?agentId=...&threadId=... without a resourceId query param — e.g. a UI calls the route from a 'new chat' page where only a thread exists, or a client drops the resourceId param entirely.
Common situations: Frontend built against an older route shape that didn't require resourceId; opening OM panel before a resource is established; empty string params stripped by an HTTP client; confusion between thread-scoped and resource-scoped OM lookup keys.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- resourceId is required
- Both baselineResponse and noisyQuery are required for Noise…
- Built-in Subconscious reflection agent
- Cursor is required
- Custom Subconscious reflection agent
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/e469d2e8f1230b66.
Report an issue: GitHub.
Appendix: source
Thrown at packages/server/src/server/handlers/memory.ts:712
const memory = await getMemoryFromContext({ mastra, agentId, requestContext });
if (!memory) {
throw new HTTPException(400, { message: 'Memory is not configured for this agent' });
}
let memoryStore: MemoryStorage | undefined;
try {
memoryStore = await memory.storage.getStore('memory');
} catch {
throw new HTTPException(400, { message: 'Memory storage is not initialized' });
}
if (!memoryStore) {
throw new HTTPException(400, { message: 'Memory storage is not initialized' });
}
// Determine the resourceId to use
const effectiveResourceId = resourceId;
if (!effectiveResourceId) {
throw new HTTPException(400, { message: 'resourceId is required for observational memory lookup' });
}
// For resource-scoped OM, lookup by resourceId only (threadId=null)
const omThreadId = omConfig.scope === 'resource' ? null : (threadId ?? null);
// Get current record
const record = await memoryStore.getObservationalMemory(omThreadId, effectiveResourceId);
// Get history
const history = await memoryStore.getObservationalMemoryHistory(
omThreadId,
effectiveResourceId,
historyLimit,
historyOptions,
);
return {
record: record ?? null,View on GitHub (pinned to 75dd419e61)