← Back to Pull requests

fix(cost-map): distinguish booleans from numbers in catalog pins #55068

Open
unknown opened this pull request with 649 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 29, 2026 11:09 UTC
Author

Handwritten 1-3 sentence description

[insert handwritten description here]

<details>
<summary>Details</summary>

TLDR

Problem this solves

  • The catalog guard accepts numbers as pinned booleans.
  • How it solves it

  • Compare booleans by identity, including inside objects and arrays.

  • Keep numeric equality and ignore JSON object key order.
  • User Flow

    Before — A catalog update can ship a pinned capability with the wrong JSON type.

    1. Set a field pinned to true to the number 1 in both catalog copies.
    2. Run the cost map guard on the proposed merge.
    3. The guard exits 0 because Python considers 1 and True equal.

    After — The guard catches the type change.

    1. Make the same catalog update and run the same check.
    2. The guard exits 1 and reports the model, field, and expected value.
    3. Keep the JSON boolean true and the check passes.

    Pre-Submission checklist

  • I have added meaningful tests

  • The handful of test files covering my change pass locally

  • My PR passes all required CI/CD checks

  • My PR's scope is as isolated as possible; it only solves 1 specific problem

  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review
  • Screenshots / Proof of Fix

    Ran the actual CI command with real Git commits in a temporary repository. It used the checked-in Fireworks MiniMax catalog entry and its vision pin. No provider request is needed because this changes how the CI guard compares decoded JSON values.

    <details>
    <summary>Reproduce both runs</summary>

    From the merge base with the PR applied to the working tree, save the script as /tmp/lite-catalog-pin-proof.py and run python3 /tmp/lite-catalog-pin-proof.py. It loads the guard from HEAD for the before run and from the working tree for the after run.

    import json
    import os
    import subprocess
    import sys
    import tempfile
    from pathlib import Path
    
    GUARD = Path("litellm/scripts/ci_cd/cost_map_guard.py")
    PINS = Path("litellm/scripts/ci_cd/cost_map_pins.json")
    CATALOG = Path("model_prices_and_context_window.json")
    MIRROR = Path("litellm/model_prices_and_context_window_backup.json")
    MODEL = "fireworks_ai/minimax-m3"
    
    def git(repo, *args):
        return subprocess.check_output(
            ["git", "-c", "user.name=Catalog test", "-c", "user.email=sample@example.invalid",
             "-c", "commit.gpgsign=false", *args], cwd=repo, text=True
        ).strip()
    
    def commit_catalog(repo, entry, message):
        data = json.dumps({MODEL: entry}, indent=2) + "\n"
        for file in (CATALOG, MIRROR):
            (repo / file).write_text(data)
        git(repo, "add", ".")
        git(repo, "commit", "-qm", message)
        return git(repo, "rev-parse", "HEAD")
    
    env = {key: value for key, value in os.environ.items() if not key.startswith("COST_MAP_GUARD_")}
    entry = json.loads(CATALOG.read_text())[MODEL]
    assert entry["supports_vision"] is True
    pin = json.loads(PINS.read_text())[MODEL]
    with tempfile.TemporaryDirectory() as directory:
        root = Path(directory)
        repo = root / "fixture"
        repo.mkdir()
        git(repo, "init", "-q")
        (repo / PINS).parent.mkdir(parents=True)
        (repo / PINS).write_text(json.dumps({MODEL: pin}) + "\n")
        base = commit_catalog(repo, entry, "base")
        heads = (
            ("true", commit_catalog(repo, {**entry, "description": "Catalog sample"}, "keep the boolean")),
            ("1", commit_catalog(repo, {**entry, "supports_vision": 1}, "use the wrong JSON type")),
        )
        before = root / "original.py"
        before.write_bytes(subprocess.check_output(["git", "show", f"HEAD:{GUARD}"]))
        for name, guard in (("upstream", before), ("patched", GUARD.resolve())):
            for value, head in heads:
                result = subprocess.run(
                    [sys.executable, str(guard), "--base", base, "--target", base,
                     "--head", head, "--head-ref", "catalog-update"],
                    cwd=repo, env=env, capture_output=True, text=True,
                )
                print(f"{name} supports_vision={value}: exit {result.returncode}")
                expected = int(name == "patched" and value == "1")
                assert result.returncode == expected, result.stdout + result.stderr
                if expected:
                    assert f"{MODEL}.supports_vision must stay true" in result.stdout
    

    </details>

    Before (6d8c2e009e512c0932b6577f0fa4dcbaff4528be)

    upstream supports_vision=true: exit 0
    upstream supports_vision=1: exit 0
    

    After (fd4cc0348aa499b1307464dbfa9f01ae6158ace9)

    patched supports_vision=true: exit 0
    patched supports_vision=1: exit 1
    

    The reproducer also checks that the rejection names the expected boolean. Four new regression cases failed against the old guard. All 91 cases in the guard's test file passed after the fix.

    $ uv run --no-project --with pytest==9.0.3 --with pytest-asyncio==1.3.0 pytest --noconftest -q tests/unit/test_cost_map_guard.py
    91 passed in 2.05s
    

    Type

    🐛 Bug Fix

    Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
  • </details>

    Diff: 649 lines (+486 / -163) across 8 files Reviewer: surlymochan Review duration: 3265m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 649 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #55068"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%