Repository navigation
test(execution): start the job-object tests on the real interpreter - #325
Merged
Merged
Conversation
Inside a Windows virtual environment sys.executable is the venv redirector, which starts the base interpreter as its own child in a job object of its own. Four tests put sys.executable in a job and read the job back from inside the child, so in a venv they read the redirector's job (limit flags 0x3000) and a one-process job refused the interpreter as a second process. They pass on a plain interpreter, which is why CI never saw it; CONTRIBUTING.md tells contributors to work in a venv. tests/support.py gains real_interpreter() (sys._base_executable on Windows, else sys.executable), used by _run_in_job and the brokered job-probe test, plus a test that the process started is the process that runs. The workers are unaffected: multiprocessing already starts the base interpreter directly in a venv. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dovvnloading
added a commit
that referenced
this pull request
Oct 17, 2026
…st (#327) The test failed intermittently under load ("expected to be called 1 times, but got 2"), on a loaded local machine and in CI on #325. The streaming bubble delivers text through useThrottledText's timer. The test clicked "Jump to latest" while the delivery of "more " could still be pending; when that delivery landed in the same act as the click, it ran after jumpToLatest had marked the reader as back at the end, so followStreamedOutput correctly followed it with an instant scroll, and the test counted two scrolls. Each step now waits until its text is in the bubble, so nothing is pending at the click. The test also checks one more thing than before: no scroll at all happens while the reader is scrolled away. The assertions on what it protects are unchanged: following is instant and only the reader's jump is smooth. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CONTRIBUTING.mdand the README tell contributors to work inpython -m venv .venv. Inside a Windows virtual environment four job-object tests fail, although they pass on a plain interpreter (which is what CI uses, so CI never saw it):tests/test_brokered_process.py::test_a_brokered_process_reads_back_the_job_it_was_placed_in(readslimit_flags12288 andactive_process_limit0 instead of the broker's job)tests/test_worker_isolation.py::test_a_real_job_carries_exactly_the_limits_it_was_giventests/test_worker_isolation.py::test_a_real_job_without_limits_is_only_kill_on_close(12288 instead of 8192)tests/test_worker_isolation.py::test_a_real_job_of_one_process_refuses_a_second(stderr: "Unable to create process using '...\Scripts\python.exe ...': Not enough quota is available to process this command.")Found while verifying the dependency refresh (#324) in a fresh venv.
Root cause
In a Windows venv,
sys.executableis the venv redirector (Scripts\python.exe). It starts the base interpreter as its own child, inside a job object it creates (KILL_ON_JOB_CLOSE | SILENT_BREAKAWAY_OK= 0x3000). The tests startsys.executable, attach that PID to the job under test, and then ask the child which job it is in:Measured in a venv: a child started from
sys.executablereported PID 8892 whilePopen.pidwas 25540; fromsys._base_executablethe two matched.The product is not affected. The backend never uses
sys.executable. The scratch, image and code workers are started throughmultiprocessing's spawn context, which already starts the base interpreter directly inside a venv (bpo-35797). The brokered path runs whatever argv the user approved.Change
tests/support.py:real_interpreter()returnssys._base_executableon Windows when it exists, andsys.executableotherwise. Outside a venv the two are the same._run_in_job(every real-job test intest_worker_isolation.py) and the brokered job-probe test startreal_interpreter(). Those children run only standard-library code (job_probe.pyimports nothing else, by design), so not seeing the venv's packages costs nothing.test_the_interpreter_the_job_tests_start_is_the_process_that_runs: the PID the child reports equalsPopen.pid. This pins the property the job tests rely on, and it runs on every platform.The other
sys.executablespawns in the suite (test_launcher.py,test_worker_containment.py, the remaining brokered tests) only check kill-on-close or exit codes. All 245 tests in the launcher and containment files pass in a venv unchanged, so they are left alone.Compatibility and rollback
Test-only change; nothing under
backend/,frontend/orcontracts/moves. Revert the single commit to undo.Checks
Venv used:
C:\Python314\python.exe -m venv --system-site-packages, soScripts\python.exeis the redirector and the packages are the same as the base run.main(00b76b0):python -m pytest -q, 4 failed, 3067 passed, 25 subtests passed. The 4 failures are exactly the tests above; nothing else fails only in a venv.python -m pytest tests/test_brokered_process.py tests/test_worker_isolation.py -q, 39 passed.py -3.12): the same two files, 39 passed.tests/test_launcher.py tests/test_worker_containment.pyin the venv onmain: 245 passed (no change needed there).win_jobs.pywas changed to setactive_process_limit = limits.active_processes + 1. In the venv, 5 tests fail, includingcarries_exactly_the_limitsandof_one_process_refuses_a_second. Before this change, the venv masked that defect behind the redirector's job.sys.executable. In the venv, the original 4 tests fail plus the new PID test (5 failed, 34 passed).python -m ruff check backend tests tools main.py app_factory.py scripts: all checks passed.python -m mypy: no issues in 98 source files (tests are outside mypy's scope by configuration).scripts/check.ps1, quick tier): all 11 checks passed in 471.3 s (backend tests 307.9 s, frontend unit tests 80.5 s).Security, concurrency, data loss
None. The children run a probe or a short standard-library snippet under the same job limits as before. Passing the venv path to them was ruled out on purpose: the brokered path strips the environment to
SystemRoot, and__PYVENV_LAUNCHER__would send the probe's own children back through the redirector.Limits
sys._base_executablecan be an app-execution alias. If that path does not exist as a file, the helper falls back tosys.executable, and the previous behaviour returns.tests/support.pyare covered by the hook's full run on the base interpreter.🤖 Generated with Claude Code