{"record":{"id":"5351c37064ebbcf9","repo":"TencentCloud/TencentDB-Agent-Memory","slug":"llm-provider-proxy-instanceid-core-instanc","errorCode":null,"errorMessage":"llm.provider=proxy 需要 instanceId，但 core 当前 instanceId 为空 —— service 模式下确保请求带 x-tdai-service-id，standalone 模式下确保 yaml 有 instanceId","messagePattern":"llm\\.provider=proxy 需要 instanceId，但 core 当前 instanceId 为空 —— service 模式下确保请求带 x-tdai-service-id，standalone 模式下确保 yaml 有 instanceId","errorType":"validation","errorClass":"LlmResolveError","httpStatus":null,"severity":"error","filePath":"MemoryCore/src/gateway/llm-resolver.ts","lineNumber":60,"sourceCode":"export function resolveEffectiveLlmConfig(\n  llm: StandaloneLLMConfig,\n  instanceId: string | undefined,\n  memorySystemUser: MemorySystemUserConfig | undefined,\n): StandaloneLLMConfig {\n  const provider = llm.provider ?? \"openai\";\n  if (provider !== \"proxy\") {\n    // 默认路径：原样返回，行为完全等价改造前\n    return llm;\n  }\n\n  // provider=proxy 的校验\n  if (!llm.baseUrl) {\n    throw new LlmResolveError(\n      \"llm.provider=proxy 需要 llm.baseUrl 指向 context_proxy 根 URL (如 http://127.0.0.1:8096)\",\n    );\n  }\n  if (!instanceId || !instanceId.trim()) {\n    throw new LlmResolveError(\n      \"llm.provider=proxy 需要 instanceId，但 core 当前 instanceId 为空 —— \" +\n      \"service 模式下确保请求带 x-tdai-service-id，standalone 模式下确保 yaml 有 instanceId\",\n    );\n  }\n\n  const useSystemUserKey = llm.proxy?.useMemorySystemUserKey ?? true;\n  let effectiveApiKey = llm.apiKey;\n  if (useSystemUserKey) {\n    if (!memorySystemUser) {\n      throw new LlmResolveError(\n        \"llm.provider=proxy 且 llm.proxy.useMemorySystemUserKey=true 需要 \" +\n        \"metadata.systemUser.memory 完整配置（userId + userKey），当前缺失\",\n      );\n    }\n    if (!isValidMemorySystemUserKey(memorySystemUser.userKey)) {\n      throw new LlmResolveError(\n        \"metadata.systemUser.memory.userKey 必须匹配 sk-mem-[A-Za-z0-9_-]{32}\",\n      );","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/3efcd317b84146d6a08518ac0f7ee7c8a8d200ec/MemoryCore/src/gateway/llm-resolver.ts#L42-L78","documentation":"With llm.provider=proxy, the gateway needs an instanceId to build the per-instance proxy path /proxy/<iid>/v1. When the current instanceId is empty — i.e. no x-tdai-service-id header in service mode and no instanceId in standalone yaml — resolveEffectiveLlmConfig throws this LlmResolveError before any LLM call.","triggerScenarios":"provider=proxy with a valid baseUrl, but instanceId is empty: service-mode requests missing the x-tdai-service-id header, or standalone deployments whose yaml has no instanceId field (or it is whitespace).","commonSituations":"Calling the gateway directly via curl/SDK without the x-tdai-service-id header; new standalone deployment where the instanceId section was never filled; header stripped by an ingress/proxy; instanceId set only in a different config file than the one loaded.","solutions":["In service mode, send the x-tdai-service-id header on every request to the gateway (with the registered service instance id).","In standalone mode, set instanceId in the gateway yaml so the core has a non-empty id.","Check for ingress/load-balancer rules that strip x-tdai-service-id before it reaches MemoryCore.","Verify which config file is actually loaded (startup logs) — instanceId may be set in a different yaml than the active one."],"exampleFix":"// before (standalone yaml)\nllm:\n  provider: proxy\n  baseUrl: http://127.0.0.1:8096\n// after\ninstanceId: my-core-instance\nllm:\n  provider: proxy\n  baseUrl: http://127.0.0.1:8096\n// service mode: curl -H \"x-tdai-service-id: my-core-instance\" ...","handlingStrategy":"validation","validationCode":"const iid = process.env.INSTANCE_ID ?? yamlConfig.instanceId;\nif (llmConfig.provider === 'proxy' && !(iid && iid.trim())) {\n  throw new Error('provider=proxy requires a non-empty instanceId (yaml instanceId or x-tdai-service-id header)');\n}","typeGuard":"function hasInstanceId(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await gateway.start();\n} catch (err) {\n  if (err instanceof LlmResolveError && err.message.includes('instanceId')) {\n    console.error('Set yaml instanceId (standalone) or ensure x-tdai-service-id header (service mode)');\n  }\n  throw err;\n}","preventionTips":["Always send x-tdai-service-id on gateway requests in service mode","Verify ingress rules do not strip x-tdai-service-id","Set instanceId in standalone yaml as part of the deployment checklist","Log the effective instanceId at startup to catch empty values early"],"tags":["configuration","llm-proxy","instance-id","headers"],"backgroundTag":"missing-instance-id","analyzedSha":"3efcd317b84146d6a08518ac0f7ee7c8a8d200ec","analyzedAt":"2026-09-01T05:44:22.276Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}