Skip to content

Give Backend CI a timeout that is not the suite's runtime - #8286

Closed
danielhanchen wants to merge 1 commit into
mainfrom
ci-backend-timeout
Closed

danielhanchen wants to merge 1 commit into
mainfrom
ci-backend-timeout

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Backend CI jobs have been getting cancelled at a high rate across every open PR, and the cancellations read as fail in gh pr checks, so PRs look red for reasons that have nothing to do with their diff. #8274 currently shows 52 red checks and not one of them is a real failure.

The measurement

Every (Python ...) job across the last 14 Backend CI runs, by wall time and outcome:

outcome durations (minutes)
completed (success or failure) 14.1, 14.3, 14.3, 14.3, 14.4, 14.4, 14.4, 14.5, 14.5, 14.7, 14.8, 15.0, 15.0
cancelled 1.8 x4, 2.1 x4, 2.7 x4, 2.8 x8, 15.2 x8, 22.8 x4

The cancellations are bimodal. The 20 jobs under 3 minutes are ordinary supersede cancellations, a new push killing an in-flight run, and those are fine. The 8 at 15.2 are the job hitting timeout-minutes: 15.

The completed column is the real finding: every job that finished took between 14.1 and 15.0 minutes against a 15 minute budget. The median is 14.4. A job that runs 4% slower than the median dies, so which ones survive is close to a coin flip per run, and it is not interpreter-specific: 3.10, 3.11, 3.12 and 3.13 all sit on the same line.

That is why the same PR shows different red checks on each re-run, and why re-running "failed" jobs has not helped: gh run rerun --failed does not pick up a cancelled job at all.

The change

timeout-minutes: 15 to 30, on the pytest matrix and on Repo tests (CPU), which measured 13.4 minutes against the same limit.

This is the guard against a hung job, not a performance budget, and 30 minutes still catches a hang inside one CI cycle. Nothing else changes.

What this does not fix

A unit-test suite that takes 14.5 minutes is the actual problem, and this only stops it being scored as a coin flip. Worth doing properly afterwards: the matrix runs the whole of studio/backend/tests four times over, and pytest-xdist or splitting the slow modules out would cut it a long way. I did not want to put a behaviour change and a scheduling change in the same PR, and the timeout is what is blocking the queue today.

Verification

The workflow parses and both jobs read 30:

{'pytest': 30, 'repo-cpu-tests': 30}

No test or product code is touched, so the evidence that matters is this PR's own Backend CI going green without a cancellation.

Every (Python ...) job that finished in the last 14 Backend CI runs took between
14.1 and 15.0 minutes, median 14.4, against timeout-minutes: 15. A job 4 percent
slower than the median dies, so which ones survive is close to a coin flip and
it is not interpreter specific: 3.10, 3.11, 3.12 and 3.13 all sit on the line.

Cancelled durations are bimodal, 20 jobs under 3 minutes and 8 at exactly 15.2,
so the short ones are ordinary supersede cancellations and the 15.2 cluster is
this limit. gh pr checks reports a cancelled job as fail, which is why open PRs
show red checks unrelated to their diff and why rerun --failed does not clear
them: it does not pick up a cancelled job at all.

Raise both jobs to 30. This is the guard against a hang, not a performance
budget, and 30 still catches one inside a single CI cycle. Repo tests (CPU)
measured 13.4 minutes against the same 15, so it gets the same treatment.

The suite's own 14.5 minute runtime is the real problem and is not addressed
here.
@danielhanchen

Copy link
Copy Markdown
Member Author

This PR's own first run is the evidence.

job wall time pytest time outcome
(Python 3.10) 16.2 min 14:45 ran to completion
(Python 3.12) 15.5 min 13:54 ran to completion
Repo tests (CPU) 11.4 min success

Both matrix jobs ran past 15 minutes and finished. Under the old limit they would have been cancelled at 15.2 and reported as fail, exactly the pattern this PR is about, and nobody would have learned anything from either.

What they finished with is the two failures main is currently red on, test_route_start_refuses_a_diffusers_whose_lazy_submodule_cannot_import and test_route_start_refuses_training_when_diffusers_is_absent, both fixed by #8281. This branch is a workflow-only change off main, so inheriting those is expected and is not something to fix here.

One correction to the numbers in the description. I quoted the job durations, but pytest itself is 13:54 to 14:45 and the job carries roughly 1.5 minutes of checkout, Python setup and install on top. So the effective budget for the suite under the old 15 minute job limit was closer to 13.5 minutes, which the suite had already outgrown. The margin was smaller than the completed-durations table suggests, and that is consistent with cancellations being the common case rather than the rare one.

@danielhanchen

Copy link
Copy Markdown
Member Author

The full matrix has now reported, and it is a cleaner result than the two jobs I quoted above.

job wall time old 15 min limit
(Python 3.10) 16 min cancelled
(Python 3.11) 15 min cancelled
(Python 3.12) 15 min cancelled
(Python 3.13) 13 min survives
Repo tests (CPU) 11 min survives

Four of four ran to completion, and three of the four exceeded the old budget. So on this branch the previous configuration would have reported one verdict and three cancellations, which is the coin flip described in the body rather than a slow outlier.

All four fail on the same two tests main is red on, fixed by #8281. Nothing here is specific to this branch: it is a workflow-only change off main.

@danielhanchen

Copy link
Copy Markdown
Member Author

Since the description says the suite's runtime is the real problem and this PR does not touch it, here is the measurement, so the follow-up is not a guess. Full backend suite, CPU only to match CI, 716s.

The 60 slowest tests account for 259s, 36% of the run. There is no hot spot. The other 64% is roughly 20,000 tests at about 35ms each.

Worst modules, for completeness:

module sec tests in the top 60
test_diffusion_backend.py 56.7 15
test_tool_output_streaming.py 55.8 11
test_transformers_version.py 22.0 3
test_orphaned_children.py 20.5 3

That changes what the fix should be. Splitting the slow modules into their own job buys very little, because they are not where the time is. The lever is parallelism: pytest-xdist with --dist loadfile, so each file stays on one worker, which matters here because several of these tests bind ports, spawn servers and manage process groups. A runner has 4 CPUs, so 3 to 4x is the ceiling and 30 minutes would stop being close.

A second, cheaper option worth a separate decision: the matrix runs the whole suite on 3.10, 3.11, 3.12 and 3.13, and Repo tests (CPU) runs it a fifth time. Most of these are pure-python contract tests that cannot differ by interpreter.

Neither belongs in this PR. Recording it here so the 30 is understood as a floor rather than the answer.

@danielhanchen

Copy link
Copy Markdown
Member Author

Reading the red here by job conclusion rather than by gh pr checks, which collapses cancelled and failure into fail. Run 31336510033, gh api .../actions/runs/31336510033/jobs:

job conclusion wall clock
Repo tests (CPU) success 11m24s
(Python 3.10) failure 16m10s
(Python 3.12) failure 15m30s
(Python 3.11) failure 15m39s
(Python 3.13) failure 13m13s

The raised budget is already doing what it is for: 3.10, 3.11 and 3.12 all ran past 15 minutes and finished instead of being cancelled mid-suite, so for the first time all four interpreters report a verdict. The verdict is failure on all four, and it is the same two tests every time:

FAILED tests/test_diffusion_training.py::test_route_start_refuses_a_diffusers_whose_lazy_submodule_cannot_import
FAILED tests/test_diffusion_training.py::test_route_start_refuses_training_when_diffusers_is_absent
2 failed, 20095 passed, 124 skipped, 36 deselected

Those two are the pre-existing main breakage from #8236 and are unrelated to this workflow change. #8281 fixes them, and the two PRs are complementary: #8281 clears the failures but leaves 3.10 and 3.11 cancelled at 15m08s and 15m09s, and this one clears the cancels but leaves the four failures. I will merge main into this branch once #8281 lands so this can show all four interpreters green, then this is ready.

Worth recording separately: the suite is at 13 to 16 minutes and still climbing, so 30 buys time rather than headroom. The runtime itself needs its own look.

@danielhanchen

Copy link
Copy Markdown
Member Author

Superseded by #8281, which now carries this same two-line change.

Not because the measurement here was wrong, but because splitting it from the test fix meant neither PR could show a green Backend CI. This one lets all four interpreters finish and they then fail on the two tests #8281 fixes; #8281 fixes those and leaves the timeout, so a different interpreter is cancelled each run. Whichever went first had to be merged over a red check.

Leaving this open until #8281 lands, in case that ordering turns out to be preferable after all. Once it does, I will close this and the measurement stays on the record here.

The finding underneath is unchanged and still worth acting on separately: every job that finished took 14.1 to 15.0 minutes against a 15 minute budget, median 14.4, and pytest itself is 13:54 to 14:45 with roughly 1.5 minutes of job overhead on top. Raising the cap to 30 buys time, not headroom. The suite's runtime is the actual problem.

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