Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test(security): CPU-clock scrub_error budgets; widen bare-schemes to 2.5s, 15s wall backstop (#6623)

LearningCircuit423c7df4ac52
diff --git a/tests/security/test_log_sanitizer.py b/tests/security/test_log_sanitizer.py
index 286647277c..22385a8dc7 100644
--- a/tests/security/test_log_sanitizer.py
+++ b/tests/security/test_log_sanitizer.py
@@ -543,6 +543,11 @@ class TestScrubErrorUrlQueryRedaction:
Scoped to scrub_error() only: sanitize_error_for_client() (the
client-facing path) must keep preserving non-credential query params,
per TestSanitizeErrorForClient.test_does_not_over_redact_innocuous_text.
+
+ Timing convention for this class's budget tests (#6612): elapsed is
+ measured on the CPU clock (time.process_time) and the wall-clock
+ backstop is @pytest.mark.timeout(15) — see the note in
+ test_scrub_error_is_bounded_on_a_run_of_bare_schemes for rationale.
"""
def test_strips_query_string_from_requests_style_http_error(self):
@@ -694,7 +699,7 @@ class TestScrubErrorUrlQueryRedaction:
assert "q=1" not in result
assert result == "see [https://h/p?<redacted> end"
- @pytest.mark.timeout(5)
+ @pytest.mark.timeout(15)
def test_scrub_error_is_linear_time_on_a_dense_url_run(self):
# Regression for #6549. The scheme-continuation bound (next test)
# covers one quadratic path; the URL body was the other. With an
@@ -705,34 +710,57 @@ class TestScrubErrorUrlQueryRedaction:
# never comes: measured ~1s at 36k chars, ~4s at 72k, ~16s at 144k
# (4x per doubling), against milliseconds before the query pass.
# Excluding the quote from the URL body and capping it restores
- # linear time (locally: 200k chars in ~30ms).
+ # linear time (locally: 200k chars in ~30ms). Timing and the
+ # wall-clock backstop follow the note in the bare-schemes test
+ # below (#6612).
run = '"https://a.com/x",' * 11_111 # ~200k chars, no "?" anywhere
- t0 = time.perf_counter()
+ t0 = time.process_time()
result = scrub_error(Exception(run))
- elapsed = time.perf_counter() - t0
+ elapsed = time.process_time() - t0
assert result == run # no query string, nothing to redact
assert elapsed < 2.0, (
- f"scrub_error took {elapsed:.2f}s on a 200k-char dense-URL run "
- f"(budget: 2.0s) — the URL-body quantifier may have regressed to "
- f"unbounded, reintroducing quadratic ReDoS."
+ f"scrub_error took {elapsed:.2f}s cpu on a 200k-char dense-URL "
+ f"run (budget: 2.0s) — the URL-body quantifier may have regressed "
+ f"to unbounded, reintroducing quadratic ReDoS."
)
- @pytest.mark.timeout(5)
+ @pytest.mark.timeout(15)
def test_scrub_error_is_bounded_on_a_run_of_bare_schemes(self):
# The worst remaining shape for the capped body: no quote to stop
# at, "://" at every fourth char, no "?" — each start position now
# scans at most 4096 chars instead of the remainder of the run, so
# the cost is linear in the input rather than quadratic.
+ # Budgets are measured on the CPU clock (process_time), not the
+ # wall clock: #6612 (a green-main docs PR) failed THIS test at
+ # 2.17s wall on an xdist-loaded runner — local CPU time for this
+ # input is ~0.44s, far under budget. The regex is pure in-process
+ # CPU work, so process_time measures the cost without the
+ # scheduler-noise component of co-scheduled pytest workers
+ # (residual cache-pollution inflation is real but bounded:
+ # measured ≤ ~1.7x here vs the ~4.9x wall inflation in #6612).
+ # This test carries the tightest healthy margin of the three
+ # (~0.44s local CPU), so its budget is 2.5s to absorb slow CI
+ # cores; a cap-removed regression measures >4s CPU locally and
+ # still trips it.
+ # The wall-clock backstop is 15s, not 5s: pytest-timeout bounds
+ # setup + call on the WALL clock, and on an xdist-loaded runner
+ # several seconds of setup/import can elapse with near-zero CPU
+ # cost — a 5s wall cap flaked exactly there under load even with
+ # the CPU budget comfortably met, and a real ~4.3s-CPU regression
+ # under contention would die by timeout before this assert could
+ # print its diagnostic. 15s still hard-fails hang-class
+ # regressions (the marker's actual purpose).
run = "x://" * 20_000 # 80k chars
- t0 = time.perf_counter()
+ t0 = time.process_time()
scrub_error(Exception(run))
- elapsed = time.perf_counter() - t0
- assert elapsed < 2.0, (
- f"scrub_error took {elapsed:.2f}s on an 80k-char run of bare "
- f"schemes (budget: 2.0s) — the URL-body cap may have been removed."
+ elapsed = time.process_time() - t0
+ assert elapsed < 2.5, (
+ f"scrub_error took {elapsed:.2f}s cpu on an 80k-char run of "
+ f"bare schemes (budget: 2.5s) — the URL-body cap may have been "
+ f"removed."
)
- @pytest.mark.timeout(5)
+ @pytest.mark.timeout(15)
def test_scrub_error_is_linear_time_on_a_long_scheme_like_run(self):
# @pytest.mark.timeout is a hard backstop, not just the assertion
# below: it fails the test outright if scrub_error itself hangs,
@@ -749,16 +777,19 @@ class TestScrubErrorUrlQueryRedaction:
# a ~1MB run would hang a worker for ~15 minutes, on a path that
# by definition handles attacker-influenceable exception text.
# Bounding the continuation restores linear time (locally: 200k
- # chars in ~50ms). Generous 2s budget absorbs noisy CI runners
- # while still catching a regression by orders of magnitude.
+ # chars in ~50ms). Generous 2s CPU budget absorbs slow CI cores
+ # while still catching a regression by orders of magnitude
+ # (timing and wall-clock backstop — see the note in the
+ # bare-schemes test below, #6612).
run = "a" * 200_000 # no "://" anywhere in this string
- t0 = time.perf_counter()
+ t0 = time.process_time()
scrub_error(Exception(run))
- elapsed = time.perf_counter() - t0
+ elapsed = time.process_time() - t0
assert elapsed < 2.0, (
- f"scrub_error took {elapsed:.2f}s on a 200k-char scheme-like "
- f"run (budget: 2.0s) — the scheme-continuation quantifier may "
- f"have regressed to unbounded, reintroducing quadratic ReDoS."
+ f"scrub_error took {elapsed:.2f}s cpu on a 200k-char "
+ f"scheme-like run (budget: 2.0s) — the scheme-continuation "
+ f"quantifier may have regressed to unbounded, reintroducing "
+ f"quadratic ReDoS."
)