{"record":{"id":"cbee31cb430d6cac","repo":"rohitg00/agentmemory","slug":"mem-smart-search-agentmemory-agent-scope-isolate","errorCode":null,"errorMessage":"mem::smart-search: AGENTMEMORY_AGENT_SCOPE=isolated is set but no agent id is available (env AGENT_ID unset and no explicit agentId in the call). Refusing to read cross-agent rows. Pass agentId: \"*\" to opt in to a wildcard read.","messagePattern":"mem::smart-search: AGENTMEMORY_AGENT_SCOPE=isolated is set but no agent id is available \\(env AGENT_ID unset and no explicit agentId in the call\\)\\. Refusing to read cross-agent rows\\. Pass agentId: \"\\*\" to opt in to a wildcard read\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/functions/smart-search.ts","lineNumber":124,"sourceCode":"      // filterAgentId fall through to `undefined` would be the same\n      // cross-agent leak this filter is meant to prevent.\n      const isolated = isAgentScopeIsolated();\n      const explicitAgentId =\n        typeof data.agentId === \"string\" && data.agentId.trim().length > 0\n          ? data.agentId.trim()\n          : undefined;\n      const wildcardAgent = explicitAgentId === \"*\";\n      const envAgentId = isolated ? getAgentId() : undefined;\n      const filterAgentId = wildcardAgent\n        ? undefined\n        : explicitAgentId ?? envAgentId;\n      if (\n        isolated &&\n        !wildcardAgent &&\n        !explicitAgentId &&\n        !envAgentId\n      ) {\n        throw new Error(\n          \"mem::smart-search: AGENTMEMORY_AGENT_SCOPE=isolated is set but \" +\n            \"no agent id is available (env AGENT_ID unset and no explicit \" +\n            \"agentId in the call). Refusing to read cross-agent rows. \" +\n            'Pass agentId: \"*\" to opt in to a wildcard read.',\n        );\n      }\n\n      if (data.expandIds && data.expandIds.length > 0) {\n        const raw = data.expandIds.slice(0, 20);\n        const items = raw.map((entry) => {\n          if (typeof entry === \"string\") return { obsId: entry, sessionId: undefined as string | undefined };\n          if (entry && typeof entry === \"object\" && typeof (entry as any).obsId === \"string\") {\n            return { obsId: (entry as any).obsId, sessionId: (entry as any).sessionId as string | undefined };\n          }\n          return null;\n        }).filter((item): item is NonNullable<typeof item> => item !== null);\n\n        const expanded: Array<{","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/rohitg00/agentmemory/blob/e04ba88819c365c9acf9d6661ea802143e728bd6/src/functions/smart-search.ts#L106-L142","documentation":"When AGENTMEMORY_AGENT_SCOPE=isolated, smart-search refuses to read rows belonging to other agents unless it can positively resolve a single agent id. If the env var AGENT_ID is unset and the call carries no explicit agentId, the function throws rather than silently scanning cross-agent data. Passing agentId: \"*\" is the explicit opt-in to a wildcard cross-agent read.","triggerScenarios":"Running with AGENTMEMORY_AGENT_SCOPE=isolated while AGENT_ID is not exported in the process environment, and calling sdk.trigger({ function_id: 'mem::smart-search', payload: { query } }) without an agentId field in the payload.","commonSituations":"Developers set the isolation flag in a .env or deployment config but forget to set AGENT_ID; local test harnesses spawn functions without the daemon's env; scripts call the REST API without forwarding an agentId header/field.","solutions":["Set the AGENT_ID environment variable in the process that hosts the SDK connection.","Pass an explicit agentId in the call payload: sdk.trigger({ function_id: 'mem::smart-search', payload: { query, agentId: 'my-agent' } }).","If a cross-agent read is truly intended, pass agentId: \"*\" explicitly to acknowledge it.","Remove AGENTMEMORY_AGENT_SCOPE=isolated if isolation was not the intent."],"exampleFix":"// before\nawait sdk.trigger({ function_id: \"mem::smart-search\", payload: { query } });\n// after\nawait sdk.trigger({ function_id: \"mem::smart-search\", payload: { query, agentId: process.env.AGENT_ID ?? \"my-agent\" } });\n// or, deliberate wildcard:\nawait sdk.trigger({ function_id: \"mem::smart-search\", payload: { query, agentId: \"*\" } });","handlingStrategy":"validation","validationCode":"const isolated = process.env.AGENTMEMORY_AGENT_SCOPE === \"isolated\";\nif (isolated && !payload.agentId && !process.env.AGENT_ID) {\n  throw new Error(\"isolated scope needs AGENT_ID env or explicit agentId in payload\");\n}","typeGuard":"function hasAgentScope(p: { agentId?: string }): p is typeof p & { agentId: string } {\n  return typeof p.agentId === \"string\" && p.agentId.length > 0;\n}","tryCatchPattern":"try {\n  return await sdk.trigger({ function_id: \"mem::smart-search\", payload });\n} catch (e) {\n  if (String(e.message).includes(\"no agent id is available\")) {\n    return await sdk.trigger({ function_id: \"mem::smart-search\", payload: { ...payload, agentId: process.env.AGENT_ID ?? \"*\" } });\n  }\n  throw e;\n}","preventionTips":["Always export AGENT_ID wherever AGENTMEMORY_AGENT_SCOPE=isolated is set (pair them in the same .env/deployment spec).","Default-inject agentId into payloads from a central client wrapper.","Reserve agentId: \"*\" for audited admin paths only."],"tags":["environment","agent-isolation","configuration"],"backgroundTag":"missing-env-var","analyzedSha":"e04ba88819c365c9acf9d6661ea802143e728bd6","analyzedAt":"2026-08-30T01:07:40.754Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}