Repository navigation
Count proxy traffic per run and stop at --proxy-budget-mb (default 10 MB) - #7
Merged
Merged
Conversation
… MB) A local browser run through --proxy / --proxy-file now counts the bytes it sends through the proxy (Playwright: request.sizes(); pyppeteer and Selenium: CDP Network.loadingFinished.encodedDataLength plus request sizes; the pre-check HEAD too). Once the total passes --proxy-budget-mb no new page, retry or re-fetch is started (concurrent workers take no further page), the browser aborts what it still tries, the rows read so far are kept, and the run exits 6 (5 with no rows) with stop_reason proxy_budget_exceeded. The sidecar records proxy_bytes, proxy_budget_bytes, proxy_budget_exceeded and pages_unattempted, and the run ends with one "Proxy traffic: X.X MB of Y MB budget" line. Nothing is metered over --cdp-endpoint or with no proxy. The canary passes --proxy-budget-mb 10 to both runs, writes their traffic to the job summary and fails when the budget was hit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CKsd7q25N19WzUZjrAdzx8
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.
Problem
A run through a residential proxy is billed per byte, and nothing measured or limited what a run sent through it. A run that kept retrying or rotating, or a site page that grew, could spend a lot before anyone looked.
Resulting behaviour
This applies only to a local browser behind
--proxy/--proxy-file/AUTOTRADER_PROXY. Nothing changes over--cdp-endpoint, with no proxy, or inscraper_api_client.py.proxy_meter.py). The count is an estimate of the tunnelled payload. It does not include TLS/CONNECToverhead, WebSocket frames or Chrome's own background requests.request.sizes()(request headers + body, response headers + body) onrequestfinished/requestfailed, for every context_launch_localmakes, including each concurrent worker's.Network.loadingFinished.encodedDataLengthof responses that came over the network, plus the request line, headers and body fromNetwork.requestWillBeSent. Chrome's own error page and cache hits are not counted.quit().HEADis counted through arequestsresponse hook.--proxy-budget-mb(default 10, 0 = unlimited). A negative or non-number value is a usage error that names the flag. It is a flag only, becauseENV_KEYSmaps only credentials and URLs. Once the total passes the budget:--concurrency: no worker takes another page, pages already loading finish, and the queue's remainder is reported;fallback()). pyppeteer and Selenium setNetwork.setBlockedURLs ["*"];stop_reason: proxy_budget_exceeded, exit 6 with rows and 5 without.finish_runputs this above a block, so a spent budget on a refused page is 5, not 3.proxy_bytes,proxy_budget_bytesandproxy_budget_exceeded, which arenull/null/falsewithout a local proxy;pages_unattempted;<out>.latest_attempt.meta.json, and the data and.meta.jsonare left as they were;Proxy traffic: X.X MB of Y MB budget.--proxy-budget-mb 10. Anif: always()step after each,.github/proxy_traffic_summary.py, appends**run listing**/**run vehicle**: proxy traffic X.X MB of 10 MBto$GITHUB_STEP_SUMMARY. If the budget was hit, it prints::error::stopped: proxy budget 10 MB exceededand fails.tests/test_proxy_meter.pywithPROXY_METER_REQUIRE=<engine>. A missing browser fails the job instead of skipping.Evidence (offline; no proxy, no paid call, no canary dispatched)
tests/test_proxy_meter.py. A stub forward proxy serves a page of known size (about 152 KB) and counts the bytes on its sockets. Compared with that count:requests: within 2%;ERR_BLOCKED_BY_CLIENT.Proxy traffic: 0.0 MB of 10 MB budget, and an attempt sidecar withproxy_bytes320–640.--proxy-budget-mb 0.0001 --retries 3: rc 5 withstop_reason: proxy_budget_exceeded. Playwright stopped after ONE CONNECT, with no retries.(1200, 1000, True),pages_unattempted [3,4,5];proxy_budget_exceeded;add()disabled: 11 smoke failures and 8 test_proxy_meter failures;finish_runoverride: 5 checks;Not changed
🤖 Generated with Claude Code
https://claude.ai/code/session_01CKsd7q25N19WzUZjrAdzx8