fix(hlth-csp): give onion vhosts a navigation budget Tor can meet

csp-checker navigates every URL with a 20000 ms budget until
domcontentloaded. Over the Tor SOCKS proxy that expires before a page of
module scripts finishes: run 34614940508 lost Mastodon#1 and OpenProject#1
to it, 26 of 27 attempts logging "Unable to reach http://<onion>/
(Navigation timeout of 20000 ms exceeded)" while sys-service-terminator
retried the unit for 35 minutes. No policy was ever read; the checker never
got that far.

csp-checker 2.3.0 takes --timeout, so script.py takes --onion-timeout and
hands it to the onion batch alone, before the -- separator that would make
it a URL. Clearnet keeps the image default. The budget is
HEALTH_CSP_TIMEOUT_MS (20000, the image default) times the tor flavor's
multiplier, 100000 ms on the public network.

The unit's TimeoutStartSec had to follow. It was 30 + 25 s per domain --
130 s for the two onion vhosts Mastodon checks, while a 100 s budget needs
up to 200 s, so systemd would have killed the check mid-run. The filter now
takes onion_per_domain_seconds and counts .onion domains at that rate;
without the argument it computes exactly what it did before, so
sys-ctl-hlth-webserver is unchanged. The Mastodon case goes from 130 s to
450 s, a clearnet-only play stays at 130 s.

Tests pin that --timeout is appended only when set and stays ahead of the
separator, that main budgets the onion batch alone, that the role passes
both --onion-timeout and the onion rate for the start budget (both guards
fail against the previous tasks file), and the filter's split rate.

Not covered: the filter still caps at 3600 s, which binds beyond 34 onion
domains in one round.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5 committed 2026-09-12 00:18:00 +02:00
1 parent ffb04da40a
commit 6e98ecf66f
10 files changed
+205 -8

No files matched your search

@@ -25,6 +25,41 @@ class TestTimeoutStartSecForDomains(unittest.TestCase):
)
self.assertEqual(result, 180)
def test_an_onion_domain_costs_its_own_rate(self):
result = _f()(
["example.com", "abc.onion"],
include_www=False,
per_domain_seconds=25,
onion_per_domain_seconds=105,
overhead_seconds=30,
min_seconds=0,
max_seconds=3600,
)
self.assertEqual(result, 160)
def test_without_an_onion_rate_every_domain_costs_the_same(self):
result = _f()(
["example.com", "abc.onion"],
include_www=False,
per_domain_seconds=25,
overhead_seconds=30,
min_seconds=0,
max_seconds=3600,
)
self.assertEqual(result, 80)
def test_the_onion_rate_covers_the_www_variant_too(self):
result = _f()(
["abc.onion"],
include_www=True,
per_domain_seconds=25,
onion_per_domain_seconds=105,
overhead_seconds=30,
min_seconds=0,
max_seconds=3600,
)
self.assertEqual(result, 240)
def test_no_www_min_clamp_applies(self):
domains = {
"canonical": ["example.com", "foo.bar"],