Skip to content

Fix flaky spec_exposure ReDoS sweep test timing thresholds - #800

Merged
squid-protocol merged 1 commit into
mainfrom
fix/redos-sweep-timing-flakiness-followup
Jul 30, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/redos-sweep-timing-flakiness-followup

Conversation

@squid-protocol

@squid-protocol squid-protocol commented Jul 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Recovers a fix that was written during PR Fix #713: bound spec_exposure ReDoS across remaining 17 vulnerable languages #798 (spec_exposure's unbounded [^\]]* ReDoS is copy-pasted across 28 languages, including already-merged yacc #713) but never actually landed on main: the branch's auto-merge fired on an earlier green CI run before this follow-up commit was pushed, so it was silently dropped.
  • CI failure being fixed: test_spec_exposure_adjacent_quantifier_redos_sweep[dart] failed on a contended macOS/Python-3.9 runner with a measured ratio of 2.49x, just under the 2.5 threshold, despite the underlying pattern genuinely being quadratic (confirmed ~4x locally, unloaded).
  • Hardens all 8 shared "prove the old pattern is quadratic" ratio checks uniformly (not just the one that failed): raises _best_of_timing's default trials 3→5, and lowers the pass threshold 2.5→2.2 (still safely above linear's ~2.0x baseline).
  • Leaves 2 unrelated pre-existing embedded_python tests (different single-shot pattern) untouched — out of scope.

Test plan

  • Cherry-picked cleanly from the original commit, no conflicts
  • pytest -k "redos_regression or redos_immunity or redos_sweep" passes locally
  • CI green

…3.9)

CI failure on this PR's own smoke-test run: test_spec_exposure_adjacent_
quantifier_redos_sweep[dart] failed with "old pattern was expected to
show quadratic (~4x) scaling... but only scaled 2.49x" -- just under
the 2.5 ratio threshold, on a contended macOS/Python-3.9 runner. Locally
(unloaded) the same pattern measures a clean ~4x, confirming this is
transient CI timing noise, not a real regression in the fix.

Hardened against this class of flakiness two ways, applied uniformly
to all 8 "prove the old pattern is quadratic" ratio checks that share
_best_of_timing (not just the new #713 sweep):

- Raised _best_of_timing's default trials from 3 to 5, tightening the
  min-of-N distribution further without changing what's being proven.
- Lowered the pass threshold from 2.5 to 2.2 -- still safely above
  linear's ~2.0x baseline, but with meaningfully more margin against a
  genuinely-quadratic (~4x) measurement getting compressed by runner
  contention.

Left the two pre-existing, unrelated embedded_python tests that use a
different (single-shot, larger-payload, `durations[-1]/durations[-2]
> 2.5`) pattern untouched -- no evidence they're flaky, and touching
them is outside this issue's scope.

Verified: the sweep test passes stably across 5+ repeated runs, the
full redos_regression suite (15 passed), and the full strict-parsing
suite (2508 passed).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 764dbc3 into main Jul 30, 2026
27 checks passed
@squid-protocol
squid-protocol deleted the fix/redos-sweep-timing-flakiness-followup branch July 30, 2026 20:05
squid-protocol added a commit that referenced this pull request Jul 30, 2026
Same root cause and fix as the earlier flakiness hardening (#800):
test_yacc_explicit_casts_redos_immunity, test_groovy_closures_redos_immunity,
and test_groovy_spec_exposure_quadratic_blowup_redos_regression each timed
a single perf_counter() sample per payload size instead of using the
shared _best_of_timing() (min-of-5) helper already used elsewhere in this
file -- a lone scheduling hiccup on any one size was indistinguishable
from a real regression toward O(n^2).

Caught live: test_groovy_spec_exposure_quadratic_blowup_redos_regression
failed in CI on macos-latest/3.10 during an unrelated PR (#770), tripping
its 0.02s floor by a hair ([...0.0064s, 0.0202s]) under smoke-test runner
contention -- not a real regression (confirmed clean locally, unloaded).
Swept the other 2 occurrences of the identical single-shot-timing shape
proactively rather than patching only the one that failed, matching the
approach used for the earlier ratio-based flaky tests.

Co-authored-by: Joe Esquibel <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
squid-protocol added a commit that referenced this pull request Sep 9, 2026
…S timing asserts (#2901) (#2919)

* ci: dedupe concurrent runs, parallelise pytest, cap job runtime

Measured over the last 400 workflow runs (~27h window, 2026-09-08/09):
2201 min of wall clock, of which Full Suite Gate alone was 983 min (45%).
The cost was not test execution -- it was running the same tests repeatedly
and then queueing for runners.

Three findings drove this:

1. `full-suite-gate.yml` triggers on `pull_request: types: [labeled]` with
   no label filter, so EVERY label added starts a separate run. PRs here
   routinely carry four labels (bug, metrics, core-engine,
   rosetta:rebless-owed), and #2915 fired four identical 12-job matrix runs
   against one SHA (56624e7) within 10 seconds. rosetta-audit, which also
   listens for `labeled`/`unlabeled`, fired five times on the same commit.
   No workflow in the repo declared `concurrency`, so nothing superseded
   anything. ~577 min of the sampled 2201 was redundant.

2. Queue time dwarfed run time. In run 34346837647 the matrix jobs RAN for
   10-18 min but QUEUED for 23-65 min, macOS worst (51-65 min) as the
   scarcest pool -- 16 macOS jobs were queued where 4 were needed.

3. `pytest tests/ -v` ran the whole suite single-threaded and streamed 7946
   lines / 1.1 MB to the Actions log per job.

Changes:

- `concurrency` on 18 workflows, keyed by workflow + PR number (or ref).
  `cancel-in-progress` is deliberately scoped to `pull_request` via an
  expression: the push/schedule/tag runs are the ones that COMMIT (docs
  deploy, tri-comparison / tree-sitter history charts, releases), and
  cancelling one mid-write risks a half-written commit. Those now serialise
  on the group instead. `publish.yml` and `release-crucible-archive.yml` are
  left untouched entirely -- the release path should not be interfered with.

- pytest jobs get `pytest-xdist` and run `-n auto -q -ra --durations=25`.
  Verified locally against this same tree: 8685 tests, serial 323.6s ->
  parallel 104.8s (3.1x on 6 cores), identical pass/skip/xfail counts. CI
  runners are 4-core, so expect ~2.5x. `-ra` keeps the xfail/skip summary
  and `--durations=25` keeps a slow-test report, which is the only part of
  `-v` that was load-bearing on a green run.

- `timeout-minutes` on every job across 18 workflows. The default is 6h; a
  Full Suite Gate run was observed sitting at 78 min mid-flight during this
  investigation with nothing to stop it.

- `full-suite-gate.yml` sizes its matrix per checkpoint. A `v*` tag still
  gets the untrimmed 12-way grid. A PR label gets 8 jobs: all four Python
  versions on ubuntu (the thing this gate exists to catch is a
  version-specific break the every-push ubuntu/3.12 full-suite cannot see),
  with windows and macOS covering the version floor and ceiling only. That
  halves the macOS jobs that dominate the queue.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix(tests): replace wall-clock ReDoS ratios with absolute bounds (#2901)

#2901 reports two asserts going red on shared macOS runners for PRs whose
diffs touched neither: `test_embedded_python_spec_exposure_redos_immunity`
(macOS runs 34288012477, 34212533327 -- expected ratio > 2.5, got 2.31) and
`test_var_decl_pattern_scales_linearly_not_quadratically`. Both compare
wall-clock samples on a contended runner.

Scope is wider than the two files the issue names, deliberately: the same
shape appears at 22 timing sites, and the companion CI change in this branch
runs the suite under `pytest -n auto`, which raises CPU contention and would
have made every one of them flakier. `_strict_harness._best_of_timing`'s own
docstring already records this class of failure recurring (#713, #800), and
groovy's spec_exposure test carries a comment about it going red on
macos-3.10 during #770.

Triaged into three groups:

- 6 sites already assert an ABSOLUTE bound on the shipped pattern
  (test_prism, abap, matlab, scheme, yaml, security_lens). Left alone --
  these are the shape the issue recommends.

- 13 sites timed the PRE-FIX pattern to prove it was quadratic before
  checking the shipped one. Removed. They measured a regex this repo no
  longer ships, so no threshold makes them both meaningful and stable, and
  every one is redundant with an `assert_redos_immune` already in the same
  test. The measured pre-fix numbers are preserved as comments, and
  `test_language_standards_strict.py` keeps each language's pre-fix pattern
  in its parametrize table as documentation (the param is renamed
  `_old_pattern_text` to mark it non-executable).

- 3 sites (groovy x2, yacc) asserted a ratio ceiling on the SHIPPED pattern
  immediately after an `assert_redos_immune` call on a 100k payload. The
  ratio was strictly weaker than the absolute bound above it; removed.

- 2 sites converted from ratio to absolute bound, since they had no
  `assert_redos_immune` of their own:
  * `var_decl`: verified the replacement still catches what it is for --
    restoring the adjacent-unbounded-quantifier shape (`[^=\n]{0,80}` ->
    `[^=\n]*`) makes the new 160k assertion FAIL, while the shipped pattern
    passes it in ~1.1s including process spawn.
  * ada `func_start`: measured while replacing it, this site has NO reachable
    quadratic regression -- the aspect segment is lazy, so even fully
    unbounded (`[^;{}]{0,300}?` -> `[^;{}]*?`) it stays linear (0.0002s /
    0.0004s / 0.0007s / 0.0014s at n=2000/4000/8000/16000). The old ratio's
    additive 0.05 floor was deciding the result. Kept as a plain ceiling on
    a long aspect run and the docstring says so rather than overclaiming.

Suite is green both ways on this tree: 8685 passed / 4 skipped / 9 xfailed /
3 xpassed, identical serial and under `-n auto`. No new ruff findings (the
one I001 in test_language_standards_strict.py predates this branch).

Closes #2901

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: Joe Esquibel <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant