Repository navigation
testing: wait for cards as long as it takes, and ask only for what a command needs - #459
Conversation
…many as a command needs The owner's rules of 2026-11-26: never give up on cards; never name cards, ask for the number a command needs; no reserve. This implements the first two in demand mode. Wait. IMX_GPU_WAIT no longer has a default, so `gpu run` is given no `--wait` and queues the command until it gets its cards. The runner's timers and watchdog now start when the scheduler grants them (`_await_grant` reads the side log once a second): timed from the spawn, a command queued for two hours was killed by its own timeout in the queue. The side log is cleared before the spawn, since a grant recorded by the previous attempt would end this one's wait before it began. The log says that a command is queued and, once granted, how long it waited. A refusal is not a wait: the process exits and the log says `not run` as before. The GPU lock keeps its bounded wait on purpose: a run holding it may sit in the queue for hours, and an unbounded wait behind it would stall an agent's session without a word. Need. The module wrapper and the agents' run_pytest/reproduce asked for one card, where every earlier cycle showed a module's tests four. A test that needs more failed: tests/diffusion/models/hy_nomas/test_pixelumm_parallel.py spawns 2 and 4 processes, with no cards_N marker and no guard. A command's count is now what it needs: a cards_N in its own -m expression, else the largest number declared by the tests it names at its run level, through a cards_N mark or a decorator's num_cards=. Tests of another level do not count; they skip by their own guard when the cards are not there. The declaration is read with the ast module, because names inside strings are not needs (the target repository's own tests quote CI commands that say cards_8), and only test directories inside the repository root are walked: a test whose root was `/` said `cd /tmp`, and the whole of /tmp was read. The result is kept for five minutes, since agents edit tests as they work. Cap. `tests/e2e --run-level advanced_model` declares eight cards: with an unbounded wait such a command might never be served. IMX_GPU_MAX caps what one command asks for; a test that declares more skips by its own guard, as it did whenever four cards were visible. The launcher sets it to four. Still bounded: a test an agent starts synchronously in run_shell waits at most half of that tool call's timeout, which the harness sets.
command_gpus took the largest `cards_N` it could find in the whole command, so `not cards_2` read as two cards. Seen in the running campaign: the scheduler module's agent ran `tests/distributed/ -m 'core_model and cuda and L4 and not cards_2'` and asked for two; the repository's own CPU job, `core_model and cpu and not (cards_2 or ... or cards_8)`, would have asked for eight. The -m expression is now parsed: `not` applies to the term that follows it or to a bracketed group. Counts it selects are the need; counts it negates are left out of what the selected tests declare.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2ca822efcf
ℹ️ 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".
| # the queue lines are the runner's, not this attempt's evidence | ||
| try: | ||
| attempt_offset = log_file.stat().st_size |
There was a problem hiding this comment.
Preserve test output produced before the grant poll completes
In unbounded demand mode, the test starts running as soon as the scheduler grants its cards, but _await_grant can take another second to observe that grant. Resetting attempt_offset to the current log size therefore excludes actual test output, not just the runner's queue messages. A command that immediately prints CUDA out of memory and exits zero now returns rc=0, leaves watchdog_triggered=False, and creates a pass marker; I reproduced this with the scheduler stub. Keep the original attempt boundary or otherwise exclude only runner-generated messages so early fatal output remains visible to the watchdog.
Useful? React with 👍 / 👎.
| rc, wd_hit, timed_out = self._spawn( | ||
| self._command(job, job.command, side_log), job, run_env, | ||
| log_file, append=True) | ||
| log_file, append=True, queue=queue) |
There was a problem hiding this comment.
Apply grant-aware timing to the coverage fallback too
When pytest rejects --cov, the fallback calls _spawn without queue, even though _command wraps that retry in another unbounded scheduler request. Consequently, the retry's timeout starts while it is still waiting for cards, undoing the new behavior for installations without pytest-cov. With the scheduler stub, a two-second job whose fallback queues for four seconds returns timeout status 124 without executing the fallback test. Pass the queue information through the fallback path as well, including clearing the previous attempt's grant record.
Useful? React with 👍 / 👎.
| command and its tests say, never the caller's `minimum`. | ||
| """ | ||
| command = command or "" | ||
| selected, excluded = _expression_cards(_option(_words(command), "-m") or "") |
There was a problem hiding this comment.
Parse pytest markers after the interpreter's module option
For python -m pytest ... -m 'core_model and cards_4', _option(..., '-m') returns pytest, so the explicit card selection and exclusions are ignored. These options have different meanings: python --help describes -m mod as “run library module as a script,” whereas pytest --help defines -m MARKEXPR as the test marker filter. This affects the module wrapper directly because module_pytest.main normally constructs commands beginning with python -m pytest; it can request cards for excluded tests or infer only one card when a different run level is selected through the marker expression. Parse the pytest argument segment rather than taking the first -m in the whole shell command, and use the same parsing in _run_level.
Useful? React with 👍 / 👎.
Summary
Two commits that implement the owner's rules of 2026-11-26 for demand mode (
IMX_GPU_MODE=demand, #455): wait for cards for as long as it takes, never name cards, ask only for as many as a command needs, and no reserve. Nothing changes outside demand mode.Wait (e1f5fc0).
IMX_GPU_WAIThas no default any more, sogpu runis given no--waitand queues the command until it gets its cards. The runner's timers and watchdog start when the scheduler grants them (_await_grantreads the side log once a second). Timed from the spawn, a command queued for two hours was killed by its own timeout in the queue. The side log is cleared before the spawn, since a grant recorded by the previous attempt would end this one's wait before it began. The log says that a command is queued and, once granted, how long it waited. A refusal is not a wait: the process exits and the log saysnot runas before.The GPU lock keeps its bounded wait on purpose. A run holding it may sit in the queue for hours; an unbounded wait behind it would stall an agent's session without a word, where a lock timeout is feedback it can act on.
Need (e1f5fc0, 2ca822e). The module wrapper and the agents'
run_pytest/reproduceasked for one card, where every earlier cycle showed a module's tests four. A test that needs more failed:tests/diffusion/models/hy_nomas/test_pixelumm_parallel.pyspawns 2 and 4 processes, with nocards_Nmarker and no guard. A command's count is now what it needs:cards_Nits own-mexpression selects (its largest); one the expression negates is an exclusion, not a need;cards_Nmark or a decorator'snum_cards=. Tests of other levels and of excluded counts do not count: they skip by their own guard when the cards are not there. A test that declares nothing needs one.The declaration is read with the
astmodule, because names inside strings are not needs (the target repository's own tests quote CI commands that saycards_8), and only test directories inside the repository root are walked. The result is kept for five minutes, since agents edit tests as they work.Cap (e1f5fc0).
IMX_GPU_MAXcaps what one command asks for. It is not set by this repository: the campaign's launcher sets it to four.Evidence
core_model, read from the target repository's tests: one card for the worker_runner, input_output, online_serving and model_config suites; four for the full runs of model_executor, scheduler and platform (196 files declare one card, 14 two, 6 four).tests/e2e --run-level advanced_modeldeclares eight cards: the whole machine. With an unbounded wait such a command might never be served, hence the cap.tests/distributed/ -m 'core_model and cuda and L4 and not cards_2'asked for two cards, and the repository's CPU job (core_model and cpu and not (cards_2 or ... or cards_8)) would have asked for eight.Validation
Offline, on head
2ca822ef:test_gpu_demand.py(82) uses a stand-ingpuexecutable and covers: the unbounded wait with the test timed from the grant (4 s in the queue, a test allowed 2 s, runs to its end), the bounded wait and its skip, a refusal, the lock keeping its default wait, the need read from decorators, module and class marks, a per-platformnum_cards, strings ignored, other run levels ignored, exclusions, the cap, and the cache./and whose command saidcd /tmphung: the first version walked every directory a command named. It now walks only test directories inside the root, at most 4000 files.tools/check_doc_links.py,tools/check_doc_citations.py,tools/check_spec_freshness.py --strict, both knowledge linters: clean.Real execution: none of this has run against the real scheduler yet. The campaign it was written for runs the same code since 10:13 on 2026-11-26, but every test request it made since was for one card, and its engine process still carries the old 30-minute bound until its next restart.
Notes for review
cards_N, nonum_cards=, no skip guard) still fails with one card;test_pixelumm_parallel.pyis the one known. A marker in that repository's tests is the fix, not a change here.run_shellstill waits at most half of that tool call's timeout, which the harness sets.testing.md,engine/steps/rebase_v3.md,rebase_engine.md.