{"record":{"id":"c7aab231849e9168","repo":"rohitg00/agentmemory","slug":"mem-search-agentmemory-agent-scope-isolated-is-s","errorCode":null,"errorMessage":"mem::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::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/search.ts","lineNumber":426,"sourceCode":"      // with filterAgentId=undefined is the same leak this fix is\n      // supposed to close.\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::search: AGENTMEMORY_AGENT_SCOPE=isolated is set but no \" +\n            \"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      const format = typeof data.format === 'string' ? data.format : 'full'\n      if (!['full', 'compact', 'narrative'].includes(format)) {\n        throw new Error(\"mem::search: format must be one of 'full', 'compact', or 'narrative'\")\n      }\n      let tokenBudget: number | undefined\n      if (data.token_budget !== undefined) {\n        if (!Number.isInteger(data.token_budget) || data.token_budget < 1) {\n          throw new Error('mem::search: token_budget must be a positive integer')\n        }\n        tokenBudget = data.token_budget\n      }\n","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/rohitg00/agentmemory/blob/e04ba88819c365c9acf9d6661ea802143e728bd6/src/functions/search.ts#L408-L444","documentation":"With AGENTMEMORY_AGENT_SCOPE=isolated, mem::search restricts results to a single agent. If no agent id can be resolved (no explicit agentId in the call, no AGENT_ID env var, and no wildcard), the function throws rather than silently reading across agents. agentId: \"*\" explicitly opts into wildcard reads.","triggerScenarios":"Calling mem::search via MCP/REST with AGENTMEMORY_AGENT_SCOPE=isolated set in the daemon environment while AGENT_ID is unset and the payload carries no agentId.","commonSituations":"Isolation mode enabled but the daemon launched without AGENT_ID (Docker/systemd env not updated); MCP tool calls that don't forward agentId; multi-agent setups where a helper agent was never assigned an id.","solutions":["Export AGENT_ID in the daemon's environment and restart the daemon.","Include an explicit agentId in the search payload.","Pass agentId: \"*\" for an intentional cross-agent search.","Disable AGENTMEMORY_AGENT_SCOPE=isolated if per-agent isolation is not required."],"exampleFix":"// before\nawait trigger({ function_id: 'mem::search', payload: { query: q } });\n// after\nawait trigger({ function_id: 'mem::search', payload: { query: q, agentId: process.env.AGENT_ID ?? '*' } });","handlingStrategy":"validation","validationCode":"const agentId = explicitAgentId ?? process.env.AGENT_ID ?? '*';\nif (!agentId) throw new Error('agentId required under isolated scope');","typeGuard":"function hasAgentId(v: unknown): v is string {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":"try {\n  return await trigger({ function_id: 'mem::search', payload });\n} catch (e) {\n  if (String(e.message).includes('no agent id is available')) {\n    return await trigger({ function_id: 'mem::search', payload: { ...payload, agentId: '*' } });\n  }\n  throw e;\n}","preventionTips":["Set AGENT_ID in the daemon's process environment, not just your shell.","Forward agentId through MCP/REST wrappers.","Audit configs after enabling AGENTMEMORY_AGENT_SCOPE=isolated.","Standardize on one shared payload builder that injects agentId."],"tags":["multi-agent","isolation","environment-variable","search"],"backgroundTag":"agent-scope-isolated-no-agent-id","analyzedSha":"e04ba88819c365c9acf9d6661ea802143e728bd6","analyzedAt":"2026-08-30T01:07:40.754Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}