chore(typing): auto-tighten the basedpyright budget nightly - #34983
chore(typing): auto-tighten the basedpyright budget nightly#34983mateo-berri wants to merge 1 commit into
Conversation
Add a --tighten mode to scripts/type_check_gate.py that lowers each rule's limit in basedpyright-code-budget.json to its current head count plus 50 slack. Limits never rise, absent rules are not adopted, and the vacuous-run guard refuses to tighten when basedpyright emitted nothing. A scheduled workflow runs it nightly against litellm_internal_staging and opens a PR only when there is headroom to remove. Includes the first tighten: 63,290 errors of stale headroom removed across 23 of 48 rules; the reportAny limit falls 34,906 -> 24,479 and reportExplicitAny 10,230 -> 7,334, so growth under the old ceilings can no longer hide. The delta-vs-base gate still spares any PR that does not push a rule past both its limit and its merge-base count
| env: | ||
| NODE_OPTIONS: --max-old-space-size=12288 | ||
| run: | | ||
| (uv run --no-sync basedpyright --outputjson || true) | uv run --no-sync python scripts/type_check_gate.py --tighten |
There was a problem hiding this comment.
Checker failures lose their status
When basedpyright terminates after emitting valid but incomplete nonempty JSON, || true discards the failure status and --tighten treats the partial diagnostics as a complete measurement. Missing rules are then counted as zero and lowered toward the slack floor, producing an invalid budget PR that can make subsequent type-check jobs fail.
| exit 0 | ||
| fi | ||
| BRANCH_NAME="litellm_tighten_basedpyright_budget_$(date +'%m_%d_%Y')" | ||
| if git ls-remote --exit-code --heads origin "$BRANCH_NAME" > /dev/null; then |
There was a problem hiding this comment.
Greptile SummaryThis PR automates tightening the repository's basedpyright error budget.
Confidence Score: 4/5The PR is safe to merge with non-blocking robustness issues in the nightly workflow's checker-failure and concurrent-run handling. The tightening logic preserves normal gate behavior, but the workflow accepts nonempty incomplete checker output and concurrent same-day runs can race while creating the shared date-derived branch. Files Needing Attention: .github/workflows/nightly_tighten_basedpyright_budget.yml, scripts/type_check_gate.py
|
| Filename | Overview |
|---|---|
| .github/workflows/nightly_tighten_basedpyright_budget.yml | Adds the scheduled measurement and PR workflow, but suppresses checker failure statuses and uses a race-prone check-before-push sequence. |
| scripts/type_check_gate.py | Adds monotonic budget-tightening logic and an empty-run guard, though the guard cannot distinguish nonempty partial results from a complete run. |
| tests/test_litellm/test_type_check_gate.py | Adds focused tests for tightening behavior and confirms that an entirely empty run leaves the budget untouched. |
| basedpyright-code-budget.json | Lowers 23 existing rule limits without changing the budget schema. |
Reviews (1): Last reviewed commit: "chore(typing): auto-tighten the basedpyr..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
TLDR
Problem this solves:
How it solves it:
Friction stays where it was: the gate's delta-vs-base check spares any PR whose rule count does not exceed its merge-base count, so a PR that merely inherits drift can never go red from a tighten. Only a PR that pushes a rule past both its limit and its own base fails, and the 50 slack per rule is the shared allowance for net new errors between tightens
Relevant issues
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
The tighten run that produced the budget change in this PR:
The guard rails, exercised against the real CLI:
Type
🚄 Infrastructure
Changes
scripts/type_check_gate.py gains tightened_budget() and cmd_tighten(), wired to a new --tighten flag that is mutually exclusive with --update and takes --slack (default 50). tightened_budget sets each budgeted rule's limit to min(existing limit, current count + slack), so a limit only ever falls and a rule that already sits close to its count keeps its limit. cmd_tighten reuses the existing vacuous-run guard so a crashed or empty basedpyright pass can never collapse every limit to the slack floor
.github/workflows/nightly_tighten_basedpyright_budget.yml checks out litellm_internal_staging on a nightly schedule (07:47 UTC, plus workflow_dispatch), installs the same environment the lint workflow uses, pipes a whole-tree basedpyright run into the tighten, and opens a PR against litellm_internal_staging only when basedpyright-code-budget.json changed. Branch names are date-suffixed and the job skips if the day's branch already exists. Note the schedule only fires from the workflow definition on the default branch; until it propagates there, it can be exercised with workflow_dispatch from a branch that contains it
basedpyright-code-budget.json carries the first tighten so the ceilings match the tree as of this branch instead of waiting for the first scheduled run
tests/test_litellm/test_type_check_gate.py adds six tests covering the tighten: headroom collapse to current plus slack, never raising a limit, flooring a cleared rule at the slack, not adopting rules outside the budget, writing only lowered limits through the CLI entry point, and refusing a vacuous run while leaving the budget file untouched
QA runbook
uv run --no-sync pytest tests/test_litellm/test_type_check_gate.py -qand expect all tests to passecho '{}' | uv run --no-sync python scripts/type_check_gate.py --tightenand expect a refusal with exit 1 and an unchanged basedpyright-code-budget.json(NODE_OPTIONS=--max-old-space-size=8192 uv run --no-sync basedpyright --outputjson || true) | uv run --no-sync python scripts/type_check_gate.py --tightenand expectgit diff basedpyright-code-budget.jsonto show only equal-or-lower limitsFinal Attestation