JuliusBrussee/caveman · error

Qwen routed profile is missing

Error message

Qwen routed profile is missing ${key}

What it means

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.

Solutions

  1. Add the missing key(s) to the Qwen routed profile: set "modelProviders" (whole object) and "providerProtocol".
  2. Regenerate the profile with the current CLI profile-creation flow instead of hand-editing, so both keys are populated.
  3. If you intended a non-Qwen agent, ensure the correct agent id is selected so the Qwen REPLACE path is not taken.
  4. Update the CLI if profiles were created by an older version with a different schema, then recreate the profile.

Example fix

// before (profile JSON)
{ "qwen": { "model": "qwen3-max" } }
// after
{ "qwen": { "model": "qwen3-max", "modelProviders": { "qwen": { "baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1", "model": "qwen3-max" } }, "providerProtocol": "openai" } }
Defensive patterns

Strategy: validation

Validate before calling

const overlay = profiles.qwen ?? {};
if (agent.id === "qwen" && (!("modelProviders" in overlay) || !("providerProtocol" in overlay))) {
  throw new Error("Qwen routed profile must define modelProviders and providerProtocol before wrapping");
}

Type guard

function isQwenOverlay(o: unknown): o is { modelProviders: Record<string, unknown>; providerProtocol: string } {
  return typeof o === "object" && o !== null
    && "modelProviders" in o && o.modelProviders !== null
    && "providerProtocol" in o && typeof (o as any).providerProtocol === "string";
}

Try / catch

try {
  await cli.run(["wrap", "--agent", "qwen"]);
} catch (e) {
  if (String((e as Error).message).includes("Qwen routed profile is missing")) {
    // recreate the profile via the CLI instead of hand-edited JSON
  }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/7f00687bf467f4c5. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/index.ts:9152

      // whenever native registration + journal + effective policy do not agree.
      const configured = jsonValueAt(baseConfig, ["mcp", "excluded"]);
      const preserved = Array.isArray(configured)
        ? configured.filter((item): item is string => typeof item === "string")
        : [];
      rawOverlay = deepMerge(rawOverlay, {
        mcp: { excluded: [...new Set([...preserved, "caveman"])] },
      });
    }
  }
  const overlay = (mcpMode === "auto" ? rawOverlay : withoutCavemanMcpServer(rawOverlay as JsonObject)) as JsonObject;
  const merged = deepMerge(baseConfig, overlay) as JsonObject;
  if (agent.id === "qwen") {
    // Qwen treats these as whole-object REPLACE settings. Our generic merge is
    // intentionally conservative for other agents, but retaining a sibling
    // provider here would make it selectable at runtime outside /w/qwen.
    for (const key of ["modelProviders", "providerProtocol"] as const) {
      const value = overlay[key];
      if (value === undefined) throw new Error(`Qwen routed profile is missing ${key}`);
      merged[key] = cloneJsonValue(value);
    }
  }
  const rendered = JSON.stringify(merged, null, 2);
  if (rendered === undefined) throw new Error("merged config is not JSON");
  const outDir = mkdtempSync(join(tmpdir(), "caveman-wrap-"));
  const outPath = join(outDir, `${agent.id}.json`);
  writeFileSync(outPath, rendered + "\n", { mode: 0o600 });
  wrapTempDirs.add(outDir);
  env[inj.env_var] = outPath;
}

function cleanupWrapTempDirs() {
  for (const dir of [...wrapTempDirs]) {
    try {
      rmSync(dir, { recursive: true, force: true });
    } catch {
      // Temp cleanup is best-effort; wrap must never fail after child exit.

View on GitHub (pinned to 3ee70a1026)