Repository navigation
test(unit): make bedrock collector and secret scan timing tests deterministic - #42405
Conversation
…ministic Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
bugbot run |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…et scan scaling test Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
…profiler and tighten the scaling bound Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
There was a problem hiding this comment.
✅ 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 84fc8ca. Configure here.
|
Review for PR #42405: Make bedrock collector and secret scan timing tests deterministic Test Determinism & Flakiness Remediation
# Deterministic assertion pattern for collector telemetry flushes
def test_bedrock_telemetry_flush(mock_bedrock_client):
flush_event = threading.Event()
collector = BedrockTelemetryCollector(on_flush_callback=lambda: flush_event.set())
collector.record_token_usage(model="anthropic.claude-3-sonnet", tokens=120)
assert flush_event.wait(timeout=2.0), "Collector failed to flush metrics within timeout window" |
TLDR
Problem this solves:
unitjob has been red on main since 2026-09-20 without a code changetracemallocdeltas, so GC timing decides pass or failHow it solves it:
cProfilefor a quarter-size and a full input, the full one must stay under 5x, no clockUser Flow
Test-only change, no user-facing behavior
Relevant issues
Affected release
Linear ticket
Pre-Submission checklist
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@greptileaito 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
Test-only change, so the proof is the flake history and the mutation checks rather than a live proxy run
Before (2f76aa1)
CircleCI pipeline 90036 on main,
unitjob:test_converse_stream_collector_keeps_usage_without_retaining_the_streamfailed withassert 179721 < (615582 // 4), the same test plus its invoke sibling andtest_scan_message_stays_linear_on_adversarial_credential_lineshave failed in 5 of the last 8 main runs with measured retention anywhere from 152 KB to 1.5 MB for identical codeAfter (84fc8ca)
Bedrock tests, baseline: growth, extra text bytes, allowed bound
Bedrock tests, mutant that disables text coalescing in
_CoalescedChunks.add(if text is not None and self._open_text_parts:->if False:), both tests failSecret detection no longer reads the clock. It runs
redact_textundercProfile.Profile.runcallon a quarter-size and a full-size input, sums the Python and C call counts, and asserts the large count stays within 1.25 times the size ratio of the small one. The profiler that was active before the helper ran is restored afterwards. The count is a pure function of the input, so it is identical on a loaded runner. Baseline counts (small, large): value-run 342088 13138, quote-run 10883 10887, keyword-run 235200 895230, value-repeat 15635 13496, assignment-flood 3832288 15324119, all greenSecret detection, mutant that adds a quadratic
_SHELL_ASSIGNMENT.matchpass over the kept lines in_parseable_lines: assignment-flood small 4395769, large 24327372, bound 21978845, redType
✅ Test
Caveats (if any)
Low
Final Attestation
Link to Devin session: https://app.devin.ai/sessions/a50faa6aa4104b818a8af665aecafb7e
Open in Devin Desktop: https://app.devin.ai/desktop/session/a50faa6aa4104b818a8af665aecafb7e?variant=devin
Note
Low Risk
Test-only changes; no runtime or production paths are modified.
Overview
Stabilizes flaky unit checks that were failing on CI without product code changes.
Bedrock passthrough stream collectors:
test_converse_stream_collector_keeps_usage_without_retaining_the_streamand the invoke-stream sibling no longer use process-widetracemallocdeltas. They compare reachable object size for collectors fed 4k vs 8k token streams and require retained growth to track added text while staying below a quarter of the extra raw stream bytes. Shared helpers build converse/invoke streams and factor out the comparison.Enterprise secret detection:
test_scan_message_stays_linear_on_adversarial_credential_linesdrops a fixed wall-clock bound onredact_text. It profiles quarter-size and full-size adversarial inputs withcProfile, sums call counts (restoring any prior profiler), and asserts the large input stays within 1.25× the scaled small count across five parametrized patterns.The Bedrock file also includes minor assert/formatting cleanups with no behavior change.
Reviewed by Cursor Bugbot for commit 84fc8ca. Bugbot is set up for automated code reviews on this repo. Configure here.