Skip to content

Unwedge Backend CI: one deadlocked test, and a timer that names the next one - #9515

Merged
danielhanchen merged 2 commits into
mainfrom
fix-backend-ci-hang
Aug 22, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix-backend-ci-hang

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Backend CI has been red on main for about forty hours and it blocks every open PR. One test deadlocks. The suite itself is fine.

The boundary

run sha (Python 3.13) job Backend tests step
last green 32385347777 b4240405d success, 10m17s 393s
first red 32385375389 caa0b7925 cancelled, 29m27s hung, cut at the then-30m cap
current main 32538719955 746ad086d cancelled, 45m15s hung, cut at the 45m cap

Seventeen seconds separate the last green run from the first red one, and exactly one commit sits in the gap: caa0b7925, "Studio: offer only the Codex models the ChatGPT plan can actually reach" (#9302).

What the measurement showed

A hanging test, not a suite that outgrew the wall, and not the dependency install.

The red job's own log settles it. Install backend test dependencies (CPU only) took 75s. pytest started at 00:01:32, finished collection at 00:02:43, and reached 95% of the suite at 00:08:05. Then it printed nothing at all for the remaining 37 minutes, until the job cap fired and the runner reported the word "cancelled".

Reproduced locally on the runner's shape (-n 4, same ignores and deselections), with a per-test timer added so a hang names itself:

tree tests wall timeouts
b4240405d last green 25986 passed 6m29s none
caa0b7925 first red 26040 passed 11m53s 1
this branch see below see below none

The 11m53s is 6m23s of real work plus one test sitting on a 330s timer. #9302 added 54 tests and no measurable time. The suite does its work in six and a half minutes against a 45 minute cap, so there is nothing here to split, parallelise further, or raise the limit for.

Where the fault is

The test, not the product code.

test_codex_proof_rollback_leaves_a_concurrent_save_alone starts one update_provider_config on a provider, parks it inside a stubbed remember_catalog_account on an asyncio.Event, and then awaits a second update_provider_config on the same provider before setting that event.

serialize_provider_config wraps that handler in a per-provider asyncio.Lock held for the whole call, and has since #9234, well before #9302:

async def _serialized(provider_id: str, *args, **kwargs):
    async with provider_config_guard(provider_id):
        return await handler(provider_id, *args, **kwargs)

So the second call cannot start while the first holds the lock, and the gate.set() that would release the first sits behind the second. The loop has no runnable task and no timer, parks in selectors.poll(None), and stays there. Confirmed directly: two coroutines through provider_config_guard("provider-x"), the first parked, and the second never runs.

I checked the retry path in openai_codex_client.py too, since it was the standing suspicion. It is sound and is not involved: _MAX_TRANSIENT_RETRIES is 2, the backoff is 2**attempt, _retry_delay_seconds clamps an upstream retry-after to 60s, and _retry_pause re-checks the cancel event every 100ms. Worst case is bounded and cancellable, and no test in the file drives a retryable status anyway.

The fix

The interleaved write now goes at providers_db.update_provider directly. That is what _restore_metadata actually defends against, since the route lock already forbids a second concurrent save on the same provider, and it is reachable by any other writer. Every assertion is unchanged, and the test still catches the bug it exists for: reverting _restore_metadata to restore the whole pre-request snapshot fails it in 1.24s.

The parked handshake is now an Event the stub sets, awaited with asyncio.wait_for(..., timeout = 10), instead of a hundred turns of asyncio.sleep(0) polling the private gate._waiters.

The guard

pytest-timeout was not a dependency anywhere in the repo. Backend CI now installs it and passes --timeout=330 to its pytest steps.

A timeout-minutes job cap names nothing. That is the reason this cost forty hours rather than one CI round: three separate PRs each carried a red (Python 3.13) at 45m14s, 45m15s and 45m16s, all reading "cancelled", which looks like a concurrency cancel and says nothing about which test is at fault. A per-test cap fails the test by name in the summary. The job cap stays as the backstop for a wedge the per-test timer cannot see, such as one during collection.

330s is taken off the measured distribution rather than picked for looking tidy. The slowest legitimate test in this suite is test_conversation_archive.py::test_the_newest_revision_survives_a_tied_run_LONGER_than_the_cap at 82.5s under -n 4 (75.4s serially), with 76s and 25s next below it, so the cap is 4x the worst real test and nothing in the suite is within reach of it.

repo-cpu-tests is deliberately left alone: I have no local measurement of its per-test distribution, and putting an unmeasured cap on a job that is currently green is how you trade one red for another.

…ext one

test_codex_proof_rollback_leaves_a_concurrent_save_alone drove two
update_provider_config calls at the same provider concurrently, with the first
parked inside a stubbed remember_catalog_account until the second one finished.
serialize_provider_config holds a per-provider asyncio.Lock across the whole
handler, so the second call could never start, and the await that would have
released the first sat behind it. The event loop then had nothing to run and no
timer to wake it, and the test never returned.

Backend CI has been red on main since that test landed. The step timings say the
suite was never the problem: the last green run finished "Backend tests" in 393s,
and the first red run reached 95% of the same suite in 5m30s and then emitted
nothing for the remaining 37 minutes before the job cap fired.

The interleaved write now goes at providers_db directly. That is the shape the
rollback actually defends against, since the route lock already forbids a second
concurrent save on the same provider, and the assertions are unchanged: reverting
_restore_metadata to restore the whole pre-request snapshot still fails the test.
The parked handshake is now an Event the stub sets rather than a hundred turns of
asyncio.sleep(0) and a read of Event._waiters.

Backend CI also gets pytest-timeout and --timeout=330 on its pytest steps. A job
cap reports "cancelled" and names nothing, which is what let this sit for forty
hours; a per-test cap fails the test by name in minutes. 330s is 4x the slowest
real test in the suite, test_the_newest_revision_survives_a_tied_run_LONGER_than_the_cap
at 82.5s, with 76s and 25s next below it.
…ls.py needs

A second break on main, which the hang above was hiding: the job never reached
the summary, so these two never reported.

#9411 added _is_imatrix_path to the import block at the top of routes/models.py
and to _dir_has_downloaded_model, without telling the two tests that stand in
for that module. test_export_absolute_paths builds a ModuleType for
utils.models.model_config and gets ImportError at the import block;
test_recommended_folders_has_model AST-extracts the real function into a
namespace it assembles by hand and gets NameError when the function runs.

The extracted-function test takes the real helper, the way it already takes the
real is_appledouble_metadata: importing utils.models.model_config costs 0.14s
and pulls in neither torch nor transformers, and a stub would let the exclusion
that function depends on regress unnoticed. The ModuleType double gets a lambda
beside its siblings, since export path discovery is what that file tests.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 43880d3586

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit af4d3b0 into main Aug 22, 2026
33 checks passed
@danielhanchen
danielhanchen deleted the fix-backend-ci-hang branch August 22, 2026 12:37
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