Repository navigation
test(proxy): make the stagger-offset and linear-dedup guards independent of runner identity and load - #45031
Conversation
…c test no longer depends on the runner's host and pid Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…he linear dedup guard is deterministic under CI load 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 |
|
|
|
||
|
|
||
| def _lines_run_resolving(registry: AttachmentRegistry, context: PolicyMatchContext) -> tuple[list[str], int]: | ||
| lines_run = 0 |
There was a problem hiding this comment.
New locals lack Final, and lines_run is rebound without justification. AGENTS.md requires Final annotations and # rebind-ok: <reason> for unavoidable rebinding. Apply these conventions to the helper and new test setup before merging
Context Used: AGENTS.md (source)
There was a problem hiding this comment.
Fixed in 588b0db. The new locals are annotated Final, and the lines_run counter has a # rebind-ok reason, since the trace hook has to increment it
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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 588b0db. Configure here.
TLDR
Problem this solves:
How it solves it:
scheduled_job_stagger.offsetsFlakes covered (run date 2026-10-06 to 2026-10-07)
tests/unit/proxy/proxy_server/test_proxy_config.py::test_ProxyConfig__update_general_settings_runtime_interval_job_carries_the_stagger_offsetCI evidence, 5 failures in the window, 3 of them passing on a rerun of the same SHA:
mainat 62dee3d, attempt 1 failed (proxy-server job), attempt 2 passedFailure:
AssertionError: <IntervalTrigger (interval=datetime.timedelta(days=1), ...)>where an_OffsetTriggerwas expectedMechanism:
offset_secondshashes"spend_log_cleanup_job\x00{host}:{pid}"into[0, window)with a 300s window, andstagger_triggercorrectly returns the bare trigger when that offset is 0. About 1 in 300 test processes land on 0, so the test's result depended on the runner's hostname and the xdist worker's pid. Reproduced locally by forking until a pid hashed to offset 0: the test fails there and passes everywhere else, with no edits in betweenFix: the test sets
scheduled_job_stagger: {offsets: {spend_log_cleanup_job: 120}}on the proxy settings, which_spend_log_cleanup_triggerreads throughparse_stagger_settings, and now asserts the job's trigger is an_OffsetTriggerwithoffset == 120swrapping the one-dayIntervalTrigger. The hash placement itself stays covered bytests/unit/proxy/common_utils/test_scheduled_job_stagger.pytests/unit/proxy/policy_engine/test_attachment_registry.py::TestGetAttachedPolicies::test_many_distinct_policies_resolve_in_linear_timeCI evidence, 2 failures in the window, both passing on a rerun of the same SHA:
20000 attachments took 1.00s, attempt 2 passed20000 attachments took 1.30s, attempt 2 passedMechanism: a wall-clock budget (
elapsed < 1.0aroundget_attached_policiesfor 20,000 policies). The call takes about 0.25s on an idle machine, so CPU contention on a shared runner was enough to cross the budget.tests/unit/AGENTS.mdalso rules out the clock in unit testsFix: the guard the test exists for is the one-pass dedup from 311d9bb, which replaced a per-policy scan that was quadratic. The test now traces
get_attached_policieswithsys.settraceand countslineevents at 1,000 and 4,000 policies, asserting the larger run does less than 8x the work of the smaller one. The current resolver measures 69,145 and 260,026 (3.8x). With the pre-311d9bba37 per-policy scan put back, the counts are 568,642 and 8,258,023 (14.5x), and the test fails. The counts do not depend on machine speed or loadNot fixed here
tests/unit/proxy/pass_through_endpoints/test_streaming_handler.py::test_failed_anthropic_stream_records_partial_usage_off_the_event_loopfailed twice (run 37513362913, run 37491587039) with the loop reported stalled about 0.7 to 0.85s of a 1.5s count, but neither run was retried on the same SHA and it passed 30 of 30 locally, idle and under CPU load, so it is reported as unreproduced rather than guessed atPre-Submission checklist
Screenshots / Proof of Fix
No end-user behavior changes; this PR only changes two tests. The mechanism of the first flake can be seen directly in the production helper, outside pytest, by asking it for the cleanup job's trigger under two runner identities:
The second flake's mechanism is in the CI logs linked above: the same SHA measured 1.00s and 1.30s on attempt 1 and passed on attempt 2
Type
Test
Caveats (if any)
Low
get_attached_policies_with_reasonsFinal Attestation
Link to Devin session: https://app.devin.ai/sessions/5db7c48d582940a2b79292fc4fdea782
Open in Devin Desktop: https://app.devin.ai/desktop/session/5db7c48d582940a2b79292fc4fdea782?variant=devin
Note
Low Risk
Only unit test assertions and harness code changed; no production behavior is modified.
Overview
Test-only changes to stop two CI flakes that depended on runner identity and wall-clock load.
In
test_attachment_registry.py, the large-policy performance guard no longer uses a <1.0s timer on 20k attachments. It adds asys.settracehelper that counts line events while resolving attachments, runs 1,000 vs 4,000 global-scope policies, and asserts the larger run stays below 8× the smaller run’s line count (still checking one-pass linear dedup).In
test_proxy_config.py, the stagger test now loadsscheduled_job_stagger.offsets.spend_log_cleanup_job: 120into proxy settings so the registered job always gets an_OffsetTriggerwithoffset == 120swrapping a one-dayIntervalTrigger, instead of relying on hostname/pid hashing that sometimes yields offset 0 and a bare interval trigger.Reviewed by Cursor Bugbot for commit 588b0db. Bugbot is set up for automated code reviews on this repo. Configure here.