Skip to content

test(crawler): stabilize throttle spacing checks - #1519

Closed
WilliamK112 wants to merge 2 commits into
squirrelscan:mainfrom
WilliamK112:codex/per-host-throttle-test-1516
Closed

WilliamK112 wants to merge 2 commits into
squirrelscan:mainfrom
WilliamK112:codex/per-host-throttle-test-1516

Conversation

@WilliamK112

Copy link
Copy Markdown
Contributor

Summary

  • assert the sequential per-host delay using the median of four start gaps so one loaded-event-loop compression does not fail the suite
  • give every wall-clock spacing bound in the file more than a 2x margin while preserving the behaviors each test distinguishes
  • document why actual fetch starts can appear closer than their reserved scheduler slots

Closes #1516

Verification

  • bun test apps/cli/tests/crawler/per-host-throttle.test.ts — 6 passed
  • 10 consecutive full-file runs with 12 busy yes processes alongside — 10/10 passed
  • mutation check with sequential perHostDelayMs: 0 — failed as expected (9.5 < 20)
  • bun run --cwd apps/cli format:check — 547 files passed
  • oxlint -c oxlint.config.mjs tests/crawler/per-host-throttle.test.ts
  • bun run --cwd apps/cli typecheck
  • git diff --check

Checklist

  • I added or updated tests for behavioral changes.
  • I did not include secrets, customer data, or incompatible third-party material.
  • Every commit includes a DCO Signed-off-by line (git commit -s).

Docs: none. Skill: none.

@nc9

nc9 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Thank you William. We reviewed this: it is sound, and it gives the same results as the fix we had for #1516 under source mutations (no spacing, spacing removed, a smaller spacing, the Crawl-delay cap all turn the tests red) and stays stable under load. We will fold it into the next release with one small addition on top: a check on the total span first to last start, next to your median.

nik

nc9 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: 1e7aa76

Thanks William. Verdict: pending maintainer review. The change is small, test-only and reads correct, and it matches the maintainer note above (adopt it, plus a total-span check next to the median). "CLI tests" was cancelled at this head, so the new timing bounds have not run in CI yet.

Findings, most severe first:

  1. Medium: CI evidence missing. The "CLI tests" job shows cancelled and the golden tests were skipped, so the 10-of-10 runs under load (test: per-host throttle sequential spacing assertion is load-sensitive (27 ms against a 30 ms bound) #1516 criterion 3) is not shown. Please re-run and note the result.
  2. Medium: mutation check not stated (test: per-host throttle sequential spacing assertion is load-sensitive (27 ms against a 30 ms bound) #1516 criterion 2). The median lower bound is 0.4 x 50 ms = 20 ms against a ~5 ms fetch latency, so removing the delay should fail it, but please say you ran it with the delay set to 0.
  3. Low: the median hides a single compressed gap, so a scheduler that occasionally fires two starts back to back would pass. The planned total-span check (first to last start) covers this.
  4. Low: apps/cli/tests/crawler/per-host-throttle.test.ts (Crawl-delay cap test) raises the upper bound from 4000 to 5000 ms. That is reasonable under load, but the reason is not in the comment.
  5. Low: other assertions in the file (spread, Crawl-delay gap) now sit at 0.4 of the expected spacing, which is below the 2x margin asked for in test: per-host throttle sequential spacing assertion is load-sensitive (27 ms against a 30 ms bound) #1516 criterion 4 only if load delays a fetch by more than ~20 ms. Fine in practice, worth a one-line note.

Repo conventions: DCO sign-off present, no new dependency, no rule docs or CHANGELOG entry needed for a test-only change (changelog guard passes). Format, lint, typecheck, CodeQL, secret scan and docs pass.

nik

@WilliamK112
WilliamK112 force-pushed the codex/per-host-throttle-test-1516 branch from 1e7aa76 to e6c7dbe Compare November 1, 2026 18:23
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Updated head: e6c7dbe.

  • Rebased onto ccc06cb, so the rerun uses the new split CLI-test jobs from ci: the CLI tests job runs at the 25-minute cap and gets cancelled on large PRs #1518 instead of the 25-minute monolith.
  • Added the requested first-to-last total-span assertion next to the median.
  • Documented why the Crawl-delay cap test keeps a 5-second upper bound.
  • Full file: 10/10 consecutive loaded runs with 12 busy yes processes on the original implementation.
  • After adding the total-span assertion: the sequential case passed 10/10 with the same 12 busy processes.
  • Mutation rechecked with perHostDelayMs: 0: failed as expected, received 7 ms against the 20 ms lower bound.
  • Current full file passes 6/6 normally; format check, targeted lint, CLI typecheck, and diff check pass.

nc9 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Reviewed head: e6c7dbe

Thanks William. Verdict: pending maintainer review. Every point from the earlier review is now addressed in the diff and your notes. The only open item is that both "CLI tests" jobs were still running at this head when I looked, so the result under CI is not yet known.

Earlier findings, one by one:

  1. CI evidence: still open. "CLI tests (apps/cli and crawler)" and "CLI tests (rules, engine and the rest)" are in progress. The rebase onto the split jobs is what makes this check feasible, so please note the result once they finish.
  2. Mutation check: addressed in your notes (perHostDelayMs: 0 fails, 7 ms against the 20 ms bound). Consistent with the bound in apps/cli/tests/crawler/per-host-throttle.test.ts (median lower bound 0.4 x 50 ms).
  3. Median hides one compressed gap: addressed. The new first-to-last span assertion (apps/cli/tests/crawler/per-host-throttle.test.ts, sequential test, last hunk) requires at least 4 x 50 x 0.4 = 80 ms, so two back-to-back starts cannot pass while the rest stay on spacing.
  4. Reason for the 5000 ms upper bound: addressed by the new comment in the Crawl-delay cap test (still far below the uncapped 10 s).
  5. Margin on the other assertions: addressed. MIN_SPACING_FRACTION = 0.4 is a 2.5x margin, and the constant carries the rationale.

New observations, low severity:

  1. The sequential test uses the median of four gaps, which averages the two middle values (even count). That is fine, but a one-line note would help the next reader.
  2. Lowering every bound to 0.4 weakens the detection of a scheduler that spaces starts at only about 40 percent of the delay. The maintainer plan for test: per-host throttle sequential spacing assertion is load-sensitive (27 ms against a 30 ms bound) #1516 already accepts that trade-off.

Repo conventions: DCO sign-off on both commits, no new dependency, test-only so no rule docs or CHANGELOG entry needed. Format, lint, typecheck, CodeQL, secret scan, changelog guard and docs pass.

nik

@WilliamK112

Copy link
Copy Markdown
Contributor Author

CI is complete at e6c7dbe:

  • CLI tests (apps/cli and crawler): passed
  • CLI tests (rules, engine and the rest): passed
  • final required CLI tests: passed

All checks on the updated head are now green.

@nc9 nc9 mentioned this pull request Nov 1, 2026
@nc9

nc9 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Landed in v0.0.158 as d2007730, f4a8e937 via #1522. Thank you William for the throttle test fix. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.158

nik

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.

test: per-host throttle sequential spacing assertion is load-sensitive (27 ms against a 30 ms bound)

2 participants