Skip to content

test: make the linear-scan timing tests hold on loaded CI runners - #8185

Merged
kovtcharov-amd merged 6 commits into
mainfrom
autofix/issue-8184
Nov 15, 2026
Merged

kovtcharov-amd merged 6 commits into
mainfrom
autofix/issue-8184

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Three "stays linear" tests timed a single call against a fixed or lopsided bound, so a busy Linux CI runner could push them over and block PRs that never touched shell code (seen twice on #8025). They now check how the time grows when the input gets 8x bigger: both sizes are timed back to back, best of several runs, so runner load slows both alike. A quadratic regression still fails.

Closes #8184

Test plan

  • python -m pytest tests/unit/test_shell_guardrails.py tests/unit/agents/test_unsupported_test_claim.py -k linear passes
  • python -m pytest tests/unit/ -x passes
  • python util/lint.py --all passes
  • Unit Tests (Linux, py3.12) is green on this PR
🔍 Technical details
  • Heredoc scan (TestHeredocCannotHideARefusedCommand::test_the_scan_stays_linear): it used to assert one call under 0.5 s. Now each shape is built at n=400 and n=3200 and timed interleaved, best of 5. The assert is big < 24*small + 5ms: linear gives ~8-9x, quadratic ~64x. At these sizes a quadratic clears the 5 ms floor on every shape that does real work; the $((…)) shape returns almost immediately at any size.
  • Test-runner detection (test_a_command_grown_and_launched_each_time_stays_linear): it timed detection once, against best-of-3 ast.parse. Now it compares 500 vs 4000 launches, interleaved best of 5 with GC paused, timing only the detector's walk (parse excluded). The assert is big < 24*small + 20ms: linear gives ~6-16x, the unbounded n²/2 ~64x. The found / no-warning / storm-only-is-False checks still run at the original 5000 launches.
  • Other _linear_bound users are unchanged; the issue named only these two tests.

Three linearity checks failed on busy Linux runners under xdist and blocked
PRs that never touched shell code. They now compare how time grows between
two input sizes, measured interleaved and best-of-N, so load slows both sides
alike while a quadratic regression still trips the ratio by a wide margin.

Closes #8184
# Conflicts:
#	tests/unit/test_shell_guardrails.py
CPython's parse of the f-string storm is itself super-linear, so on a loaded
Windows runner the 4x size step crossed the 9x bound with no detector change.
The growth check now excludes the parse, uses an 8x step (500 to 4000
launches) with best-of-5, and allows 24x: linear runs measure 6-16x, while a
per-launch re-read of earlier statements measures 40-68x and still fails.
@github-actions github-actions Bot added the tests Test changes label Nov 15, 2026
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Skill audit

Skill Verdict Claimed tier Cleared tiers Findings Rules
hub/agents/gaia/npm ✅ ALLOW experimental experimental 3 high body.injection.credential_request, body.injection.guardrail_bypass, body.injection.persona_override

✅ All audited skills cleared the tier they claim.

Per-finding detail is withheld here on purpose. Read it in the Security > Code scanning tab, or download the skill-audit-reports artifact from this run. Offending source text is withheld from CI everywhere — reproduce it locally with gaia skill audit <dir> --show-snippets.

@github-actions

Copy link
Copy Markdown
Contributor Author

Verdict: Request changes

🔴 The merge from main reverted another PR's tests, and one edited test will now fail on Linux. The merge commit kept this branch's older copy of the shell-guardrails test file. That throws away main's #8028 suite: multi-line commands are judged on POSIX and refused only on Windows. It also drops the gh_on_path fixture calls. The product code on main still has the #8028 behaviour, so the restored assertion is now wrong: it expects every multi-line command to be refused, but on POSIX they are offered once.

To fix it, take main's version of tests/unit/test_shell_guardrails.py and re-apply only the heredoc linearity change. The growth-ratio approach for the timing tests looks sound; the launch-storm change is fine as it is.

🔍 Technical details
  • git diff be41bea1e f7c4879e5 -- tests/unit/test_shell_guardrails.py shows 139 changed lines against main's parent. Only about 30 of them are the intended heredoc change.
  • TestOperatorsUnderBypass::test_shell_only_operators_are_never_run_unasked_by_default[ls\necho hi] now asserts TIER_REFUSE unconditionally. shell_tools.py refuses a line break only under the cmd dialect (_FIRST_LINE_ONLY), so on Linux the result is TIER_CONFIRM_ONCE and the test fails. Restore the first_line_only = "\n" in command and shell_tools._pipe_dialect() == "cmd" branch.
  • These were deleted:
  • Main already relaxed the heredoc test in test(shell): give the heredoc scan timing test room for a busy runner #8177 (fdb9b2838). This PR's growth-ratio version replaces that change, which is fine.
  • I couldn't run pytest in this environment because gaia and pytest aren't installed. The failure above comes from reading the code, not from a test run.

…owth test

The last merge from main kept this branch's older copy of the file, dropping
the multi-line command suite and the gh_on_path fixture calls.
@kovtcharov-amd kovtcharov-amd added the ready_for_ci Run CI workflows on draft PR without requesting review label Nov 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor Author

Verdict: Approve with suggestions

This makes the two flaky "stays linear" timing tests stable on busy CI runners. They now compare how the time grows when the input gets 8x bigger, instead of timing one call against a fixed limit. The change is tests-only and makes both tests sturdier and no weaker than before. Two small things are worth fixing:

  • The heredoc test misses a quadratic slowdown in its cheapest shapes. The fixed 5 ms allowance is larger than a quadratic blow-up would add to shapes that take well under a millisecond. It still catches the runaway backtracking it was written for, but the PR's claim that "a quadratic regression still fails by a wide margin" holds only for the slower shapes.
  • The PR description's technical details are out of date. They describe an earlier version of the test-runner change (1000 vs 4000 launches, best of 3, a 9x bound). The code now uses 500 vs 4000, best of 5, and a 24x bound.

Real-world evidence

N/A: this PR only changes tests, so this verdict comes from reading the code. pytest isn't installed on this review runner, so I couldn't run the changed tests. I did time a heredoc scan at both sizes: the near-identical copy in command_timeouts.py, because shell_tools can't be imported here without its dependencies. Those timings are the basis for the first point.

🔍 Technical details

Issues found

🟢 The 5 ms floor hides quadratic growth in the cheap heredoc shapes (tests/unit/test_shell_guardrails.py, test_the_scan_stays_linear). These are best-of-5 timings of command_timeouts._strip_heredoc_bodies (n=100 vs n=800):

shape small bound 24·small + 5ms if quadratic (64·small)
${OUT:-x}×n 0.23 ms 10.4 ms 14.5 ms ✅ caught
${a:-×n … 0.15 ms 8.7 ms 9.9 ms (barely)
$((((…)))) ~0 ms 5.0 ms 0.02 ms ❌ passes
$(×n … 0.09 ms 7.0 ms 5.4 ms ❌ passes
long names ×2 0.6–0.7 ms 19–22 ms 36–46 ms ✅ caught

Exponential backtracking is still caught, and the old 0.5 s wall-clock bound couldn't catch a quadratic either, so nothing is lost compared with main. Either drop the claim or tighten the test. Larger inputs keep the slack small relative to the measured time:

        small, big = make_command(400), make_command(3200)

(or lower the floor to + 0.001).

🟢 The PR body's 🔍 section describes superseded parameters. It still says "1000 vs 4000 launches, interleaved best of 3 … big < 9*small + 50ms … linear ~4x, n²/2 ~16x". The code in test_unsupported_test_claim.py (_growth_seconds / _assert_grows_linearly) does 500 vs 4000, best of 5, big < 24*small + 0.02. It also says the heredoc test went from "50 ms" to the new bound, but the removed assert was < 0.5 s. Please update the body so the merged record matches the code.

Checked, no action needed

  • The patch("gaia.agents.base.checks.ast.parse", return_value=tree) in _scan_seconds is correct. checks.py calls ast.parse once (line 1161), so the timing covers only the walk, as the comment says.
  • The correctness assertions (detection is True with a runner, False for the storm alone, no warning logged) still run at the original 5000 launches.
  • _linear_bound still has other callers, so leaving it in place is right. time is still used in test_shell_guardrails.py.

Strengths

  • Growth-ratio testing with interleaved best-of-N timing is the right fix for load-sensitive timing tests. It keeps the regression signal and stops runner load from causing false failures.
  • Pausing GC during the AST-walk timing addresses a specific cause of noise the author measured, and the reason is given in one comment line.
  • The scope is tight: only the two tests named in Linear-scan timing tests fail on loaded Linux CI runners #8184 changed.

@kovtcharov-amd kovtcharov-amd added ready_for_ci Run CI workflows on draft PR without requesting review and removed ready_for_ci Run CI workflows on draft PR without requesting review labels Nov 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor Author

Verdict: Approve

This PR fixes three flaky "stays linear" timing tests. They now check how the scan time grows when the input is 8x bigger, rather than comparing one run against a fixed time limit. Both sizes are timed back to back and the best of 5 is kept, so a busy runner slows both sizes alike, while a quadratic slowdown (~64x) still fails the 24x bound. It only touches tests, the original correctness checks still run at full size, and I found nothing blocking.

Real-world evidence

N/A: this PR changes tests only. There is no evidence bundle, and nothing user-facing changed that could be run. The verdict rests on reading the code alone. I could not run the tests here because pytest isn't installed in this review sandbox, so the PR's own CI run is what shows them passing.

🔍 Technical details

Issues found

🟢 Parsing is patched out of the timing, so a re-parse regression wouldn't show (tests/unit/agents/test_unsupported_test_claim.py:1340). _scan_seconds patches checks.ast.parse to return a tree that was parsed in advance. That keeps CPython's super-linear f-string parse out of the timing, which is the point. The cost: if _detect_test_runner someday re-parsed per launch, each of those calls would return the cached tree for free, and the test would stay green. There is one ast.parse call in checks.py today (line 1161), so this is fine for now. Worth a word in the comment so nobody relies on it to catch that case.

🟢 The $((…)) heredoc shape can't catch a regression (tests/unit/test_shell_guardrails.py:1302). That shape returns almost at once at both sizes, so the 5 ms floor is the whole bound. The PR description says this openly. Either drop the shape from this test or keep it as a smoke check only.

🟢 The heredoc test leaves GC running. The detection test pauses GC during timing; the heredoc test doesn't. The heredoc strings are small, so the risk is low, but pausing GC there too would make the two tests consistent.

Strengths

  • Each round times the small and large inputs back to back and keeps the best of 5, which cancels most runner load. The 24x bound leaves wide room on both sides of linear (~8x) and quadratic (~64x).
  • The behaviour checks (runner found, no warning, a storm with no runner returns False) still run at the original 5000 launches, so the change loses no correctness coverage.
  • The scope matches Linear-scan timing tests fail on loaded Linux CI runners #8184: the other _linear_bound users are untouched, and the PR says so.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit b09adcf Nov 15, 2026
45 of 53 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the autofix/issue-8184 branch November 15, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready_for_ci Run CI workflows on draft PR without requesting review tech debt tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linear-scan timing tests fail on loaded Linux CI runners

1 participant