Fix 16 CI flakes in the tests, so a runner stall no longer changes their outcome

Merged
AD
19d ago
+252-55

Why we make these changes

After #12523, main still failed on tests that pass only when the runner is fast enough. This PR fixes four filed flakes and twelve more found in CI since, so that a runner stall no longer changes their outcome. Every change is in a test, a test helper or the coverage config; no library code changes.

One limit remains: the 3.13 CI job fails any test that runs past its 8 s per-test budget, so a stall longer than that still fails a test there. These fixes take speed out of a test's outcome below that budget, not above it.

Flakes fixed elsewhere are left out: #12713 duplicates #12708, which #12724 fixed; #12716 was fixed by #12793; #12717 was fixed by #13454; #12712 was fixed by #13566; the DBOS permissions flake was fixed by #13319; the real-bwrap coverage flake was fixed by #13376. #12715 needs a library change to run_stream(), so it moves to its own PR. The twelve unfiled flakes have no issue; each links the CI run it failed in.

New public surface

None.

User-visible behavior

None.

Verification

Each flake was proven by forcing its interleaving, not by rerunning. A scratch pytest plugin injects a stall, a clock jump or extra loop turns at the racy point. Every proof fails on main with the CI failure's error and passes on this branch, and each touched test module then passes unforced.

pyproject.toml omits tests/mcp_server.py from coverage: the #12718 fix runs it in-process, where coverage now sees it, but each test calls only some of its tools, and the stdio runs it also serves are not measured.

For the maintainer to decide

  • Merge by a maintainer. Shared test files change besides the failing test modules: the helpers tests/harness/render/runtime_live.py and tests/harness/code_mode/grpc_relay.py, tests/harness/gh_aw/conftest.py, the new tests/_timeouts.py, and the two modules on main whose copies of the timeout it replaces.
  • Not fixed: #12633 and #12969, which contributors have claimed. test_the_time_budget_fails_slow_tests_unless_marked (run) shares its cause with #13048, also claimed: pytester's SysModulesSnapshot.restore() iterates sys.modules in Python while another thread imports, giving dictionary keys changed during iteration. Forcing a thread to import inside that loop reproduces it on both tests; the importing thread in CI is not identified. The Windows test_native_text_copy fix is proven only against a fake subprocess.run, since no Windows runner was available. #12625 is the durable-exec job running out of its 15-minute budget, not a race in one test, so it needs the job's slow tests found first.
  • Network dependency, not fixed: the GPT-Live token-cap tests call tiktoken.get_encoding('o200k_base'), which downloads the encoding from openaipublic.blob.core.windows.net on first use in each process. That host timed out once on this PR (run), and in none of the 39 other recent failed CI runs. Removing it means caching the file in CI or faking the encoding, and either is a change of its own.
  • Product code still races on time: these tests are protected only by patching, and users can still hit both. LocalWorkspaceBackend's 5 s _SPAWN_GRACE raises a bare TimeoutError when a process start stalls past it. Docker's 2 s _STOP_TIMEOUT can cancel a timed-out command's stop before it removes its PID file. The OAuth callback server drops a connection that sends nothing for 5 s. run_copy gives up on a clipboard copy after 30 s without an error. The Render CLI's dev server (v2.29.0) maps a run outside its store's lock, so runs show can report completed with results: null.
Each flake: root cause and forced proof
IssueRoot causeFixForced on main, then on this branch
#12714 (run)An unclosed inner-pytest event loop sits in a cycle and is freed in a later test: Invalid file descriptor: -1The generated conftest closes the loop each inner session leaves behindSelf-pipe socket finalized before the loop: Invalid file descriptor: -1 at teardown, then pass
#12718 (run)A stdio server child misses the 5 s init_timeoutThe tests run tests.mcp_server in-process over one shared FastMCPTransport, with init_timeout at the 300 s hang guard6 s initialize stall: deadline exceeded, then pass
#12719 (run)A process start stalls past LocalWorkspaceBackend's 5 s _SPAWN_GRACEThe conformance tests patch it to 300 s: it runs in a shielded scope no test timeout can cut short, so a longer patch would let a real hang block CI6 s stall on one spawn: TimeoutError, then pass
#12720 (run)The first cold node start is paid inside the test's 8 s budgetA package-scoped started_node fixture, building on #1265910 s cold node: 11.3 s over budget, then pass
unfiled (run)test_a_timeout_is_stopped_even_when_the_configured_working_dir_is_gone: the shielded stop's 2 s _STOP_TIMEOUT cancels it before it removes the PID filePatch it to 300 s3 s stall before the stop: PID file left, then pass
unfiled (run)TestDetachedJobRoundTrip::test_start_check_stop waits for started, which the command printed before writing made.txtPrint started lastsleep 2 before the write: FileNotFoundError, then pass
unfiled (run)test_job_files_removed_while_waiting: the launcher's handle or the watcher's watch.trapped lands mid-rm -rf, so the job directory survivesThe command waits for both files before rm; status reads wait until the directory is goneLauncher stalled after launch.ready and an rm that waits before rmdir: output doesn't end in status.json, then pass
unfiled (run)test_nested_agents_run_as_lineaged_local_render_operations: the Render dev server can show a run completed with results: nullwait_for_run polls until a completed run has resultsFirst completed runs show torn: ValidationError, then pass (real render v2.29.0)
unfiled (run, run, run)test_native_remote_checkout_refusals and test_async_monty_sandbox_is_awaited on 3.11: the relay's wait_closed() doesn't wait for open connections, so a late client FIN leaves its transport openThe relay closes the connections it accepted and waits for them on stopClient close deferred past the test on 3.11: unclosed transport in both, then pass
unfiled (run)test_fallback_gives_each_model_a_fresh_deadline compared the fallback's time left with the clockCompare the fallback's deadline with the primary's0.15 s clock jump in the fallback: 0.0498 > 0.1 fails, then pass
unfiled (run)test_local_store_versions_do_not_repeat_after_delete_and_recreate[3]: the first Pixeltable test pays for starting its catalog inside the 8 s budgetA module-scoped fixture starts it9 s catalog start: over budget, then 9.7 s in shared setup and 0.1 s in the call
unfiled (run)test_shell_image_and_text_turns[True]: a 15 s fail_after ran out while the shell was still startingA 300 s hang guard16 s clock jump at plugin loading: deadline exceeded, then pass
unfiled (run)test_exchange_code_from_callback_survives_malformed_request_line: the callback server drops a connection silent for 5 s, giving ReadErrorPatch _CALLBACK_READ_TIMEOUT to 300 s5.5 s stall before the request: ReadError, then pass
unfiled (run)Windows test_native_text_copy: a cold PowerShell start passed the 30 s COPY_TIMEOUT, and the copy was droppedPatch it to 300 sFake subprocess.run timing out under 40 s: reads '', then pass
unfiled (run)test_idna_invalid_hostname_raises_model_retry: the SSRF check resolves the hostname with the runner's real DNS before httpx2 parses it, so a DNS failure raises firstStub resolve_hostname with a public addressgetaddrinfo failing: ValueError('DNS resolution failed ...') is not httpx2.InvalidURL, then pass
unfiled (run)test_cache_read_and_write_do_not_overlap_on_windows: a 1 s fail_after ran out while the read and write threads finished after the reader was releasedThe 300 s hang guard1.5 s stall in the writer's os.replace: deadline exceeded in the task group's exit, then pass

The #12720 cause is the one the forcing reproduces, but the CI log doesn't confirm it. Both parametrizations took about 11 s at once on different workers, and another test in the same job slowed from 0.4 s to 3.8 s, which points at a slow runner as much as at the cold start.

PR decisions
  • Test-side only. The run_stream() fix for #12715, the review-prompt changes and the timing rules for tests/AGENTS.md left this PR, so that every change here is a test change with its own forced proof.
  • #12719 is fixed test-side. An earlier version rewrote the conformance test's pid polling; patching the grace removes the dependence on speed without changing the shared conformance suite.
  • One hang guard. Every wait guard and patched product timeout here uses the 300 s READINESS_WAIT_TIMEOUT from tests/_timeouts.py, which replaces the two module copies of it on main. It is far beyond any runner stall, and a real hang still fails within five minutes. tests/_timeouts.py imports nothing, because tests/harness/code_mode/grpc_relay.py also runs inside Temporal's workflow sandbox.
### Checklist
  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.