{"record":{"id":"d32822eb54a1288a","repo":"JuliusBrussee/caveman","slug":"routeoverridelabel-agent-routeoverride-surfa","errorCode":null,"errorMessage":"${routeOverrideLabel(agent)} ${routeOverride.surface} ${routeOverride.reason}","messagePattern":"\\$\\{routeOverrideLabel\\(agent\\)\\} \\$\\{routeOverride\\.surface\\} \\$\\{routeOverride\\.reason\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":9369,"sourceCode":"  }\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\"\n      ? { optionalOpenAIKeyReference: \"{env:OPENAI_API_KEY}\" }\n      : {};\n    let rendered = renderDeep(content, renderedGw, env, renderOptions);\n    if (agent.id === \"kilo\" && mcpMode === \"auto\") {\n      const ownedMcp = ownedMcpRegistration(agent.id, agentArgs);\n      if (ownedMcp) {\n        // Project exact owned registration into Kilo's highest user-controlled\n        // layer. Route preflight rejects active org/managed sources that load","sourceCodeStart":9351,"sourceCodeEnd":9387,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L9351-L9387","documentation":"This is the generic guard at the end of the Qwen/others route-override handling in buildWrapEnv: after any agent-specific special cases, if agentRouteOverride(agent, agentArgs) still returns an override, the wrapper throws an error composed of the agent label, the CLI surface, and the reason the surface is unsafe. It exists so that any CLI surface known to break the 'what we inject' vs 'what we tell the proxy' consistency fails loudly instead of launching a mis-routed agent.","triggerScenarios":"Calling buildWrapEnv (or the CLI agent-launch path) with arguments that match any entry in the route-override table for the selected agent — the thrown message interpolates routeOverrideLabel(agent), routeOverride.surface and routeOverride.reason, e.g. \"Qwen --openai-api-key bypasses managed routing\" style combinations.","commonSituations":"Passing provider/API-key flags directly to a wrapped agent so it can bypass the gateway; using a CLI flag combination registered as unsafe for your agent; a new agent release adding flags that the override table maps to an existing unsafe surface.","solutions":["Read the interpolated message: remove the named surface (flag/config) from the agent invocation so agentRouteOverride returns undefined.","Move the credential/behavior the flag was providing into the Caveman-managed configuration (env injection, gateway headers) instead of raw agent flags.","If the override entry is stale for your pinned agent version, update the override table after verifying the surface is safe."],"exampleFix":"// before\ncaveman agent qwen --openai-api-key sk-...   # raw key flag conflicts with managed routing\n// after\ncaveman agent qwen                            # credentials provided via Caveman-managed env/headers","handlingStrategy":"try-catch","validationCode":"// Check the override table yourself before launching\nconst override = getRouteOverride(agent, agentArgs);\nif (override) {\n  console.warn(`Blocked surface for ${agent.id}: ${override.surface} — ${override.reason}`);\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"try {\n  caveman.launch({ agent, args });\n} catch (e) {\n  if (e instanceof Error && /route override|unsafe surface/i.test(e.message)) {\n    // message format: \"<AgentLabel> <surface> <reason>\"\n    console.error(`Remove the flagged CLI surface from the invocation: ${e.message}`);\n  } else throw e;\n}","preventionTips":["Parse the interpolated error message (label/surface/reason) to identify exactly which flag to remove.","Provide agent credentials via Caveman-managed env/headers instead of raw CLI flags.","Keep the route-override table in sync when upgrading pinned agent versions."],"tags":["route-override","agent-launch","cli-flags","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"}