Skip to content

chore(lint): bring ANN202 and BLE001 back under the strict-rule budget - #40444

Merged
mateo-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_annotate_strict_budget_helpers
Sep 9, 2026
Merged

mateo-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_annotate_strict_budget_helpers

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • The strict-rule lint gate fails on the staging to main promote PR
  • Three new nested helpers had no return type, which put ANN202 at 831 over its 829 ceiling in the first red run
  • Four new bare except Exception blocks push BLE001 over its ceiling
  • Promote PR chore(ci): promote internal staging to main #40307 merged with that red job, and today's merge base still fails the gate, now on BLE001 (2915 over 2914)

How it solves it:

  • Adds the return type to dispatch_async, transform_then_dispatch, and _send_batch
  • Marks the four broad catches with the repo's # noqa: BLE001 # <reason> convention
  • ANN202 drops from 828 to 825 and BLE001 from 2915 to 2911, both under their limits
  • No budget json edit on this branch: the limits stay at 829 and 2914 until the daily tech-debt PR ratchets them down
  • Supersedes chore(lint): annotate new private helpers so ANN202 total stays under its ratchet #40328, which annotated the same three helpers with coarser types

User Flow

Before: the engineer promoting staging to main sees the lint job fail on the promote PR and merges it red

  1. The engineer opens the weekly promote PR from litellm_internal_staging to main at main...litellm_internal_staging
  2. GitHub runs the checks and the "LiteLLM Linting" job goes red
  3. The job log at https://github.com/BerriAI/litellm/actions/runs/34301028931 ends in FAIL: strict-rule totals exceed their limit naming ANN202 over its ceiling
  4. Every later promote PR shows the same red job, and the engineer merges around it

After: the engineer promoting staging to main sees the lint job pass on the promote PR

  1. The engineer opens the weekly promote PR from litellm_internal_staging to main at main...litellm_internal_staging
  2. GitHub runs the checks and the "LiteLLM Linting" job goes green
  3. The job log ends in OK: every strict rule is within its codebase ceiling
  4. The engineer merges the promote PR with every required check green

Relevant issues

Supersedes #40328

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Both runs use the same commands from a bootstrapped worktree. The gate is the exact command the "LiteLLM Linting" job runs on a promote PR, with origin/main as the base, and the count comes from the strict config over litellm/

Before (096984b, merge base on litellm_internal_staging)

Strict gate against main

  1. python scripts/ruff_strict_gate.py --base origin/main
  2. Observed:
    FAIL: strict-rule totals exceed their limit (base origin/main):
      BLE001: total 2915 over limit 2914 (this change added 2)
        litellm/litellm_core_utils/get_model_cost_map.py:588
        litellm/litellm_core_utils/llm_cost_calc/utils.py:1447
        litellm/proxy/_experimental/mcp_server/server.py:1056
        litellm/proxy/management_endpoints/cost_tracking_settings.py:646
    Reduce the new violations or remove an equal number elsewhere; the ceiling is the limit in ruff-strict-budget.json.
    
    exit 1

ANN202 on the three helpers

  1. ruff check --config ruff-strict.toml --select ANN202 --output-format concise litellm/llms/custom_httpx/llm_http_handler.py litellm/integrations/azure_sentinel/azure_sentinel.py
  2. Observed (the two older hits are pre-existing and budgeted):
    litellm/integrations/azure_sentinel/azure_sentinel.py:421:19: ANN202 Missing return type annotation for private function `_send_batch`
    litellm/llms/custom_httpx/llm_http_handler.py:578:13: ANN202 Missing return type annotation for private function `dispatch_async`
    litellm/llms/custom_httpx/llm_http_handler.py:629:23: ANN202 Missing return type annotation for private function `transform_then_dispatch`
    litellm/llms/custom_httpx/llm_http_handler.py:5994:9: ANN202 Missing return type annotation for private function `_handle_error`
    litellm/llms/custom_httpx/llm_http_handler.py:6551:23: ANN202 Missing return type annotation for private function `_backend_connection`
    Found 5 errors.
    

Strict totals over litellm/

  1. ruff check litellm --config ruff-strict.toml --output-format json --exit-zero | python3 -c "import json,sys,collections; c=collections.Counter(i['code'] for i in json.load(sys.stdin)); print('ANN202', c['ANN202'], 'BLE001', c['BLE001'])"
  2. Observed: ANN202 828 BLE001 2915 (limits 829 and 2914)

After (8bb6d8c, PR tip)

Strict gate against main

  1. python scripts/ruff_strict_gate.py --base origin/main
  2. Observed:
    OK: every strict rule is within its codebase ceiling (base origin/main)
    
    exit 0, and the same command with --base origin/litellm_internal_staging prints OK too

ANN202 on the three helpers

  1. ruff check --config ruff-strict.toml --select ANN202 --output-format concise litellm/llms/custom_httpx/llm_http_handler.py litellm/integrations/azure_sentinel/azure_sentinel.py
  2. Observed: only the two pre-existing hits remain (_handle_error at 5994 and _backend_connection at 6551); _send_batch, dispatch_async, and transform_then_dispatch are gone
    Found 2 errors.
    

Strict totals over litellm/

  1. same count command as Before
  2. Observed: ANN202 825 BLE001 2911 (limits 829 and 2914)

make check at the tip: check: PASS (Python lint, LIT and TQ budgets, basedpyright budget, ruff format, dashboard API-type sync)

Type

🧹 Refactoring
🚄 Infrastructure

Caveats (if any)

Medium

Low

  • osv-scan and codecov/patch are red on the tip, neither required, neither caused here
    • osv-scan is GHSA-7w5x-hrqm-74c2 (smol-toml 1.6.1 in the dashboard lockfile), published 2026-09-09 18:07Z after the sibling PRs' green scans; codecov/patch is 16.67 percent because the touched lines are except bodies
  • The four new # noqa: BLE001 lines count as fresh debt for the daily tech-debt automation
    • Its prompt counts every new # noqa in the last 24 hours, so the next rolling litellm_techdebt_ PR may try to remove them
  • The gate against main was run locally, not by the promote PR's own lint job
    • The PR's lint job uses staging as the base; the same command with --base origin/main passes from a worktree at the tip and after a merge preview onto the current staging tip, and the next promote PR is the real check
  • The four new # noqa: BLE001 lines can go stale without RUF100 noticing
    • ruff-strict.toml selects BLE but also lists BLE001 under external, so an unused BLE001 noqa is never flagged; pre-existing config issue, not changed here

Open in Devin Desktop: https://app.devin.ai/desktop/session/1d398e0db179497bb299d81c219f756b?variant=devin
Requested by: @mateo-berri


Note

Low Risk
Lint and type-annotation only; broad exception handling is unchanged aside from documented noqa comments.

Overview
Brings the strict ruff gate back under budget so staging→main promote PRs pass LiteLLM Linting again. No intended runtime behavior change.

ANN202: Adds return types on three nested helpers—Azure Sentinel _send_batch (httpx.Response, plus httpx import), and in llm_http_handler dispatch_async (Coroutine[..., ModelResponse | CustomStreamWrapper]) and transform_then_dispatch (ModelResponse | CustomStreamWrapper).

BLE001: Documents four intentional broad except Exception handlers with # noqa: BLE001 and short reasons: background model cost map retry, unmapped model in get_billed_token_rates, MCP proxy failure-hook logging, and cost-tracking completion_cost → HTTP 404 mapping.

Reviewed by Cursor Bugbot for commit 8bb6d8c. Bugbot is set up for automated code reviews on this repo. Configure here.

Annotate the return types of dispatch_async and transform_then_dispatch in llm_http_handler and _send_batch in azure_sentinel, and mark four legitimate broad catches with the repo's noqa convention, so the promote PR's lint job passes the strict gate again. Supersedes #40328.
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@codspeed

codspeed Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_annotate_strict_budget_helpers (8bb6d8c) with litellm_internal_staging (096984b)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR restores the strict lint gate to budget without changing runtime behavior

  • Adds precise return annotations to three nested asynchronous helpers
  • Adds reasoned BLE001 suppressions to four existing broad exception handlers
  • Adds the required httpx import for the Azure Sentinel callback annotation
  • Does not modify lint budget files

Confidence Score: 5/5

The PR appears safe to merge because its annotations match runtime contracts and its suppressions follow the strict-lint convention

No actionable failures remain; the changes affect static linting only, and the added import, return types, and suppression syntax are compatible with their surrounding contracts

Important Files Changed

Filename Overview
litellm/integrations/azure_sentinel/azure_sentinel.py Adds an accurate httpx.Response return annotation to the batch callback
litellm/llms/custom_httpx/llm_http_handler.py Adds return annotations matching the asynchronous dispatch helpers and their callers
litellm/litellm_core_utils/get_model_cost_map.py Documents and suppresses the intentional broad catch in background retry handling
litellm/litellm_core_utils/llm_cost_calc/utils.py Documents and suppresses the existing unmapped-model fallback catch
litellm/proxy/_experimental/mcp_server/server.py Documents and suppresses the existing failure-hook isolation catch
litellm/proxy/management_endpoints/cost_tracking_settings.py Documents and suppresses the existing unpriceable-model exception mapping

Reviews (1): Last reviewed commit: "chore(lint): bring ANN202 and BLE001 bac..." | Re-trigger Greptile

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Devin e2e QA

Tested at: 8bb6d8c
Session: https://app.devin.ai/sessions/1d398e0db179497bb299d81c219f756b

No-regression check for a lint-only change: the same real proxy boot and the same two real Anthropic calls (claude-haiku-4-5, real spend) at the merge base and at the PR tip. Both sides return HTTP 200 with the same content; the annotated dispatch_async and transform_then_dispatch helpers in the shared HTTP handler are on the path of both calls.

Before (096984b)

Boot a real proxy from this commit on a random free port

  1. git checkout --detach 096984bfc2f146e6e4bb6c259e8daab885a5e5f6; pick a random free port with socket.bind on 127.0.0.1 and confirm with ss -ltn "sport = :59859" (0 listeners)
  2. uv run --no-sync litellm --config /tmp/qa_config.yaml --port 59859 where the config routes claude-haiku to anthropic/claude-haiku-4-5 with api_key: os.environ/ANTHROPIC_API_KEY and master_key: sk-qa-1234
  3. curl -s -w ' HTTP %{http_code}' http://127.0.0.1:59859/health/liveliness
  4. Observed: "I'm alive!" HTTP 200

Non-streaming POST /v1/chat/completions (Anthropic, shared HTTP handler)

  1. curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:59859/v1/chat/completions -H 'Authorization: Bearer sk-qa-1234' -H 'Content-Type: application/json' -d '{"model":"claude-haiku","messages":[{"role":"user","content":"Reply with exactly: pong"}],"max_tokens":20}'
  2. Observed:
    {"id":"chatcmpl-fa7fa8fa-4e50-4a7d-bc2a-ee7f8bbddd3e","created":1788982807,"model":"claude-haiku","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"pong","role":"assistant","provider_specific_fields":{"citations":null,"thinking_blocks":null}}}],"usage":{"completion_tokens":5,"prompt_tokens":13,"total_tokens":18,"completion_tokens_details":{"reasoning_tokens":0,"text_tokens":5},"prompt_tokens_details":{"cached_tokens":0,"text_tokens":13,"cache_write_tokens":0,"cache_creation_tokens":0,"cache_creation_token_details":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0}},"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"inference_geo":"not_available","service_tier":"standard"}}
    HTTP 200
    

Streaming POST /v1/chat/completions (Anthropic, shared HTTP handler)

  1. curl -sN -w '\nHTTP %{http_code}' http://127.0.0.1:59859/v1/chat/completions -H 'Authorization: Bearer sk-qa-1234' -H 'Content-Type: application/json' -d '{"model":"claude-haiku","messages":[{"role":"user","content":"Count from 1 to 5, separated by spaces."}],"max_tokens":30,"stream":true}'
  2. Observed:
    data: {"id":"chatcmpl-3489aba6-ba87-4bfc-880c-4ba84e4237f0","object":"chat.completion.chunk","created":1788982807,"model":"claude-haiku","choices":[{"index":0,"delta":{"role":"assistant","content":"1 2 "}}]}
    
    data: {"id":"chatcmpl-3489aba6-ba87-4bfc-880c-4ba84e4237f0","object":"chat.completion.chunk","created":1788982807,"model":"claude-haiku","choices":[{"index":0,"delta":{"content":"3 4 "}}]}
    
    data: {"id":"chatcmpl-3489aba6-ba87-4bfc-880c-4ba84e4237f0","object":"chat.completion.chunk","created":1788982807,"model":"claude-haiku","choices":[{"index":0,"delta":{"content":"5"}}]}
    
    data: {"id":"chatcmpl-3489aba6-ba87-4bfc-880c-4ba84e4237f0","object":"chat.completion.chunk","created":1788982807,"model":"claude-haiku","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
    
    data: [DONE]
    
    
    HTTP 200
    

After (8bb6d8c)

Boot a real proxy from this commit on a random free port

  1. git checkout --detach 8bb6d8c120e2c116a719495ecf2401a2bab9dd5a; pick a random free port with socket.bind on 127.0.0.1 and confirm with ss -ltn "sport = :59274" (0 listeners)
  2. uv run --no-sync litellm --config /tmp/qa_config.yaml --port 59274 where the config routes claude-haiku to anthropic/claude-haiku-4-5 with api_key: os.environ/ANTHROPIC_API_KEY and master_key: sk-qa-1234
  3. curl -s -w ' HTTP %{http_code}' http://127.0.0.1:59274/health/liveliness
  4. Observed: "I'm alive!" HTTP 200

Non-streaming POST /v1/chat/completions (Anthropic, shared HTTP handler)

  1. curl -s -w '\nHTTP %{http_code}' http://127.0.0.1:59274/v1/chat/completions -H 'Authorization: Bearer sk-qa-1234' -H 'Content-Type: application/json' -d '{"model":"claude-haiku","messages":[{"role":"user","content":"Reply with exactly: pong"}],"max_tokens":20}'
  2. Observed:
    {"id":"chatcmpl-babee4ae-0ccb-43e0-a5f7-1f6054504e0e","created":1788982831,"model":"claude-haiku","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"pong","role":"assistant","provider_specific_fields":{"citations":null,"thinking_blocks":null}}}],"usage":{"completion_tokens":5,"prompt_tokens":13,"total_tokens":18,"completion_tokens_details":{"reasoning_tokens":0,"text_tokens":5},"prompt_tokens_details":{"cached_tokens":0,"text_tokens":13,"cache_write_tokens":0,"cache_creation_tokens":0,"cache_creation_token_details":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0}},"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"inference_geo":"not_available","service_tier":"standard"}}
    HTTP 200
    

Streaming POST /v1/chat/completions (Anthropic, shared HTTP handler)

  1. curl -sN -w '\nHTTP %{http_code}' http://127.0.0.1:59274/v1/chat/completions -H 'Authorization: Bearer sk-qa-1234' -H 'Content-Type: application/json' -d '{"model":"claude-haiku","messages":[{"role":"user","content":"Count from 1 to 5, separated by spaces."}],"max_tokens":30,"stream":true}'
  2. Observed:
    data: {"id":"chatcmpl-ce22ead6-edb1-4a87-8d18-c13919899421","object":"chat.completion.chunk","created":1788982831,"model":"claude-haiku","choices":[{"index":0,"delta":{"role":"assistant","content":"1 2 "}}]}
    
    data: {"id":"chatcmpl-ce22ead6-edb1-4a87-8d18-c13919899421","object":"chat.completion.chunk","created":1788982831,"model":"claude-haiku","choices":[{"index":0,"delta":{"content":"3 4 "}}]}
    
    data: {"id":"chatcmpl-ce22ead6-edb1-4a87-8d18-c13919899421","object":"chat.completion.chunk","created":1788982831,"model":"claude-haiku","choices":[{"index":0,"delta":{"content":"5"}}]}
    
    data: {"id":"chatcmpl-ce22ead6-edb1-4a87-8d18-c13919899421","object":"chat.completion.chunk","created":1788982831,"model":"claude-haiku","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
    
    data: [DONE]
    
    
    HTTP 200
    

@codecov

codecov Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/litellm_core_utils/get_model_cost_map.py 0.00% 1 Missing ⚠️
litellm/proxy/_experimental/mcp_server/server.py 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 8bb6d8c. Configure here.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mateo-berri
mateo-berri merged commit f529d6d into litellm_internal_staging Sep 9, 2026
131 of 133 checks passed
@mateo-berri
mateo-berri deleted the litellm_annotate_strict_budget_helpers branch September 9, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant