Commit 0b209d4
feat(reliability+network): SR-174 — network-state pre-click gate
Adds three new modules + extends runner_policy with PROVIDER_NETWORK_TUNING.
- survey/network/beacon_filter.py: regex-based filter for analytics
beacons (Google Analytics, DoubleClick, Segment, Mixpanel, etc.).
Configurable, extensible, with negative tests against survey-tracking
URLs to prevent over-matching (e.g. 'survey-analytics-provider.com'
must NOT match).
- survey/network/cdp_network_tracker.py: Playwright-CDPSession-based
network monitor. Subscribes to Network.requestWillBeSent /
responseReceived / loadingFailed / loadingFinished. Per-page-scoped,
detaches cleanly on close (try/finally + async context manager).
Beacons filtered out of pending count. Snapshot is monotonic-clock
based, immutable, safe to take during traffic.
- survey/reliability/network_gate.py: async wait_for_network_quiet()
that polls the tracker on a 10 ms cadence until pending_count <=
max_pending AND last_response_age >= quiet_ms. On timeout, emits a
'network_never_quiet' event (NOT a hang) and returns force_proceed=
True — caller decides escalation. Strict caps: max_wait_ms hard
upper-bound, no infinite waits possible.
- survey/runner_policy.py: PROVIDER_NETWORK_TUNING table with profiles
for pollfish (strict), cint (relaxed for beacons), lucid (tight),
qualtrics (medium). Default fallback. get_network_tuning() is
pure-function.
Tests (45 cases, all green on Python 3.13):
- test_beacon_filter.py (8 cases): default beacon match, survey-tracking
preservation, custom-pattern injection, regex-compile-once perf.
- test_cdp_network_tracker.py (17 cases): full CDP event lifecycle,
beacon-exclusion, finish + fail event paths, monotonic ordering,
context-manager attach/detach, idempotent close, race-condition
detach-during-event, snapshot-immutability.
- test_network_gate.py (20 cases): immediate-pass when already quiet,
wait-for-pending-to-finish, beacon-doesn't-block, timeout +
force-proceed semantics, EventEmitter integration, provider-tuning
end-to-end (pollfish vs cint vs lucid behavior demonstrated).
Latency (micro-benchmark, in-process FakePage):
best-case (already quiet) : p50=0.00ms p95=0.02ms
after 1 request settles : p50=30.78ms p95=30.93ms
(quiet_ms=10, single 20ms request -> ~30ms total = correct)
Path-doctrine: 100% inside survey-cli/survey/. No new top-level dirs.
Scope intentionally NOT included (separate work):
- safe_executor.py integration: deferred until SR-169 lands (composes
DOM-stability + network-quiet behind one stability.py facade). This
PR ships the gate as a primitive, ready to be wired in.
- proxy hot-rotation telemetry: out of scope.
Refs: #179 (SR-174), depends-on #175 (SR-169) for full integration.
Co-authored-by: v0-agent <v0-agent@stealth-runner.local>1 parent 0a7d965 commit 0b209d4
9 files changed
Lines changed: 1595 additions & 21 deletions
File tree
- survey-cli
- survey
- network
- reliability
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
| 2 | + | |
20 | 3 | | |
21 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
22 | 15 | | |
23 | 16 | | |
24 | 17 | | |
25 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
38 | 46 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
0 commit comments