Skip to content

ci(unit): stop the full history clone on the db-and-spend shard, fetch the schema merge base by sha - #50120

Merged
kerry-berri merged 4 commits into
mainfrom
litellm_db_and_spend_shallow_checkout
Nov 4, 2026
Merged

kerry-berri merged 4 commits into
mainfrom
litellm_db_and_spend_shallow_checkout

Conversation

@kerry-berri

@kerry-berri kerry-berri commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

The db-and-spend unit shard was the only one cloning the whole repo (2.8 GB of git objects) and it kept dying at checkout after 10 minutes before a single test ran. The full clone existed only so the schema compatibility script could find the merge base, so the job now asks GitHub for that sha, fetches that one commit, and clones one commit like every other shard

Details

TLDR

Problem this solves:

  • db-and-spend clones full history, median 108 s, p99 371 s, 10 minute cap
  • When GitHub is slow the clone hits the cap and the shard fails with no test run
  • 12 of 32 main runs failed that way on 2026-11-03

How it solves it:

  • Checkout is fetch-depth: 1 with the 3 minute cap, same as the other shards
  • New step Check schema.prisma against the merge base, PR events on db-and-spend only, 3 minute cap
  • Merge base comes from the compare API, then git fetch --depth=1 origin <sha>
  • Base branch falls back to the PR's current base when the event's branch is gone, as ui-unit does
  • check_schema_compatibility.py gains --base-commit <sha> next to --base-ref
  • The step is registered in test_lint_workflow_diff_gates.py, which runs it against a fake upstream
  • Install dependencies cap goes from 8 to 5 minutes so the setup ceiling check_workflow_startup_safety.py sums stays at 35. That step took 33 s at most over the last 246 main jobs, median 12 s
  • Pushes to main no longer run the check (it compared HEAD to itself before)

User Flow

Before: a contributor's PR goes red on unit / db-and-spend without any test output

  1. They push a commit that touches nothing near the database
  2. https://github.com/BerriAI/litellm/actions shows unit / db-and-spend red after 10 minutes
  3. The log ends inside actions/checkout with the step timed out, no pytest output anywhere
  4. They re-run the job and wait another 3 to 10 minutes for the clone

After: the same shard checks out in seconds and only fails on a real test or schema break

  1. They push the same commit
  2. unit / db-and-spend checks out one commit in under 30 s like the other shards
  3. The schema step prints Schema compatibility passed against merge base <sha> and the 7 test files run
  4. A dropped column in schema.prisma still fails the step with Breaking: Field <Model>.<field> was removed

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/unit/<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
  • 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

E2E exception at 0e2a676. Scope is one workflow step, the argument parsing of one CI script and one consumer entry in the workflow test, no proxy code changes, so the proof is the exact commands the job now runs, in a real one-commit clone, plus the job itself on this PR

Dry run in a fresh git clone --depth=1 of this branch (git rev-list --count HEAD prints 1), using the head of #50118 as the PR head

  1. gh api repos/BerriAI/litellm/compare/main...ff624cdd2b --jq .merge_base_commit.sha -> 1967b41368833ea4c9a150a74e4c71df7246060d
  2. git merge-base HEAD 1967b413... in that clone -> fatal: Not a valid commit name, which is why the old --base-ref path cannot work without history
  3. git fetch --no-tags --depth=1 origin 1967b413... -> 11 s
  4. python scripts/check_schema_compatibility.py --base-commit 1967b413... -> Schema compatibility passed against merge base 1967b413..., exit 0
  5. Mutation: delete budget_duration from LiteLLM_BudgetTable in schema.prisma, run step 4 again -> Breaking: Field LiteLLM_BudgetTable.budget_duration was removed, exit 1

The unit / db-and-spend job on this PR at e7eac43 (job 126899653336): checkout 4 s, install plus schema step 10 s with Schema compatibility passed against merge base 9703e01c... in the log, tests 154 s, green. Before this PR the same checkout was 108 s at the median and up to 461 s

tests/unit/test_lint_workflow_diff_gates.py discovers every workflow step that reads merge_base_commit and runs it against a fake upstream, including a rerun after the base branch was deleted, renamed, or retargeted. Without the consumer entry the six new cases fail with KeyError: 'test-unit.yml:unit', with it 113 passed in 13.69s together with test_unit_shard_per_test_timeout.py and test_assert_ci_coverage.py. tests/code_coverage_tests/check_workflow_startup_safety.py prints Workflow startup invariants hold (setup ceiling 35m)

In the full checkout, --base-ref origin/main still works unchanged, running with neither flag exits with one of the arguments --base-ref --base-commit is required. ruff check, ruff format --check and basedpyright are clean on the script (the old options.base_ref read was a reportAny, the new typed mapping removes it)

Type

🚄 Infrastructure

Caveats (if any)

Low

  • The compare base is now the PR's base branch, not always main. Identical for PRs into main, more accurate for PRs into stable/**, rc/** and lts/**
  • Pushes to main and workflow_dispatch runs skip the step instead of diffing the schema against itself
  • The step calls api.github.com with github.token, the same calls the UI unit test step already makes
  • main() of the script shells out to git, so its --base-commit path is covered by the workflow test with a recorded uv argv, not by a unit test of the function
  • A cold uv cache now has 5 minutes instead of 8 for uv sync. The worst observed over 246 recent main jobs was 33 s

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

Link to Devin session: https://app.devin.ai/sessions/a353beb13ddd45f79cf8333fdbc421ad
Open in Devin Desktop: https://app.devin.ai/desktop/session/a353beb13ddd45f79cf8333fdbc421ad?variant=devin
Requested by: @kerry-berri


Note

Low Risk
CI-only changes to checkout depth and how the Prisma schema gate obtains its base commit; runtime product behavior is unchanged.

Overview
Fixes db-and-spend unit CI failing on checkout timeouts by dropping the full-repo clone that existed only to resolve a merge base for schema.prisma checks.

Workflow (test-unit.yml): All unit shards now use fetch-depth: 1 and a 3-minute checkout timeout (no special 10-minute / full-history path for db-and-spend). Schema validation moves out of the install step into Check schema.prisma against the merge base, which runs only on pull requests for the db-and-spend shard. That step resolves the merge base via the GitHub compare API, git fetch --depth=1 that SHA, then runs the compatibility script with --base-commit. Pushes to main no longer run this check.

scripts/check_schema_compatibility.py: Adds --base-commit (direct SHA, shallow-clone friendly) as an alternative to --base-ref (still uses git merge-base when history exists).

Tests: Registers test-unit.yml:unit in test_lint_workflow_diff_gates.py so merge-base workflow steps stay covered against a fake upstream.

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

@kerry-berri
kerry-berri requested a review from a team November 4, 2026 22:09
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@kerry-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Low impact] The changes affect one unit-test shard's checkout and schema-check steps.

The two outstanding repository test requirements must be addressed before merging

Findings

  1. P2 Required regression tests are missing ▶
  2. P2 Unit tests start Git ▶

Summary

The PR replaces the full-history checkout on db-and-spend with a shallow checkout and fetches the schema comparison commit by SHA

  • The db-and-spend shard checks schema with a shallow checkout.

Reviews (3) · Last reviewed commit: "ci(unit): keep the setup ceiling at 35 m..." · Reviewed by Greptile

Comment thread .github/workflows/test-unit.yml Resolved
Comment thread .github/workflows/test-unit.yml Resolved
Comment on lines +63 to +68
source: Final = parser.add_mutually_exclusive_group(required=True)
source.add_argument("--base-ref", help="compare against the merge base of HEAD and this ref (needs history)")
source.add_argument("--base-commit", help="compare against this commit as is (works in a shallow clone)")
options: Final = TypeAdapter(dict[str, str | None]).validate_python(vars(parser.parse_args()))
base_commit: Final = options["base_commit"]
base: Final = base_commit if base_commit else _merge_base(options["base_ref"] or "")

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.

P2 Required regression tests are missing

AGENTS.md requires regression tests before merging. Existing tests bypass main. Test that --base-commit works without history and rejects a removed field

Context Used: AGENTS.md (source)

@codecov

codecov Bot commented Nov 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…llback and register it with the merge-base step test
@kerry-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

def _schema_base_commit_and_its_type_in_the_checkout(run: StepRun) -> tuple[str, str]:
argv: Final = _argv_recorded(run.runner, "uv")
base_commit: Final = argv[argv.index("--base-commit") + 1]
return base_commit, _git(run.runner.checkout, "cat-file", "-t", base_commit).strip()

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.

P2 Unit tests start Git

This consumer runs Git through _git, violating tests/unit/AGENTS.md's no-subprocess rule. Move this check outside tests/unit before merging

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@kerry-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@kerry-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@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 0e2a676. Configure here.

@kerry-berri
kerry-berri enabled auto-merge (squash) November 4, 2026 22:37
@kerry-berri
kerry-berri merged commit d29c515 into main Nov 4, 2026
89 of 92 checks passed
@kerry-berri
kerry-berri deleted the litellm_db_and_spend_shallow_checkout branch November 4, 2026 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants