Opt-in per-client event throttling (#1)#8
Draft
tensiondriven wants to merge 1 commit into
Draft
Conversation
Noisy CDP domains (Console.enable, Network.enable) can emit 100k+ events
that back up native messaging stdio and drown slow WS clients. Add an
opt-in throttle, configured per client via chrome-tap.attach:
chrome-tap.attach { tabId, eventThrottle: { "Console.messageAdded": 50, "*": 200 } }
- host/throttle.js: ClientThrottle — sliding 1s window per method, "*"
wildcard with explicit-method override, accumulates dropped counts.
- router.js: applies throttle + 4MB send-buffer backpressure in the event
fan-out; flushes a chrome-tap.throttled notice (per-method dropped counts)
every 100ms so loss is never silent. eventThrottle is stripped before
forwarding to the extension/CDP.
- Default is unchanged: no config => raw firehose. Per-client, so one slow
consumer never throttles others.
- Tests via node:test (zero deps); `npm test` in host/.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Closes #1.
What
Opt-in, per-client event throttling for high-volume CDP domains. By default nothing changes — clients still get the raw firehose. A client opts in by passing
eventThrottletochrome-tap.attach:{"id":2,"method":"chrome-tap.attach","params":{ "tabId":123, "eventThrottle":{"Console.messageAdded":50,"Network.dataReceived":100,"*":200} }}Values are max events/sec per method (
"*"is a wildcard; an explicit method overrides it). Events over the cap inside a 1s window are dropped newest-first.Drops are never silent. Every 100ms the host emits a notice with per-method counts since the last flush:
{"type":"event","method":"chrome-tap.throttled","params":{"dropped":{"Console.messageAdded":312}}}A throttled client whose WS send buffer backs up past 4MB also has its events dropped (and counted) until it drains — router-side backpressure so one slow consumer can't stall the host.
Approach / scope
The issue listed four candidate approaches. This implements the two that live entirely host-side and need no extension reload or Team-tier config:
eventThrottleon attach).Extension-side ring buffering and array-batching were left out deliberately — batching would change the wire format (events become arrays) and touch the MV3 service worker; worth its own issue if the host-side limits prove insufficient.
Throttle state is per WS client, so throttling one client never affects another subscribed to the same tab.
eventThrottleis stripped before commands are forwarded to the extension/CDP.Files
host/throttle.js—ClientThrottle(sliding window, wildcard, drop accounting).host/router.js— applies throttle + backpressure in the event fan-out; flush timer forchrome-tap.throttled; stripseventThrottleon attach.host/throttle.test.js— 11 tests via the built-innode:testrunner (zero new deps).host/package.json— addsnpm test.README.md— documents the opt-in throttle.Verification
node --checkclean on everyhost/*.js.cd host && npm test→ 11 passing, 0 failing.No lint/typecheck tooling exists in the repo (vanilla CommonJS, no eslint/prettier/tsconfig), so syntax check + tests are the bar. No pre-existing warnings to baseline against.
🤖 Generated with Claude Code