{"record":{"id":"249931afb13d1eec","repo":"JuliusBrussee/caveman","slug":"qwen-safe-mode-ignores-caveman-system-settings","errorCode":null,"errorMessage":"Qwen safe mode ignores Caveman system settings","messagePattern":"Qwen safe mode ignores Caveman system settings","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/cli/src/index.ts","lineNumber":9361,"sourceCode":"  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\") {\n    const cc = inj.config_content;\n    const content = wrapMode(gw) === \"managed\" && cc.managed !== undefined ? cc.managed : cc.local;\n    const renderOptions: RenderDeepOptions = agent.id === \"kilo\"","sourceCodeStart":9343,"sourceCodeEnd":9379,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L9343-L9379","documentation":"Qwen CLI's --safe-mode flag makes Qwen ignore external/system settings files, including the Caveman-injected system settings that provide the durable second lock for managed routing. Because safe mode would silently defeat those settings, the wrapper refuses to launch when it detects a route override on the --safe-mode surface with that reason. You can still use safe mode, just not combined with the routed wrap.","triggerScenarios":"Launching the qwen agent through the managed/routed wrapper while agentRouteOverride reports { surface: \"--safe-mode\", reason: \"ignores Caveman system settings\" } — i.e. the Qwen invocation includes --safe-mode (or an equivalent alias captured by the override table).","commonSituations":"Adding --safe-mode to a Qwen alias or script that is then launched via Caveman; organizational wrappers that always pass --safe-mode; trying to harden Qwen while simultaneously routing it through the managed gateway.","solutions":["Drop --safe-mode from the Qwen invocation; the wrapper already disables risky surfaces via ENABLE_WEB_SEARCH=0 and QWEN_CODE_DISABLE_WORKFLOWS=1 in routed mode.","Run Qwen directly (not through the Caveman managed wrap) if --safe-mode is required.","Keep the safety guarantee via the injected env switches and system settings rather than the Qwen flag."],"exampleFix":"// before\ncaveman agent qwen --safe-mode   # throws\n// after\ncaveman agent qwen               # ENABLE_WEB_SEARCH=0 and QWEN_CODE_DISABLE_WORKFLOWS=1 injected instead","handlingStrategy":"validation","validationCode":"const args = qwenArgs.filter(a => a !== \"--safe-mode\");\nif (args.length !== qwenArgs.length) {\n  console.warn(\"--safe-mode removed: incompatible with Caveman routed mode; env switches provide the safeguards.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  caveman.launch({ agent: \"qwen\", args });\n} catch (e) {\n  if (e instanceof Error && e.message === \"Qwen safe mode ignores Caveman system settings\") {\n    console.error(\"Drop --safe-mode or run Qwen directly without the Caveman wrap.\");\n  } else throw e;\n}","preventionTips":["Don't bake --safe-mode into aliases or scripts that are launched via Caveman routed mode.","Rely on the wrapper's injected env switches (ENABLE_WEB_SEARCH=0, QWEN_CODE_DISABLE_WORKFLOWS=1) for hardening.","If safe mode is mandatory, run Qwen outside the managed wrap entirely."],"tags":["qwen","safe-mode","settings","route-override","managed-routing"],"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"}