{"record":{"id":"7f00687bf467f4c5","repo":"JuliusBrussee/caveman","slug":"qwen-routed-profile-is-missing-key","errorCode":null,"errorMessage":"Qwen routed profile is missing ${key}","messagePattern":"Qwen routed profile is missing (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":9152,"sourceCode":"      // whenever native registration + journal + effective policy do not agree.\n      const configured = jsonValueAt(baseConfig, [\"mcp\", \"excluded\"]);\n      const preserved = Array.isArray(configured)\n        ? configured.filter((item): item is string => typeof item === \"string\")\n        : [];\n      rawOverlay = deepMerge(rawOverlay, {\n        mcp: { excluded: [...new Set([...preserved, \"caveman\"])] },\n      });\n    }\n  }\n  const overlay = (mcpMode === \"auto\" ? rawOverlay : withoutCavemanMcpServer(rawOverlay as JsonObject)) as JsonObject;\n  const merged = deepMerge(baseConfig, overlay) as JsonObject;\n  if (agent.id === \"qwen\") {\n    // Qwen treats these as whole-object REPLACE settings. Our generic merge is\n    // intentionally conservative for other agents, but retaining a sibling\n    // provider here would make it selectable at runtime outside /w/qwen.\n    for (const key of [\"modelProviders\", \"providerProtocol\"] as const) {\n      const value = overlay[key];\n      if (value === undefined) throw new Error(`Qwen routed profile is missing ${key}`);\n      merged[key] = cloneJsonValue(value);\n    }\n  }\n  const rendered = JSON.stringify(merged, null, 2);\n  if (rendered === undefined) throw new Error(\"merged config is not JSON\");\n  const outDir = mkdtempSync(join(tmpdir(), \"caveman-wrap-\"));\n  const outPath = join(outDir, `${agent.id}.json`);\n  writeFileSync(outPath, rendered + \"\\n\", { mode: 0o600 });\n  wrapTempDirs.add(outDir);\n  env[inj.env_var] = outPath;\n}\n\nfunction cleanupWrapTempDirs() {\n  for (const dir of [...wrapTempDirs]) {\n    try {\n      rmSync(dir, { recursive: true, force: true });\n    } catch {\n      // Temp cleanup is best-effort; wrap must never fail after child exit.","sourceCodeStart":9134,"sourceCodeEnd":9170,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L9134-L9170","documentation":"This error is thrown when building a wrapped CLI config for the Qwen agent (agent.id === \"qwen\") during routed-profile wrapping. Qwen requires the overlay profile to carry both \"modelProviders\" and \"providerProtocol\" as whole-object REPLACE settings, and the generic conservative merge used for other agents would leave a sibling provider selectable at runtime outside /w/qwen. If either key is absent (undefined) in the overlay, the wrapper refuses to produce a silently mis-routed config and throws instead.","triggerScenarios":"Running the wrap/render path with agent \"qwen\" while the resolved overlay profile lacks either \"modelProviders\" or \"providerProtocol\" (e.g. a hand-written or older routed profile JSON that only carries model/provider strings, or a profile produced by a previous schema version).","commonSituations":"Users migrating old Qwen profiles to the new routed-profile format; hand-editing ~/.caveman profiles and deleting keys; profiles copied from agents like claude/codex whose overlays legitimately omit providerProtocol.","solutions":["Add the missing key(s) to the Qwen routed profile: set \"modelProviders\" (whole object) and \"providerProtocol\".","Regenerate the profile with the current CLI profile-creation flow instead of hand-editing, so both keys are populated.","If you intended a non-Qwen agent, ensure the correct agent id is selected so the Qwen REPLACE path is not taken.","Update the CLI if profiles were created by an older version with a different schema, then recreate the profile."],"exampleFix":"// before (profile JSON)\n{ \"qwen\": { \"model\": \"qwen3-max\" } }\n// after\n{ \"qwen\": { \"model\": \"qwen3-max\", \"modelProviders\": { \"qwen\": { \"baseUrl\": \"https://dashscope.aliyuncs.com/compatible-mode/v1\", \"model\": \"qwen3-max\" } }, \"providerProtocol\": \"openai\" } }","handlingStrategy":"validation","validationCode":"const overlay = profiles.qwen ?? {};\nif (agent.id === \"qwen\" && (!(\"modelProviders\" in overlay) || !(\"providerProtocol\" in overlay))) {\n  throw new Error(\"Qwen routed profile must define modelProviders and providerProtocol before wrapping\");\n}","typeGuard":"function isQwenOverlay(o: unknown): o is { modelProviders: Record<string, unknown>; providerProtocol: string } {\n  return typeof o === \"object\" && o !== null\n    && \"modelProviders\" in o && o.modelProviders !== null\n    && \"providerProtocol\" in o && typeof (o as any).providerProtocol === \"string\";\n}","tryCatchPattern":"try {\n  await cli.run([\"wrap\", \"--agent\", \"qwen\"]);\n} catch (e) {\n  if (String((e as Error).message).includes(\"Qwen routed profile is missing\")) {\n    // recreate the profile via the CLI instead of hand-edited JSON\n  }\n}","preventionTips":["Never hand-edit routed profile JSON; use the CLI's profile management commands.","Validate profile files against the current schema after CLI upgrades.","Keep modelProviders and providerProtocol as a pair when editing profiles."],"tags":["config","qwen","routing","missing-key"],"backgroundTag":"missing-required-config-field","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}