{"record":{"id":"9aa959cfdcf6f432","repo":"TencentCloud/TencentDB-Agent-Memory","slug":"agent-fixed-asset-set-failed-setenv-code","errorCode":null,"errorMessage":"agent-fixed-asset/set failed: ${setEnv.code}","messagePattern":"agent-fixed-asset/set failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"MemoryPanel/src/panel/http/routes/meta/proxy.ts","lineNumber":439,"sourceCode":"    injection_mode?: string;\n    priority?: number;\n    created_by?: string;\n  }>(listEnv);\n  if (bindings.some((b) => b.asset_id === assetId)) return; // 已绑定，幂等跳过\n\n  const newBindings = [\n    ...bindings.map((b) => ({\n      asset_id: b.asset_id,\n      asset_type: b.asset_type,\n      injection_mode: b.injection_mode ?? 'summary',\n      priority: b.priority ?? 50,\n      created_by: b.created_by,\n    })),\n    { asset_id: assetId, asset_type: assetType, injection_mode: 'tool', priority: 50, created_by: caller },\n  ];\n  const setEnv = await deps.metaKernel.invoke('agent-fixed-asset/set', { agent_id: agentId, bindings: newBindings }, ctx);\n  if (setEnv.code !== 0) {\n    throw new Error(`agent-fixed-asset/set failed: ${setEnv.code}`);\n  }\n}\n\n// ── team-member/add 成功后：为 default-agent 导入预置 Skill ──\n\nasync function importDefaultSkillsForNewMember(\n  body: Record<string, unknown>,\n  ctx: MetaCallContext,\n  deps: PanelDeps,\n): Promise<void> {\n  try {\n    const userId = body.user_id as string | undefined;\n    const teamId = body.team_id as string | undefined;\n    if (!userId || !teamId) return;\n\n    // 1. 获取用户信息（拿 username 拼 agent 名称）\n    const userEnv = await deps.metaKernel.invoke('user/get', { user_id: userId }, ctx);\n    if (userEnv.code !== 0) return;","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/3efcd317b84146d6a08518ac0f7ee7c8a8d200ec/MemoryPanel/src/panel/http/routes/meta/proxy.ts#L421-L457","documentation":"allocateKnowledgeToAgent calls the meta-kernel operation 'agent-fixed-asset/set' and expects a response envelope. A non-zero `code` on the envelope means the kernel rejected the agent asset-binding update (e.g. unknown agent_id, invalid bindings, or an internal kernel failure). The throw surfaces only the numeric code, not the kernel's human-readable message, which makes diagnosis from the caller side harder.","triggerScenarios":"Calling cloneTemplateAssets (which calls allocateKnowledgeToAgent) when: the target agent_id does not exist in the kernel; the bindings payload fails kernel-side validation (e.g. asset_id not found, bad asset_type); the meta-kernel is degraded and returns an internal error code; or the caller lacks permission to mutate the agent's fixed assets.","commonSituations":"Cloning a team template right after team-member/add when the default agent has not finished provisioning; kernel schema/version drift where 'injection_mode' or 'priority' fields are rejected; transient kernel store failures during asset import.","solutions":["Log the full setEnv envelope (message/data) instead of only code, then fix the root cause reported by the kernel","Verify the agent_id exists before invoking 'agent-fixed-asset/set' (fetch the agent or list agents first)","Validate each binding (asset_id exists, asset_type/injection_mode values accepted by the current kernel version)","Retry the clone operation if the kernel returned a transient error code; check kernel health if failures persist"],"exampleFix":"// before\nconst setEnv = await deps.metaKernel.invoke('agent-fixed-asset/set', { agent_id: agentId, bindings: newBindings }, ctx);\nif (setEnv.code !== 0) {\n  throw new Error(`agent-fixed-asset/set failed: ${setEnv.code}`);\n}\n// after\nconst setEnv = await deps.metaKernel.invoke('agent-fixed-asset/set', { agent_id: agentId, bindings: newBindings }, ctx);\nif (setEnv.code !== 0) {\n  throw new Error(`agent-fixed-asset/set failed: code=${setEnv.code} agent=${agentId} msg=${(setEnv as any).message ?? 'n/a'}`);\n}","handlingStrategy":"validation","validationCode":"const agents = await deps.metaKernel.invoke('agent/list', {}, ctx);\nif (agents.code !== 0 || !agents.data?.some(a => a.agent_id === agentId)) {\n  throw new Error(`agent ${agentId} not found before agent-fixed-asset/set`);\n}","typeGuard":"function isOkEnvelope(env: { code: number }): env is { code: 0 } {\n  return env.code === 0;\n}","tryCatchPattern":"try {\n  const setEnv = await deps.metaKernel.invoke('agent-fixed-asset/set', { agent_id: agentId, bindings: newBindings }, ctx);\n  if (!isOkEnvelope(setEnv)) throw new Error(`agent-fixed-asset/set failed: ${setEnv.code}`);\n} catch (e) {\n  logger.error({ agentId, bindingCount: newBindings.length, err: e });\n  throw e;\n}","preventionTips":["Always verify the target agent exists before mutating its assets","Log the full kernel envelope (code + message + data), never just the code","Validate asset_ids referenced by templates exist in the kernel before cloning","Treat kernel non-zero codes as retriable vs fatal via an explicit code table"],"tags":["meta-kernel","envelope-error","agent-assets"],"backgroundTag":"meta-kernel-invocation-failed","analyzedSha":"3efcd317b84146d6a08518ac0f7ee7c8a8d200ec","analyzedAt":"2026-09-01T05:44:22.276Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}