fix(record): avoid ZeroDivisionError in HttpRecorder final-report fallback#1692
Open
WatchTree-19 wants to merge 1 commit into
Open
fix(record): avoid ZeroDivisionError in HttpRecorder final-report fallback#1692WatchTree-19 wants to merge 1 commit into
WatchTree-19 wants to merge 1 commit into
Conversation
…lback HttpRecorder.record_final_report sends a final_report event that is not appended to self._events. For a run that recorded no sample events, self._events is empty, so a failed POST evaluated failed_requests / len(self._events) and raised ZeroDivisionError. That error escaped _send_event (record_final_report only catches RuntimeError), crashing instead of falling back to the LocalRecorder. Use len(self._events) or len(events) as the denominator so the ratio stays well-defined; the failed final report now falls back to the LocalRecorder as intended. Adds a regression test. Signed-off-by: WatchTree-19 <119982314+WatchTree-19@users.noreply.github.com>
WatchTree-19
requested review from
andrew-openai,
etr2460 and
katyhshi
as code owners
July 10, 2026 13:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
summary
HttpRecorder.record_final_reportbuilds afinal_reportevent and sends it withself._send_event([report_event]), but it does not append that event toself._events. For a run that recorded no sample events,self._eventsstays empty.When the POST fails,
_send_eventruns:so it raises
ZeroDivisionError.record_final_reportonly catchesRuntimeError, so theZeroDivisionErrorpropagates and crashes the run instead of falling back to theLocalRecorder.fix
_send_eventis only ever called with a non-empty batch, so this keeps the ratio well-defined. In the empty-events case the threshold is now exceeded and aRuntimeErroris raised, whichrecord_final_reportcatches and uses to fall back to theLocalRecorder(the intended behavior). The normal (non-empty) path is unchanged.test
adds
test_http_recorder_final_report_no_events_falls_back_without_zerodivisiontoevals/record_test.py: withrequests.postpatched to fail and no recorded events,record_final_reportmust not raise and the report must be written by the fallbackLocalRecorder. the test fails withZeroDivisionErrorwithout the fix and passes with it.