Repository navigation
Conversation
b08a5d5 to
2db9f71
Compare
3225eaa to
eee2016
Compare
Agent loops that serve an external harness need to stop admitting model calls before the manager aborts inference, and reopen admission after it resumes; otherwise the abort cuts requests the harness is still waiting on. Add optional prepare_pause/resume hooks to AgentLoop, RouterAgentLoop and AgentLoopActor, and call them around pause_generation/continue_generation in both the colocated and disaggregated managers. A failed drain now prevents the global abort. Generalize the close helper into call_agent_loop_hook.
Drop the cancellation-proof cleanup helpers and the error-chaining machinery. The trainer closes managers through asyncio_run, which never cancels the cleanup, so await_cleanup, gather_cleanup and CleanupError guarded a path that does not occur. Close failures are now logged and no longer replace the training result. Also remove id()-based owner dedup and the optional-hook getattr guard, which cannot trigger, keep a single closing check in the sandbox loop, shrink the lifecycle doc to the extension contract, and revert formatting changes to untouched test lines.
2026-11-09 new-main compatibility checkValidated this PR independently against fixed upstream main Focused targets:
Result: 24 passed, pytest exit 0. Python 3.12.12, Torch 2.10.0, Ray 2.56.1, Transformers 5.17.0, existing LMDeploy 0.18.0 environment. This does not validate main's all-extra Ray 2.58.0 environment. ProduceBatchResult impact: this validation checks shutdown and pause/resume lifecycle behavior; no new changes to status, reward totals, counters or timing aggregation in this refresh. Ray concurrency impact: lifecycle behavior is tested locally, not under saturated cluster dispatch. These are targeted CPU/local-runtime checks, not a full-suite, GPU/PPO performance or CI-green claim. The unit-test check for this head was cancelled at the status inspection; cancellation is not a pass. Existing draft/readiness status is unchanged. |
|
Closing: trainer-exit cancellation and cleanup of running Agents are now covered on main by #2297 ( |
Problem
Resource-owning AgentLoops need explicit shutdown and pause/resume hooks. Otherwise background work and external clients can survive trainer exit, and a disaggregated producer blocked on generation can prevent shutdown.
Ray async concurrency groups also run on different event loops. Directly forwarding control RPCs to a loop that created generation tasks elsewhere can raise
Future attached to a different loopduring cancellation/draining. Moving control RPCs into the generate group instead would let saturated generation starve shutdown.Change
AgentLoop.close(), a no-op by default. Both RL trainers close training and evaluation managers on normal, error and cancelled exits. Managers forward hooks to local loops, Ray actors and router workers, and attempt every owner even if one fails. Close failures are logged; after otherwise successful training, the first close failure is raised. An existing training failure remains primary.finallyblocks to release pools.prepare_pause()andresume(). Managers drain beforepause_generation()and resume aftercontinue_generation(). A failed drain prevents inference abort.run_coroutine_threadsafe/wrap_future; same-loop calls await directly. Construction failures surface on the first RPC. No extra event-loop thread or generation-wide shield is added; local loops are unchanged.Contract:
docs/en/rl/agent_loop_shutdown.md.ProduceBatchResult impact:
group_gen_pause_time_snow covers the complete pause phase. Status, reward and produced-work accounting are unchanged by this follow-up.RoutedExperts impact: no change to object-reference transfer or ownership.
Ray concurrency impact: generation retains the named
generategroup; control RPCs retain the default group and dispatch directly onto the owner event loop without queuing for a generate slot.Test Plan
Latest follow-up (2026-11-13)
Six focused CPU tests passed on this PR branch:
Required
pre-commit run --all-filesexecuted: mypy passed on 409 source files and pydantic checks passed. Overall failure is confined to pre-existing formatting/import-order issues in six untouchedautotest/files; those automatic edits were discarded. All applicable changed-file pre-commit hooks pass.Earlier validation reported 86 passing lifecycle/trainer/producer tests; that broader set was not rerun for this follow-up. The latest test deliberately uses real Ray but no model server, live sandbox deletion or GPU training. No throughput benchmark was run: this follow-up corrects loop ownership and pause accounting, without adding model passes or per-token RPCs. Target-environment validation and clean upstream CI remain outstanding.