Skip to content

ci: dedupe concurrent runs, parallelise pytest, and de-flake the ReDoS timing asserts (#2901) - #2919

Merged
squid-protocol merged 2 commits into
mainfrom
ci/2901-throughput
Sep 9, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
ci/2901-throughput

Conversation

@squid-protocol

@squid-protocol squid-protocol commented Sep 9, 2026 •

Copy link
Copy Markdown
Owner

Why

CI wall clock was measured over the last 400 workflow runs (~27h window, 2026-09-08/09): 2201 min total, of which Full Suite Gate alone was 983 min (45%).

The cost is not test execution. It is running the same tests repeatedly, then queueing for runners.

Workflow n median p90 total
Full Suite Gate (OS x Python) 26 36.4m 61.3m 983m
GitGalaxy Smoke Tests 17 14.1m 28.1m 288m
rosetta-audit 40 3.2m 14.0m 234m
Muninn Security Scan 54 2.7m 3.6m 168m

1. Every PR ran the full matrix 3-4 times on the same commit. full-suite-gate.yml triggers on pull_request: types: [labeled] with no label filter, so every label added starts a run. PRs here routinely carry four labels (bug, metrics, core-engine, rosetta:rebless-owed). #2915 fired four identical 12-job matrix runs against one SHA (56624e7b8) within 10 seconds; rosetta-audit fired five. No workflow declared concurrency, so nothing superseded anything. ~577 min of the sampled 2201 was redundant.

2. Queue time dwarfed run time. In run 34346837647 the jobs ran 10-18 min but queued 23-65 min:

macos-latest, 3.10     queued=65m   ran=14m
macos-latest, 3.9      queued=60m   ran=16m
ubuntu-latest, 3.10    queued=33m   ran=15m
windows-latest, 3.9    queued=36m   ran=12m

macOS is the scarcest pool, and the duplicate runs put 16 macOS jobs in a queue that needed 4.

3. The suite ran single-threaded and streamed 7946 lines / 1.1 MB to the Actions log per job via -v.

What changed

  • concurrency on 18 workflows, keyed by workflow + PR number (or ref). cancel-in-progress is scoped to pull_request via an expression on purpose: 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 serialise on the group instead. publish.yml and release-crucible-archive.yml are left untouched entirely.

  • pytest-xdist, -n auto -q -ra --durations=25 on both pytest jobs. -ra and --durations=25 keep the only parts of -v that were load-bearing on a green run.

    Measured locally on 6 cores, 8685 tests, all four runs reporting identical counts (8685 passed / 4 skipped / 9 xfailed / 3 xpassed):

    serial -n auto speedup
    origin/main (unmodified) 349.3s 109.5s 3.19x
    this branch 323.6s 104.8s 3.09x

    Two things worth reading off that table. The speedup is parallelism, not this PR's test edits — it is the same either side. And the flaky: ReDoS "pre-fix pattern scales quadratically" timing ratios fail on shared macOS runners #2901 deletions are worth ~26s serial (7%) on their own, which was never the point of them; de-flaking was. CI runners are 4-core, so expect ~2.5x there rather than 3.1x.

  • 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.

  • Per-checkpoint matrix in full-suite-gate.yml. A v* tag still gets the untrimmed 12-way grid. A PR label gets 8 jobs: all four Python versions on ubuntu (a version-specific break the every-push ubuntu/3.12 full-suite cannot see is exactly what this gate exists for), windows and macOS at the version floor and ceiling only. Halves the macOS jobs that dominate the queue.

Closes #2901

The flaky ReDoS timing asserts had to be fixed as part of this, not after: -n auto raises CPU contention, which would have made every wall-clock ratio assert flakier.

Scope is wider than the two files #2901 names — the same shape appears at 22 timing sites. _best_of_timing's own docstring records this class recurring (#713, #800), and groovy's spec_exposure test carries a comment about it going red on macos-3.10 during #770.

  • 6 sites already assert an absolute bound on the shipped pattern (test_prism, abap, matlab, scheme, yaml, security_lens) — left alone, this is the shape the issue recommends.
  • 13 sites timed the pre-fix pattern to prove it was quadratic before checking the shipped one. Removed: they measure a regex this repo no longer ships, and each is redundant with an assert_redos_immune already in the same test. Measured pre-fix numbers preserved as comments; test_language_standards_strict.py keeps each language's pre-fix pattern in its parametrize table as documentation.
  • 3 sites (groovy x2, yacc) asserted a ratio ceiling on the shipped pattern immediately after an assert_redos_immune on a 100k payload — strictly weaker than the bound above it. Removed.
  • 2 sites converted from ratio to absolute bound:
    • var_decl — verified the replacement still catches what it is for: restoring [^=\n]{0,80} -> [^=\n]* makes the new 160k assertion fail, while the shipped pattern passes in ~1.1s.
    • ada func_start — measured while replacing it, this site has no reachable quadratic regression: the aspect segment is lazy, so even fully unbounded it stays linear (0.0002/0.0004/0.0007/0.0014s at n=2000..16000). The old ratio's additive 0.05 floor was deciding the result. Kept as a plain ceiling, and the docstring says so rather than overclaiming.

Verification

  • Suite green both ways on this tree: 8685 passed, 4 skipped, 9 xfailed, 3 xpassed — identical serial and under -n auto.
  • tests/tools/audit_check.py: ruff (70-finding baseline, format clean), mypy (2-error baseline), dead-key, ast-accuracy — all clear.
  • Every workflow YAML re-parsed after editing; the per-trigger matrix shell was executed for both event types and its JSON validated (12 jobs on tag, 8 on PR label).

Reviewer notes

  • This changes when the 12-way matrix runs, not whether it exists. Release tags are unchanged.
  • concurrency cancels superseded PR runs only. If you want a commit-producing main-push workflow to also cancel, that is a deliberate follow-up, not an oversight here.
  • Not done here, as it is a policy call rather than a defect: filtering the gate to one explicit label (if: github.event.label.name == 'full-matrix') so bookkeeping labels like rosetta:rebless-owed stop triggering a matrix at all. concurrency already collapses the duplicates without changing the documented "any label = full validation pass" intent.

🤖 Generated with Claude Code

squid-protocol and others added 2 commits September 9, 2026 09:43
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]>
#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]>
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 172d349 into main Sep 9, 2026
31 checks passed
@squid-protocol
squid-protocol deleted the ci/2901-throughput branch September 9, 2026 14:14
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.

flaky: ReDoS "pre-fix pattern scales quadratically" timing ratios fail on shared macOS runners

1 participant