Only push usage payloads when WebRTC connection was established#2359
Conversation
Previously usage payloads were always flushed when the modal function completed, including the case where no WebRTC connection could be established at all. Move the push so it only fires on the success path and on the "connection established but no frames" error path, and skip it entirely when the connection was never established.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3a22cb0. Configure here.
| ), | ||
| ) | ||
| usage_collector.push_usage_payloads() | ||
|
|
There was a problem hiding this comment.
Recorded usage still pushed by background threads
High Severity
record_usage() is still called unconditionally (even when the connection was never established), but only push_usage_payloads() is skipped. The UsageCollector singleton has a background _collector_thread that periodically calls _enqueue_usage_payload() every flush_interval seconds (default 10s), which will enqueue and eventually send the recorded data anyway. Additionally, if the Modal container is reused for a subsequent request, the stale recorded data accumulates in self._usage and gets pushed on the next successful push_usage_payloads() call. Moving record_usage() inside the conditional (or guarding it with connection_established) is needed to actually prevent usage from being reported when no connection was established.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 3a22cb0. Configure here.


What does this PR do?
Previously usage payloads were always flushed when the modal function completed, including the case where no WebRTC connection could be established at all. Move the push so it only fires on the success path and on the "connection established but no frames" error path, and skip it entirely when the connection was never established.
Type of Change
Testing
Test details:
Running locally
Checklist
Additional Context
N/A
Note
Medium Risk
Adjusts usage-flush behavior in the WebRTC Modal worker, which can affect billing/telemetry accuracy. Change is small and localized but touches usage reporting on error paths.
Overview
Usage tracking in
webrtc_worker/modal.pyis adjusted sousage_collector.push_usage_payloads()is not called when a WebRTC connection was never established.Payloads are now flushed only on the normal success path and on the "connection established but no frames processed" failure path, avoiding sending usage for sessions that never connected.
Reviewed by Cursor Bugbot for commit 3a22cb0. Bugbot is set up for automated code reviews on this repo. Configure here.