mastra-ai/mastra · error

Subconscious remind requires organizationId in the request c

Error message

Subconscious remind requires organizationId in the request context.

What it means

`resolveScope` in packages/memory/src/processors/observational-memory/subconscious/remind.ts:31 builds the knowledge scope for subconscious remind from the request context. The library requires an `organizationId` entry in `requestContext` to partition knowledge per tenant and throws when it is missing, not a string, or empty/whitespace.

Source

Thrown at packages/memory/src/processors/observational-memory/subconscious/remind.ts:31

const NO_REMINDER = '<no-reminder />';
const DEFAULT_INSTRUCTIONS = `Review the current observations and use the knowledge tools to find prior knowledge that is directly relevant now.

Be selective. Treat future-dated records as relevant when their time is imminent or useful to the current task. When the observations show whether an earlier reminder was used, tune your selectivity accordingly without storing hit/miss counters.
Never remind about knowledge that is already visible in the current observations or recent messages — a reminder is only valuable for knowledge the agent can no longer see. Echoing back what was just said or just captured is noise.
If nothing is relevant, respond with exactly ${NO_REMINDER} and nothing else.
If knowledge is relevant, return one concise reminder that explains why it matters and includes source node or record IDs. Do not invent knowledge and do not expose knowledge outside the tools' scoped results.`;

/** Own-thread records younger than this are treated as still-in-context and excluded from reminder candidates. */
const FRESH_OWN_RECORD_WINDOW_MS = 30 * 60 * 1000;

function resolveScope(context: {
  requestContext?: { get(key: string): unknown };
  resourceId?: string;
  threadId: string;
}) {
  const organizationId = context.requestContext?.get('organizationId');
  if (typeof organizationId !== 'string' || !organizationId.trim()) {
    throw new Error('Subconscious remind requires organizationId in the request context.');
  }
  const resourceId = resolveKnowledgeResourceId(context.requestContext, context.resourceId);
  if (!resourceId) {
    throw new Error('Subconscious remind requires a resourceId.');
  }

  return canonicalizeKnowledgeScope([`org:${organizationId}`, `resource:${resourceId}`, `thread:${context.threadId}`]);
}

const REMINDER_QUERY_STOP_WORDS = new Set([
  'about',
  'after',
  'before',
  'current',
  'from',
  'have',
  'observations',
  'that',

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Set `requestContext.set('organizationId', '<your-org-id>')` before the memory/agent call that triggers remind.
  2. Ensure the value is a non-empty trimmed string (e.g. `String(orgId)` if it comes from a JWT claim or header).
  3. If requestContext is built per-request, add organizationId in the middleware that constructs it.

Example fix

// before
await memory.remember({ threadId, resourceId, requestContext: new Map() });
// after
await memory.remember({
  threadId,
  resourceId,
  requestContext: new Map([['organizationId', 'org_123']]),
});
Defensive patterns

Strategy: validation

Validate before calling

const organizationId = requestContext?.get('organizationId');
if (typeof organizationId !== 'string' || !organizationId.trim()) {
  throw new Error('organizationId must be set in requestContext before invoking memory operations');
}

Type guard

function hasOrganizationId(ctx) {
  const v = ctx?.requestContext?.get('organizationId');
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  await memory.remember({ threadId, resourceId, requestContext });
} catch (e) {
  if (e.message.includes('requires organizationId')) {
    requestContext.set('organizationId', defaultOrgId);
    return memory.remember({ threadId, resourceId, requestContext });
  }
  throw e;
}

Prevention

When it happens

Trigger: Invoking remind (directly or via the processor path) with a context whose `requestContext.get('organizationId')` returns undefined (key never set), a non-string value (number/object), or `' '`.

Common situations: Server integrations that forget to forward tenant headers into requestContext; calling memory APIs outside a request handler where requestContext is undefined; moving from single-tenant to multi-tenant usage without adding the organizationId key.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/fb1614eb2cf438f6. Report an issue: GitHub.