Skip to content

bug: _build_cheap_route() missing credential_pool key in runtime dict #7024

@kuishou68

Description

@kuishou68

Summary

SmartModelRouter._build_cheap_route() in agent/smart_model_routing.py constructs its runtime dict without the credential_pool key, while both _build_primary_route() branches include it.

Root Cause

In _build_cheap_route() (the cheap/fallback routing path), the return dict's runtime block is missing credential_pool:

# _build_cheap_route() — MISSING credential_pool
return {
    "model": route.get("model"),
    "runtime": {
        "api_key": runtime.get("api_key"),
        "base_url": runtime.get("base_url"),
        "provider": runtime.get("provider"),
        "api_mode": runtime.get("api_mode"),
        "command": runtime.get("command"),
        "args": list(runtime.get("args") or []),
        # credential_pool missing here!
    },
    ...
}

Both _build_primary_route() branches include it:

# _build_primary_route() — present
"credential_pool": primary.get("credential_pool"),

Impact

When the smart router selects the cheap route (e.g. for low-cost tasks), downstream code that reads result["runtime"]["credential_pool"] will receive None or raise a KeyError, causing credential rotation to fail silently or crash.

Fix

Add the missing key to _build_cheap_route()'s runtime dict:

"credential_pool": runtime.get("credential_pool"),

A PR is being submitted with this fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp/agentCore agent loop, run_agent.py, prompt builderstaleNo activity, may auto-closesweeper:implemented-on-mainSweeper: behavior already present on current main

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions