Repository navigation
Count proxy traffic per run and stop at --proxy-budget-mb (default 10 MB) - #25
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, exit rotation or captcha solve 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, writes its 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/MEDIAMARKT_PROXY. Nothing changes over--cdp-endpointor with no proxy.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()onrequestfinished/requestfailedfor every proxied context, the concurrent workers' included.Network.loadingFinished.encodedDataLengthof responses that came over the network, plus the request line, headers and body. Chrome's own error page and cache hits are not counted.quit().HEADis counted through arequestsresponse hook..github/canary_preflight.pyruns in its own process, before the scraper, so its request is not in the count.--proxy-budget-mb: default 10,0= unlimited. A negative value or a non-number 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, in all three engines:--concurrency, no worker takes another page, and pages already loading finish;fallback(). pyppeteer and Selenium setNetwork.setBlockedURLs ["*"];stop_reason: proxy_budget_exceeded: exit 6 with rows, 5 without.finish_runputs this above a block.proxy_bytes,proxy_budget_bytesandproxy_budget_exceeded. They arenull/null/falsewithout a local proxy.pages_unattemptedafter a stop.<out>.latest_attempt.meta.json. The data and.meta.jsonare left untouched.Proxy traffic: X.X MB of Y MB budget.--proxy-budget-mb 10. Anif: always()step,.github/proxy_traffic_summary.py, then appends**live-run**: proxy traffic X.X MB of 10 MBto$GITHUB_STEP_SUMMARY. When 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.--pages 3 --retries 3.Proxy traffic: 0.0 MB of 10 MB budget.--proxy-budget-mb 0.0001: rc 5,stop_reason: proxy_budget_exceeded, andproxy_bytesof 217–654 in the attempt sidecar.finish_runprecedence for rows/blocked/failed combinations, giving 6 or 5 withproxy_budget_exceeded.scrape(), with the browser and page fetch stubbed:(1200, 1000, True),pages_unattempted [3,4,5];_fetch_one_pageneither retries a timed-out navigation nor rotates away from a dead exit on a spent budget.add()disabled: 10 smoke and 8 test_proxy_meter failures.finish_runoverride: 7 checks.Not changed
🤖 Generated with Claude Code
https://claude.ai/code/session_01CKsd7q25N19WzUZjrAdzx8