Repository navigation
Close the agentic round's loop and recorder server; node lease tests see no host processes - #926
Open
michaellchung wants to merge 1 commit into
Open
michaellchung wants to merge 1 commit into
michaellchung wants to merge 1 commit into
Conversation
… processes AgenticRound.close() stopped its event loop but never closed it, and the records proxy recorder's aiohttp server on that loop kept its listening socket and any request still in the engine (aiohttp does not cancel a handler whose client left). The garbage collector later destroyed the pending handler tasks wherever it ran, and asyncio logged "Task was destroyed but it is pending!" into that test's log capture: test_fabric_groups' caplog assertions failed after test_agentic_compaction_switch ran in the same shard. close() now cancels what is still pending on the loop, stops the recorder's server (when the recorder has aclose), shuts down async generators and closes the loop. A second close returns at once (it used to block on the stopped loop). The trials are still cancelled and given CLOSE_WAIT_S first, so a cancelled trial's cleanup runs before the loop closes, and a failure to stop the recorder does not fail the close. test_node_lease's probe scanned the host's real process table, so a venv sampler marker left by another test process on the same host (yeto-ssh-sampler:run-a:...) showed up as sampler:<pid> in five tests. The fake node PATH now has a ps that lists only the processes a test writes to ps.txt, plus the probe itself. 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.
Summary
Two tests failed depending on what else ran on the host or in the same shard. One root
cause is in product code (
AgenticRound.close); the other is in a test helper.test_fabric_groups: asyncio log records from an earlier test
test_fabric_groupsasserts on its log capture (caplog.records == [fg.HINT]). In theshard it shares with
test_agentic_compaction_switch, a garbage collection inside afabric test destroyed tasks that the agentic tests had left pending, and asyncio logged
Task was destroyed but it is pending!(aiohttpRequestHandler) into that capture. Aleak detector (a
gc.collect()after every test, with asyncio log records, unraisableexceptions and ResourceWarnings recorded) found the source: every agentic round left an
unclosed event loop and the recorder server's listening socket, and a round closed during
a summary turn also left that pending handler task. No other test in the shard leaked
asyncio objects. The warning is fixed where it starts, not filtered in test_fabric_groups.
test_node_lease: the probe saw other tests' processes
still_runs_scriptscansps -eo pid=,args=for venv sampler markers. The tests ran itagainst the host's real process table, so a
yeto-ssh-sampler:run-a:...process left byanother test process on the same host showed up as
sampler:<pid>in five tests(
test_the_probe_finds_trainer_process_groups_and_venv_samplers, the docker and podmanview tests). The fake node PATH (
_node_bin) now also has a fakeps. It lists the rowsa test writes to
ps.txt, plus the probe's own shell (so the "the probe never findsitself" check still holds). The venv-sampler test writes its samplers there instead of
starting a real process.
Product change: AgenticRound.close (engine sampler, agentic rounds)
Scope:
yeto/rl/engine/agentic_round.pyonly.LoopThread.close()andAgenticRound.close()changed; a helperLoopThread.cancel_pending()was added.Before:
LoopThread.close()stopped the loop and joined the thread. It never closed the loop.Pending tasks and the selector stayed alive until the garbage collector found them.
AgenticRound.close()never stopped the recorder's aiohttp server, which runs on thatloop. Its listening socket stayed open, and so did a request still in the engine
(aiohttp does not cancel a handler whose client left).
AgenticRound.close()blocked forever, becauserun_coroutine_threadsafeonthe stopped loop never returns.
After, in this order:
CLOSE_WAIT_S(2 s) to end. Acancelled trial's own cleanup on the loop still runs to its end before anything below.
aclose(ProxyTokenRecorder), cancel what is stillpending on the loop (the leftover recorder requests), then stop the recorder's server,
bounded by
CLOSE_WAIT_S. A failure here is swallowed, and the loop still closes.close_pools_now). Its error stillpropagates to the caller, as before.
LoopThread.close()cancels the remaining tasks (bounded, 2 s), shuts downasync generators, stops the loop, joins the thread and closes the loop. It does
nothing if the loop is already closed.
AgenticRound.close()returns 0 at once.Impact:
round_factory) callsclose()once, at the endof the sampler run (
engine_sampler). What happens before it is unchanged: rounds,drains, the live and drain weight switches, the infra retries. At the end, the
recorder's port is released and the loop is closed, where before they lingered until
the process exited.
a socket and the default executor's threads.
close()already stopped theloop at the same point. The new steps run only inside
close(), after the trials werecancelled and waited for.
main.
New tests (
tests/test_agentic_compaction_switch.py):close()writes the samples, stops the recorderserver (its port refuses connections), closes the loop, emits
rl_agentic_closeonce,and a
gc.collect()afterwards logs nothing from asyncio. Beforeclose(), the loop isopen and the server answers (nothing closed early).
for the collector.
loop closes.
acloseraises does not failclose(), and the loop isclosed. A
close_pools_nowerror still raises, and the loop is closed anyway.close()returns 0 and changes nothing: the pooled sandboxes are not deletedagain,
rl_agentic_closeis not emitted again, and no coroutine is handed to the closedloop (no "never awaited" warning). Before this change it blocked.
LoopThread.close()cancels a pending task, closes the loop, can be called twice, andleaves nothing for the collector.
Verification
Fault injection was done with local-only pytest plugins; none of it is in this PR.
collection runs at the start of each output-sensitive fabric test (inside its log
capture), after the agentic close tests. Old code: 20/20 iterations failed
(
['Task was destroyed but it is pending! ...'] == [HINT]). New code: 200/200iterations passed (the agentic close tests and the four fabric tests in each).
CPU load: 200/200 passed.
pswrapper first on the pytest process's own PATHadds another test's
yeto-ssh-sampler:run-a:row to full listings (nothing runs on thehost). Old code: the same five tests failed. New code: 200/200 iterations of those
five passed. CPU load: 200/200 passed.
agentic_round(23 files), plus test_fabric_groups andtest_node_lease: 887 passed, 22 skipped, with
-W error::RuntimeWarning.test_fabric_groups run): no second-close guard; no recorder stop; no
loop.close();no early return of
LoopThread.close()on a closed loop; no task cancel inLoopThread.close(); no cancel before the recorder'saclose; anacloseerror notswallowed; the recorder stopped before the trials were waited for; the loop closed
without
shutdown_asyncgensand without the join check. All 9 are caught.examples/k31dry-runs (run up --dry-runof both run configs with their preflight logs, and the pool--dry-run)are identical line by line to origin/main after normalization.
Not changed: tests/test_bulk_resend.py
A timing failure under load was reported for this file, without the test name or the
assertion. It did not reproduce: 3 runs of the file under CPU load, one with every push
delayed 25 ms and one with a niced syncer all passed. The margins measured: merges during
the gate were 239 to 352 against the 10 required; late merges 127 to 184 against 5; the
replay-tail backlog 151 to 197 against more than 0; merge rate 26 to 35/s against one
merge each second. The assertions that depend on wall time are: the inline cases
(
during == 0from 0.5 s into the gate,late == 0in its second half), the backgroundlower bounds after a fixed
GATE_Ssleep, "a second without a merge", and the 90 sreplay window. They are left as they are: without a failure to aim at, a change could not
be checked with the failing-injection and 200-iteration protocol (one run of the file
takes 4 to 5 minutes).
🤖 Generated with Claude Code