{"record":{"id":"66029235f2536db3","repo":"JuliusBrussee/caveman","slug":"cannot-safely-resolve-qwen-s-effective-settings","errorCode":null,"errorMessage":"cannot safely resolve Qwen's effective settings","messagePattern":"cannot safely resolve Qwen's effective settings","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":9358,"sourceCode":"  if (agent?.id === \"gemini\" && wrapMode(gw) === \"managed\") {\n    throw new Error(\"managed Gemini CLI routing is unsupported because Gemini CLI cannot send separate Caveman and upstream credentials\");\n  }\n  const renderedGw = agent ? attributedGatewayUrl(gw, agent) : gw;\n  const env: NodeJS.ProcessEnv = {\n    ...process.env,\n    ...(agent?.injection.method === \"native-extension\" ? {} : wrapBaseUrlEnv(renderedGw)),\n  };\n  if (wrapMode(gw) === \"managed\") {\n    const gatewayKey = connectedGatewayAPIKey();\n    if (gatewayKey) env.CAVE_API_KEY = gatewayKey;\n  }\n  if (!agent) return env;\n  if (applyClaudeBedrockWrap(env, agent, renderedGw, gw)) return env;\n  const routeOverride = agentRouteOverride(agent, agentArgs);\n  if (agent.id === \"qwen\") {\n    const override = routeOverride;\n    if (override?.surface === \"effective settings\") {\n      throw new Error(\"cannot safely resolve Qwen's effective settings\");\n    }\n    if (override?.surface === \"--safe-mode\" && override.reason === \"ignores Caveman system settings\") {\n      throw new Error(\"Qwen safe mode ignores Caveman system settings\");\n    }\n    // These environment switches outrank settings in pinned Qwen 0.22.3.\n    // Keep side-request tools and workflow-spawned agents off in routed mode;\n    // corresponding system settings provide the durable second lock.\n    env.ENABLE_WEB_SEARCH = \"0\";\n    env.QWEN_CODE_DISABLE_WORKFLOWS = \"1\";\n  }\n  if (routeOverride) throw new Error(`${routeOverrideLabel(agent)} ${routeOverride.surface} ${routeOverride.reason}`);\n  const inj = agent.injection;\n  if (inj.method === \"env\") {\n    for (const [k, raw] of Object.entries(inj.env)) {\n      const val = renderTemplate(raw, renderedGw);\n      if (val !== \"\") env[k] = val;\n    }\n  } else if (inj.method === \"config-env-content\") {","sourceCodeStart":9340,"sourceCodeEnd":9376,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L9340-L9376","documentation":"While building the wrapped environment for the Qwen CLI, the wrapper consults a route-override table describing CLI surfaces Qwen handles unsafely under managed routing. If the user's arguments/config touch the 'effective settings' surface (Qwen would resolve settings in a way the wrapper cannot statically reason about), buildWrapEnv throws instead of producing an environment whose routing and settings could disagree. It is a fail-fast guard for the pinned Qwen version where env switches and settings interact non-obviously.","triggerScenarios":"Calling buildWrapEnv with the qwen agent profile when agentRouteOverride(agent, agentArgs) returns an override whose surface is \"effective settings\" — i.e. the supplied agent arguments or saved route config map Qwen's launch onto the settings-resolution surface (for example a settings/config-affecting flag combination registered as unsafe).","commonSituations":"Passing Qwen CLI flags that change which settings files are loaded while relying on Caveman-managed routing; upgrading the pinned Qwen version so route overrides no longer match; hand-edited agent route config entries that mark the effective-settings surface as overridden.","solutions":["Remove the Qwen argument/config combination that triggers the 'effective settings' route override — launch Qwen with default settings so the wrapper can compute its environment safely.","Inspect the route override table (agentRouteOverride) and update it for your Qwen version so the surface is no longer overridden, if you have verified the version behaves safely.","Run Qwen outside the managed wrap (direct gateway/direct provider credentials) if you need those settings-affecting flags."],"exampleFix":"// before\ncaveman agent qwen --settings-file ./custom.json   # override: 'effective settings'\n// after\ncaveman agent qwen                                  # default settings, wrapper resolves env safely","handlingStrategy":"validation","validationCode":"// Pre-check before launching qwen through the wrapper\nconst override = getRouteOverride(agent, agentArgs);\nif (override?.surface === \"effective settings\") {\n  throw new Error(\"Qwen launch would hit the 'effective settings' route override; remove settings-affecting flags.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  caveman.launch({ agent: \"qwen\", args });\n} catch (e) {\n  if (e instanceof Error && e.message === \"cannot safely resolve Qwen's effective settings\") {\n    console.error(\"Remove settings-affecting Qwen flags or run Qwen outside the managed wrap.\");\n  } else throw e;\n}","preventionTips":["Keep Qwen launched via Caveman on default settings files; manage overrides through Caveman config instead.","Pin the Qwen version the wrapper was tested against so route overrides stay accurate.","Review agent scripts for flags that alter settings resolution before routing them through the managed wrap."],"tags":["qwen","route-override","settings","managed-routing","fail-fast"],"backgroundTag":"conflicting-config-options","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"}