Skip to content

[Feature] Isolate Agent sandbox trials and add bounded exit recovery - #2313

Closed
Wuyh11 wants to merge 27 commits into
InternLM:xs1997zju/agent-rl-stack-20261111/06-valid-attemptsfrom
Wuyh11:wuyihao/agent-rl-sandbox-cleanup
Closed

Wuyh11 wants to merge 27 commits into
InternLM:xs1997zju/agent-rl-stack-20261111/06-valid-attemptsfrom
Wuyh11:wuyihao/agent-rl-sandbox-cleanup

Conversation

@Wuyh11

@Wuyh11 Wuyh11 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Agent RL sandbox cleanup — integration map

Review each repository against its stated dependency. These are companion changes, not three independently complete cleanup implementations.

Validated runtime combination: XTuner 9735a334, Lagent 6680c358, CRG 35d91eb5. Keep Draft.

Test-source exclusion update: Current delivery heads: XTuner f7554574, Lagent 3a694e7e, CRG f00cc0a2. The confirmed 29 cleanup-owned test/script/fixture changes (XTuner 12, Lagent 5, CRG 12) have been reverted to their respective direct stack baselines; pre-existing baseline tests are preserved. All 33 latest local test copies, including 4 previously untracked files, are archived outside the delivery repositories. Runtime and documentation contents are byte-identical to the preceding heads; this is a test-only scope reduction, not a new experiment run. By the user's explicit scope choice, #2299 alignment is deferred: XTuner's current GitHub comparison still shows 15 inherited upstream-stack test files, outside these 29 cleanup-owned files.


Agent tasks can leave sandboxes allocated when task execution, creation, Ray shutdown or the Driver fails. Run each sandbox task in its own CPU process and retain durable run-owned records so normal finalization, bounded exit recovery and a limited background recycler can reclaim known resources.

Review scope and dependencies

This is the cleanup layer above #2299; configured base remains xs1997zju/agent-rl-stack-20261111/06-valid-attempts. Published head: f7554574. Review the cleanup-only delta from validated base e42ad7b4.

Base alignment pending: #2299 has since moved to 2c9ccbfe through a rewritten/rebased stack. GitHub currently reports merge conflicts. The complete current PR diff therefore is not a cleanup-only comparison. This publication preserves the tested runtime; it does not include an unvalidated rebase. Resolve that alignment and rerun compatibility checks before Ready.

Review units: 7e3bde25 / d6a0677a establish durable exit/recycler ownership; 5e91217e adds independent task processes and consolidates lifecycle/review fixes; 9735a334 hardens final-close retries, FD handling and business/outer timeout validation. Intermediate commits are review units, not independently accepted integration versions.

Changes

  • AgentInSandboxLoop dispatches complete infer→verify work to a reconstructable private Python process. Parent actors retain model services and shared creation permits. After cooperative cancellation expires, terminate only the task process group, confirm exit and recover that task's exact manifest; never kill a shared actor for one timed-out task.
  • SandboxLifecycle owns allocation intent, exact IDs, same-name acquisition serialization, dependency rollback, phase release, final sealing and failed-cleanup handoff. Final close retries incomplete steps; business errors and cancellation remain distinct from cleanup results.
  • CleanupJournal records known ownership durably; confirmed deletion or exact-ID 404 clears it. Linux OFD record locks replace BSD flock for the validated GPU/GPFS domain. Protocol headers reject incompatible old lock namespaces; old runs require offline recovery with matching tools after all owners stop.
  • On exit: stop creation admission → drain tasks → bounded sweep → persist remaining work. Passive Driver/optional peer observers and a Ray-shutdown guard invoke the same exit path; normal training does not periodically scan all journals.
  • One recycler per run processes bounded immutable request generations with limited concurrency/backoff. Exhausted work stays durable and ancestor requests do not receive unlimited renewed budgets. Defaults remain 8 workers, 6 rounds, 2–60 second backoff, 30 seconds/round and 600 seconds total.

Code entry: agent_in_sandbox_loop.py, trial_process.py, trial_channel.py, lifecycle.py, cleanup.py, locking.py, run_control.py, recycler.py, supervisor.py, runner.py and both Trainer exits.

Validation

  • Real Qwen3.6-35B-A3B inference on two nodes, each with 8 H200 GPUs in llmagent_gpu; sandbox project ailab-llmit, identity wuyihao.p. Each point used at least 8 real resources. No optimizer updates; this is two 8-GPU inference deployments, not 16-GPU distributed-training acceptance.
  • 64/66 cleanup points passed. All 608 unique sandboxes were independently confirmed deleted: 592 automatically, 8 by the external product CLI after deliberately killing every in-job recovery process, and 8 by exact-ID safety deletion for I07. The latter is a failed automatic-recovery case, not a pass. All GPU allocations and owned model aliases were released.
  • Repeated the 39 original points and 15 supplemental points, then added 5 cross-GPU-node and 7 isolated-process/creation-window points. Coverage includes normal/error/cancel/timeout, phase changes, DELETE failures/backoff, worker/driver termination, blocked Ray shutdown and actual rjob stop. Cross-GPU-node active-owner protection, crash takeover and competing recovery all passed.
  • CyberGym and TerminalBench exercised continuous rollout→native verify. DeepSWE exercised real inference exits and native verifier replay with an existing real patch; replay is not fresh continuous solve→verify. Search/tooluse were excluded because the selected paths do not allocate sandboxes. Task reward was not the cleanup acceptance criterion.
  • Runtime files in these commits match the frozen experiment snapshot. The cleanup delta now excludes all 29 cleanup-owned test scripts, fixtures and regression changes relative to its direct stack baselines; current local test copies are archived outside the delivery repositories. Existing baseline tests are retained. Reported test results describe execution against the retained local suite, not a fresh-checkout CI result. Latest recipe regression: 170 tests + 95 subtests; earlier component rounds are recorded separately, not summed as a newly rerun suite. Ruff 0.9.10, whitespace and Python 3.10 syntax checks passed; full repository hooks/CI and optimizer-update training are not claimed.
  • Common test recycler settings: concurrency 8, 6 rounds, 2-second initial backoff, 20-second cap, 45 seconds/round, 240 seconds total; individual fault points used explicit shorter settings. Product defaults remain 8 / 6 / 2 / 60 / 30 / 600. This is not acceptance of the default 600-second budget.

Known limits and normal-training impact

The two failed injections do not lie on the current standard training entry's normal path. They remain real recovery limits, not evidence of a universal no-leak guarantee:

  1. S13 — control-container ↔ GPU mount-domain locking. A control-container observer entered provider resolution for 8 active GPU-owned journals. A test guard blocked every DELETE; original owners then deleted their resources normally. The standard recipe launches the Driver and its local observer in the GPU environment; merely submitting jobs or reading logs from the control container does not invoke recovery. Tested GPU↔GPU protection/takeover passed. Do not run online recovery from the incompatible control mount; external recovery must use the validated GPU/storage domain or first independently establish that every relevant owner has stopped. Otherwise active resources could be deleted and tasks interrupted. The storage bridge's exact cause is not yet located.
  2. I07 — create response received before ID persistence. The test paused 8 successful create responses before the allocation callback, then SIGKILLed the private workers. After foreground recovery and six background rounds, journals still said creating with no IDs, so recovery could not locate these 8 resources. Only their separately audited exact IDs allowed safety deletion. Ordinary successful execution continues into the callback and records the ID; cooperative cancellation is covered separately. Abrupt termination in this narrow window can leak sandbox quota, and accumulated leaks can affect subsequent allocation. The injected window was widened deliberately; its natural occurrence rate was not measured. Resolving it requires a durable create identity plus platform-supported exact lookup/idempotency.

All in-job recovery executors disappearing still requires an external executor. LocalhostRunner, tools bypassing Pool, full-node power loss, throughput/peak-memory acceptance and full optimizer-update training are outside this delivery's completed acceptance.

Reviewer guide and review report

The static review predates the two fault-injection findings; the current limitations above take precedence. No automatic merge.

Codex and others added 13 commits November 11, 2026 12:18
Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.
Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.
Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.
…nces

Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.

Review commit only: protocol, affinity, lifecycle, Trainer guards and cold-start wiring form one atomic core merge group. Do not enable or merge this intermediate commit alone.
Trie traversal overlaps existing InternLM#2252; preserves InternLM#2257 request-aware reference rules rather than replacing the file.
…rriers

Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.

Review commit only: protocol, affinity, lifecycle, Trainer guards and cold-start wiring form one atomic core merge group. Do not enable or merge this intermediate commit alone.
Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.

Review commit only: protocol, affinity, lifecycle, Trainer guards and cold-start wiring form one atomic core merge group. Do not enable or merge this intermediate commit alone.
Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.

Review commit only: protocol, affinity, lifecycle, Trainer guards and cold-start wiring form one atomic core merge group. Do not enable or merge this intermediate commit alone.
Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.

Review commit only: protocol, affinity, lifecycle, Trainer guards and cold-start wiring form one atomic core merge group. Do not enable or merge this intermediate commit alone.
Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.
Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.
Existing InternLM#2257 tests/docs retained centrally; no equality burden on individual review commits.
Wuyh11 and others added 11 commits November 17, 2026 12:59
Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.
Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.
…nces

Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.

Review commit only: protocol, affinity, lifecycle, Trainer guards and cold-start wiring form one atomic core merge group. Do not enable or merge this intermediate commit alone.
Trie traversal overlaps existing InternLM#2252; preserves InternLM#2257 request-aware reference rules rather than replacing the file.
…rriers

Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.

Review commit only: protocol, affinity, lifecycle, Trainer guards and cold-start wiring form one atomic core merge group. Do not enable or merge this intermediate commit alone.
Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.

Review commit only: protocol, affinity, lifecycle, Trainer guards and cold-start wiring form one atomic core merge group. Do not enable or merge this intermediate commit alone.
Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.

Review commit only: protocol, affinity, lifecycle, Trainer guards and cold-start wiring form one atomic core merge group. Do not enable or merge this intermediate commit alone.
Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.

Review commit only: protocol, affinity, lifecycle, Trainer guards and cold-start wiring form one atomic core merge group. Do not enable or merge this intermediate commit alone.
Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.
Mechanical extraction from XTuner InternLM#2257 fixed head 43d62b6. No new implementation.
Existing InternLM#2257 tests/docs retained centrally; no equality burden on individual review commits.
@jayhenry
jayhenry force-pushed the xs1997zju/agent-rl-stack-20261111/06-valid-attempts branch from e42ad7b to 2c9ccbf Compare November 17, 2026 06:43
@Wuyh11

Wuyh11 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Sandbox cleanup — review report and current validation

Test-source exclusion update: Current delivery heads: XTuner f7554574, Lagent 3a694e7e, CRG f00cc0a2. The confirmed 29 cleanup-owned test/script/fixture changes (XTuner 12, Lagent 5, CRG 12) have been reverted to their respective direct stack baselines; pre-existing baseline tests are preserved. All 33 latest local test copies, including 4 previously untracked files, are archived outside the delivery repositories. Runtime and documentation contents are byte-identical to the preceding heads; this is a test-only scope reduction, not a new experiment run. By the user's explicit scope choice, #2299 alignment is deferred: XTuner's current GitHub comparison still shows 15 inherited upstream-stack test files, outside these 29 cleanup-owned files.

Validated runtime heads before the test-only exclusion: XTuner 9735a334c9696a28d08647ee89cb079af2d47bce, Lagent 6680c358892c4e3326a36bb296968661d9b2d74a, CRG 35d91eb5d221d8aae429128317dcda0dc13ecb6a.

This comment republishes the latest retained architecture/code review, review_2313_387_79_sandbox-cleanup_2026-11-17_15-06.md, in full, followed by the subsequent full GPU/sandbox report. It is a cross-repository integration review, not a newly executed review of each intermediate commit. The independent reviewers recorded in that report used GPT-6.1 Sol / high; no new independent review or GPU run was performed for publication.

Read the chronology correctly: the 15:06 static review found no confirmed PR-introduced defect in its scope. Later 16-GPU fault injection found S13 and I07 unresolved; the overall current result is 64/66 passed, not complete acceptance. Publishing the older report does not override those failures.

Known limits and normal-training impact

The two failed injections do not lie on the current standard training entry's normal path. They remain real recovery limits, not evidence of a universal no-leak guarantee:

  1. S13 — control-container ↔ GPU mount-domain locking. A control-container observer entered provider resolution for 8 active GPU-owned journals. A test guard blocked every DELETE; original owners then deleted their resources normally. The standard recipe launches the Driver and its local observer in the GPU environment; merely submitting jobs or reading logs from the control container does not invoke recovery. Tested GPU↔GPU protection/takeover passed. Do not run online recovery from the incompatible control mount; external recovery must use the validated GPU/storage domain or first independently establish that every relevant owner has stopped. Otherwise active resources could be deleted and tasks interrupted. The storage bridge's exact cause is not yet located.
  2. I07 — create response received before ID persistence. The test paused 8 successful create responses before the allocation callback, then SIGKILLed the private workers. After foreground recovery and six background rounds, journals still said creating with no IDs, so recovery could not locate these 8 resources. Only their separately audited exact IDs allowed safety deletion. Ordinary successful execution continues into the callback and records the ID; cooperative cancellation is covered separately. Abrupt termination in this narrow window can leak sandbox quota, and accumulated leaks can affect subsequent allocation. The injected window was widened deliberately; its natural occurrence rate was not measured. Resolving it requires a durable create identity plus platform-supported exact lookup/idempotency.

All in-job recovery executors disappearing still requires an external executor. LocalhostRunner, tools bypassing Pool, full-node power loss, throughput/peak-memory acceptance and full optimizer-update training are outside this delivery's completed acceptance.

Snapshot and publication scope: the report's old HEAD + local repairs runtime is now committed as the three heads above, and all runtime hashes match the experiment snapshot. The current cleanup delta excludes all 29 cleanup-owned test changes and retains the latest local suite in a separate archive; 5 documentation-only worktree changes remain uncommitted. The reports' test counts describe local execution, not a fresh-checkout CI result. Test exclusions use additional commits; existing history was not rewritten. Retained local paths below identify evidence on the shared filesystem; they are not publicly hosted artifacts. No credentials or raw platform responses are published.

Dependency alignment: XTuner's validated cleanup delta starts at e42ad7b4705cbc9b1822f08d3f61652ed3e5c588. #2299 has since been rebased/updated to 2c9ccbfec4652d3f63062567e40a7ce586c07730; #2313 currently has merge conflicts against that moving base. Review the immutable cleanup-only comparison. Rebase/conflict resolution and compatibility revalidation remain separate work before Ready. Lagent's incremental base remains #385 6d007f0; CRG's remains !78 6448db2.


Retained architecture/code review — 2026-11-17 15:06

summary

本轮未发现可确认的本 PR 引入缺陷。 已修复前轮确认的 tokenizer 缓存身份问题,并按用户最新要求,只审查三个 PR/MR 相对直接 stack 基线新增或改变的代码及其交互;基线既有问题不再列为本轮 finding。

缓存修复覆盖 DeepSWE 和 CyberGym:显式传播预计算 tokenizer_hash;未提供时首次 hash() 计算并复用 tokenizer 指纹;cache schema 从1升至2,继续纳入 max_length、system_prompt、tools_schema。没有增加管理类、改变清理预算或提交/推送。

仓库 直接比较基线 本地拟交付版本
XTuner #2313 e42ad7b4705cbc9b1822f08d3f61652ed3e5c588,#2299 5e91217e8bad73605dd948a90429ab11b63016da+未提交修复
Lagent #387 6d007f05443f845cd6ee4e1706f83158c85bd679,#385 db9e46e3c09e1414e382ba213bf705ac37f6909f+未提交修复
CRG !79 6448db2bc1c542e2cf1efe475eec11a9b87db16a,!78 e2a79977f32881e91a2e797c2dda392b5b55f99d+未提交修复

工作目录为三个原 cleanup worktree,完整交付96文件/86 Python;本轮缓存修复6文件。虽然阅读完整调用路径,但 finding 必须能归因于上述 diff 或其造成的行为变化,不以“文件改过”把整文件的旧问题归给本 PR。Lagent #385自身、独立429 worktree和未改变的既有业务语义不在本轮缺陷范围内。评审对象为本地源码,远端PR尚未同步这些未提交修改。

采用 improve-codebase-architecture,读取CONTEXT,以module、interface、depth、seam、adapter、leverage、locality和deletion test评估;配套codebase-design skill及相关ADR未找到。用户指定Markdown,不另生成HTML或候选确认。主审Codex的精确子型号与思考强度未由会话提供;独立审查为GPT-6.1 Sol / high。

before是直接stack基线,after是当前工作区。类图使用added/changed stereotype,流程图使用Mermaid8.8.0基础graph/subgraph/classDef;未运行旧版renderer,不宣称完成视觉验收。图示覆盖主要class/module,不把功能module误称Python管理class。

UML before this PR

直接基线中,Runner 与任务共享 Ray actor,资源归属和重试在 Pool 内;CyberGym 自行补删与查询,并在阶段释放时关闭 provider。尚无本次公共账本、独立任务进程及统一退出回收器。Lagent 基线没有本次 DBox provider,CRG 基线没有本次 DeepSWE recipe。

classDiagram
  class AgentLoopActor {
    +generate()
  }
  class AgentInSandboxLoop {
    +generate_sample()
    -_run_item()
  }
  class Runner {
    +run()
  }
  class SandboxPool {
    +get()
    +release_all()
    -_acquire_ready()
    -_release_group()
  }
  class SandboxSpec
  class SandboxStage {
    +run()
  }
  class Judger {
    +run()
  }
  class SandboxProvider {
    <<protocol>>
    +create()
    +delete()
  }
  class GatewayProvider {
    +create()
    +delete()
    +get()
    +aclose()
  }
  class SandboxClient
  class OpenSandboxProvider
  class OpenSandboxClient
  class CyberGymRunner
  class CyberGymPool
  class FairAsyncTokenBucket
  AgentLoopActor "1" *-- "1" AgentInSandboxLoop : per actor
  AgentInSandboxLoop "1" --> "0..*" Runner : concurrent tasks in actor
  Runner "1" --> "1" SandboxPool : per trial
  Runner "1" --> "1" SandboxStage : infer
  Runner "1" --> "1" Judger : validate
  SandboxPool "1" *-- "1..*" SandboxSpec : named plans
  SandboxSpec "0..*" --> "0..*" SandboxSpec : dependency config reuse
  SandboxPool "0..*" --> "1" GatewayProvider : optional shared provider
  SandboxPool "0..*" --> "1" OpenSandboxProvider : alternative backend
  SandboxPool "1" --> "0..*" SandboxClient : owned clients
  SandboxPool "1" --> "0..*" OpenSandboxClient : alternative clients
  SandboxPool "0..*" --> "0..1" FairAsyncTokenBucket : shared per process and key
  SandboxProvider <|.. GatewayProvider
  SandboxProvider <|.. OpenSandboxProvider
  Runner <|-- CyberGymRunner
  SandboxPool <|-- CyberGymPool
Loading

数量关系说明:Runner→Pool 的 1:1 是一次执行关系;同一个 Runner 模板可以先后产生多个 Pool。Spec 的多对多是配置引用,不代表多个任务共同拥有一个物理沙盒;依赖只支持一层。provider 是互斥后端选择,不表示每个 Pool 同时连接两个 provider。token bucket 是每进程每 key 的共享注册表实例,不是全局 Singleton 类。

Main Flowchart before this PR

graph TD
  subgraph BActor ["xtuner.v1.rl.agent_loop.sandbox_agent_loop.agent_in_sandbox_loop.AgentInSandboxLoop._run_item"]
    B1["解析配置并注入原 session"]
    B2["在共享 Ray actor 内执行 runner.run"]
    B1 --> B2
  end
  subgraph BRun ["xtuner.v1.rl.agent_loop.sandbox_agent_loop.runner.Runner.run"]
    B3["校验输入并构造 Pool"]
    B4["infer 后执行 validate"]
    B5["finally 先写最终日志,再 release_all"]
    B3 --> B4 --> B5
  end
  subgraph BGet ["xtuner.v1.rl.agent_loop.sandbox_agent_loop.sandbox.SandboxPool.get"]
    B6["读取缓存或逐项创建依赖组"]
    B7["健康检查、provision、提交 group"]
    B6 --> B7
  end
  subgraph BCreate ["lagent.serving.sandbox.providers.gateway.GatewayProvider.create"]
    B8["POST 分配后返回 client 与 ID"]
  end
  subgraph BOS ["recipe.cybergym.opensandbox_provider.OpenSandboxProvider.create"]
    B9["分配与就绪,失败自行回滚"]
  end
  subgraph BStage ["xtuner.v1.rl.agent_loop.sandbox_agent_loop.sandbox.SandboxStage.run"]
    B10["pre hooks、entries、post hooks"]
  end
  subgraph BJudge ["xtuner.v1.rl.agent_loop.sandbox_agent_loop.judger.Judger.run"]
    B11["验证阶段,可释放 infer 资源并另建 verifier"]
  end
  subgraph BRelease ["xtuner.v1.rl.agent_loop.sandbox_agent_loop.sandbox.SandboxPool.release_all"]
    B12["逆序 DELETE 与 client close;错误只记录日志"]
  end
  subgraph BCyber ["recipe.cybergym.pipeline.CyberGymPool.release_all"]
    B13["补删 owned IDs 并查询最终状态"]
    B14["finally 关闭 provider"]
    B13 --> B14
  end
  B2 --> B3
  B4 --> B6
  B6 --> B8
  B6 --> B9
  B7 --> B10 --> B11
  B11 --> B12
  B5 --> B12
  B12 -.-> B13
Loading

图中的创建后端二选一。基线已有普通 finally、局部回滚和 CyberGym 专用补删,不能描述成“原先完全没有清理”;缺少的是统一持久所有权、任务可强制终止与退出接管。

UML after this PR

classDiagram
  class AgentLoopActor {
    <<changed>>
    +generate()
  }
  class FairAsyncTokenBucket
  class AgentInSandboxLoop {
    <<changed>>
    -_run_item()
  }
  class TrialProcess {
    <<added>>
    +run_trial_process()
    +resolve_runner()
    +validate_trial_budget()
  }
  class TrialChannel {
    <<added>>
    +acquire()
  }
  class CreationLimiter {
    <<added>>
    +acquire()
  }
  class Runner {
    <<changed>>
    +prepare_trial_pool()
    +run_with_pool()
    +run()
  }
  class SandboxPool {
    <<changed>>
    +get()
    +task_scope()
    +release_all()
    +aclose()
  }
  class SandboxLifecycle {
    <<added>>
    +acquire_group()
    -_name_locks
    +release_all()
    +finish()
  }
  class Finalization {
    <<added>>
    release_attempted
    sealed
    handed_off
    completed
    release_error
  }
  class CleanupJournal {
    <<added>>
    +begin_create()
    +allocated()
    +confirmed()
    +detach()
  }
  class SandboxProvider {
    <<changed>>
    ClientT covariant
    +create()
    +delete()
    +get()
    +aclose()
  }
  class GatewayProvider {
    <<changed>>
  }
  class DBoxProvider {
    <<added>>
  }
  class OpenSandboxProvider {
    <<changed>>
  }
  class SandboxClient {
    <<changed>>
    +is_pid_running()
    +get_lifecycle_state()
  }
  class DBoxSandboxClient {
    <<added>>
    +get_diagnostics()
    +configure_network()
  }
  class OpenSandboxClient {
    <<changed>>
    +get_diagnostics()
    +configure_network()
  }
  class SandboxSpec
  class SandboxStage
  class Judger
  class CyberGymRunner {
    <<changed>>
  }
  class TrialObservation {
    <<changed>>
    +observe_trial()
  }
  class RLCyberGymTokenizeFn {
    <<changed>>
    +hash()
    -_tokenizer_hash
  }
  class RLDeepSWETokenizeFn {
    <<added>>
    -_tokenizer_hash
    +hash()
    +__call__()
  }
  class ProcessProbe {
    <<added>>
    +is_running()
  }
  class DeepSWERunner {
    <<added>>
  }
  class Recycler {
    <<added>>
    +request_recovery()
    +run_batch()
  }
  class RunControl {
    <<added>>
    +training_scope()
    +ray_shutdown_scope()
  }
  class Supervisor {
    <<added>>
    +main()
  }
  AgentLoopActor "1" *-- "1" AgentInSandboxLoop : per actor
  TrialChannel "0..*" --> "0..*" FairAsyncTokenBucket : parent registry permit keys
  AgentInSandboxLoop "1" --> "0..*" TrialProcess : concurrent isolated trials
  TrialProcess "1" --> "1" Runner : per child invocation
  TrialProcess "1" --> "1" TrialChannel : child endpoint
  CreationLimiter "0..*" --> "1" TrialChannel : compatible permit adapter
  Runner "1" --> "1" SandboxPool : per trial
  Runner "1" --> "1" SandboxStage : infer
  Runner "1" --> "1" Judger : validate
  CyberGymRunner ..> TrialObservation : one scope per invocation
  OpenSandboxClient "1" *-- "0..1" ProcessProbe
  RLDeepSWETokenizeFn ..> AgentInSandboxLoop : rollout item configuration
  RLCyberGymTokenizeFn ..> AgentInSandboxLoop : rollout item configuration
  Runner <|-- CyberGymRunner
  Runner <|-- DeepSWERunner
  SandboxPool "1" *-- "1" SandboxLifecycle
  SandboxPool "1" *-- "1..*" SandboxSpec
  SandboxSpec "0..*" --> "0..*" SandboxSpec : dependency config reuse
  SandboxLifecycle "1" *-- "1" Finalization : private data only
  SandboxLifecycle "1" *-- "0..1" CleanupJournal
  SandboxLifecycle "0..*" --> "1" SandboxProvider : dedicated or shared
  SandboxLifecycle "1" --> "0..*" SandboxClient : exclusive release obligation
  SandboxProvider <|.. GatewayProvider
  SandboxProvider <|.. DBoxProvider
  SandboxProvider <|.. OpenSandboxProvider
  SandboxClient <|-- DBoxSandboxClient
  OpenSandboxClient ..> SandboxClient : compatible operations without inheritance
  CleanupJournal "0..*" ..> "1" Recycler : one active worker per run
  RunControl "1" --> "0..*" Supervisor : head and optional peer witnesses
  RunControl ..> Recycler : bounded exit handoff
Loading

图中 TrialProcess、Recycler、RunControl、Supervisor 与 TrialObservation 是 module 视图,不是新增 Python 管理 class;Finalization 是私有 _Finalization 纯数据。TrialChannel/CreationLimiter 对应 _TrialChannel/_CreationLimiter,后者保持既有 .acquire() interface。SandboxProvider 是既有 Protocol 的扩展;OpenSandboxClient 没有继承 SandboxClient,只提供兼容操作,图中没有把鸭子类型误画成继承。

TrialObservation 对应已有 recipe.cybergym.metrics module;它没有新增 Python 管理 class。泛型参数只描述不同 provider 的 client 返回值,不要求 OpenSandboxClient 继承 SandboxClient。

channel→bucket 的多对多表示多个 trial 复用父进程的多个限速 key,不是沙盒共同所有权。

每个独立 trial 一个 CPU 子进程、一个创建许可 channel endpoint;同一子进程若业务显式构造多个 Pool,可以拥有多个账本。每个 Pool 独占自己的资源释放义务,provider transport 可以共享。每个 run 至多一个持锁的活动回收链;head 和可选 peer 可以有多个退出观察者,竞争者不会同时取得同一账本所有权。它们都不是全局 Singleton 类。相同 name 的并发 get 现在在同一 Lifecycle 中串行并复用提交结果;该锁不跨 Pool 共享。

简称 完整名称
AgentInSandboxLoop xtuner.v1.rl.agent_loop.sandbox_agent_loop.agent_in_sandbox_loop.AgentInSandboxLoop
TrialProcess/TrialChannel 同 package 的 trial_process module、trial_channel._TrialChannel
Runner/Pool/Lifecycle/Journal 同 package 的 runner.Runner、sandbox.SandboxPool、lifecycle.SandboxLifecycle、cleanup.CleanupJournal
RunControl/Recycler/Supervisor 同 package 的 run_control、recycler、supervisor modules
Provider/Client lagent.serving.sandbox.providers.base.SandboxProvider/SandboxClient
Gateway/DBox 同 providers package 的 gateway.GatewayProvider、dbox.DBoxProvider、dbox_client.DBoxSandboxClient
OpenSandbox recipe.common.opensandbox_provider.OpenSandboxProvider/OpenSandboxClient
Recipe Runner recipe.cybergym.pipeline.CyberGymRunner/recipe.deepswe.pipeline.DeepSWERunner

Main Flowchart after this PR

黄色为改造的既有入口,绿色为新增能力,灰色为保留的业务步骤。图中 provider 是互斥后端,infer→verify 的业务顺序保留。

graph TD
  subgraph FData["recipe.deepswe.xtuner_dataset.RLDeepSWETokenizeFn.hash / RLDeepSWETokenizeFnConfig.build"]
    D0["构造训练 item;缓存身份包含 tokenizer 指纹和配置"]
  end
  subgraph FLoop["xtuner.v1.rl.agent_loop.sandbox_agent_loop.agent_in_sandbox_loop.AgentInSandboxLoop._run_item"]
    L0["原 session UID;调用独立任务入口"]
  end
  subgraph FProcess["xtuner.v1.rl.agent_loop.sandbox_agent_loop.trial_process.run_trial_process / resolve_runner"]
    P0["校验可信可重建配置与声明预算;启动 CPU child"]
    P1["child 重建 Runner,模型仍经原 HTTP proxy"]
    P2["等待或取消;只终止本任务进程组;确认退出"]
    P3["按任务 manifest 恢复;核对结果身份与 receipt"]
    P0 --> P1
    P2 --> P3
  end
  subgraph FObserve["recipe.cybergym.metrics.observe_trial"]
    O0["必需身份/开始记录/输出目录,均早于分配"]
    O1["可选 usage/诊断/最终记录;普通错误不覆盖结果"]
  end
  subgraph FCyberRun["recipe.cybergym.pipeline.CyberGymRunner.run / _run_cybergym_trial"]
    C0["观察 scope 内,标准 Runner 与总期限;保留已有错误"]
  end
  subgraph FPrepare["xtuner.v1.rl.agent_loop.sandbox_agent_loop.runner.Runner.prepare_trial_pool / run_with_pool"]
    R0["校验与复制配置,构建 Pool;task_scope 内线性执行"]
    R1["关闭 Pool,保存清理快照,再记录最终日志"]
  end
  subgraph FPool["xtuner.v1.rl.agent_loop.sandbox_agent_loop.sandbox.SandboxPool.get / _acquire_ready"]
    G0["规划依赖、限速、健康和 provision"]
  end
  subgraph FLife["xtuner.v1.rl.agent_loop.sandbox_agent_loop.lifecycle.SandboxLifecycle.acquire_group"]
    A0["登记获取完成信号;按 name 锁;重查准入与缓存"]
    A1["创建前 intent;分配即归属;回滚后才决定重试"]
    A0 --> A1
  end
  subgraph FJournal["xtuner.v1.rl.agent_loop.sandbox_agent_loop.cleanup.CleanupJournal.begin_create / allocated / confirmed"]
    J0["OFD lease;先登记精确 manifest;持久意图与 ID"]
  end
  subgraph FChannel["xtuner.v1.rl.agent_loop.sandbox_agent_loop.trial_channel.serve_channel / _CreationLimiter.acquire"]
    Q0["复用父 actor 共享创建许可"]
  end
  subgraph FProvider["lagent.serving.sandbox.providers.gateway.GatewayProvider.create / lagent.serving.sandbox.providers.dbox.DBoxProvider.create"]
    V0["单 POST;早期分配通知;ready;失败保留可恢复 ID"]
  end
  subgraph FOpen["recipe.common.opensandbox_provider.OpenSandboxProvider.create"]
    V1["线程 POST 与取消补偿;分配通知早于就绪"]
  end
  subgraph FInfer["recipe.cybergym.pipeline.InferStage.run"]
    I0["标准业务执行后,必须停止 agent 并收集产物"]
    I1["停止与收集结束,返回业务结果"]
    I0 --> I1
  end
  subgraph FJudge["xtuner.v1.rl.agent_loop.sandbox_agent_loop.judger.Judger.run"]
    B0["阶段释放、准备 verifier、执行 verify"]
  end
  subgraph FRelease["xtuner.v1.rl.agent_loop.sandbox_agent_loop.lifecycle.SandboxLifecycle.release_all / finish"]
    S0["停止并排空获取;逆序删除+查询确认;关闭 clients"]
    S1["分别记录 release、seal、handoff、transport 完成事实"]
    S0 --> S1
  end
  subgraph FExit["xtuner.v1.rl.agent_loop.sandbox_agent_loop.run_control.training_scope / ray_shutdown_scope"]
    X0["退出 stop admission → drain → 有预算补扫"]
  end
  subgraph FWitness["xtuner.v1.rl.agent_loop.sandbox_agent_loop.supervisor.main"]
    W0["正常时只观察 driver;退出时接管同一补扫"]
  end
  subgraph FRecycler["xtuner.v1.rl.agent_loop.sandbox_agent_loop.recycler.request_recovery / run_batch"]
    Z0["失败持久入队;固定代际范围;受限并发+退避;耗尽保留"]
  end
  D0 --> L0 --> P0
  P1 --> R0
  P1 -.-> O0 --> C0 --> R0
  R0 --> G0 --> A0
  A1 --> J0
  A1 --> Q0
  A1 --> V0
  A1 --> V1
  V0 --> I0
  V1 --> I0
  I1 --> B0 --> S0
  R0 --> R1 --> S1
  R1 -.-> O1
  R1 --> P2
  S1 -.-> Z0
  P3 -.-> Z0
  W0 --> X0 --> Z0
  classDef changed fill:#fff2cc,stroke:#b8860b,color:#222;
  classDef added fill:#e2f0d9,stroke:#548235,color:#222;
  classDef business fill:#eeeeee,stroke:#777,color:#222;
  class L0,R0,R1,G0,V0,V1,O0,O1,C0 changed;
  class P0,P1,P2,P3,A0,A1,J0,Q0,S0,S1,X0,W0,Z0 added;
  class D0 added;
  class I0,I1,B0 business;
Loading

这是主干及配套 CyberGym 路径的展开图;DeepSWE 使用相同公共任务/Pool 流程,其可选 capture 独立有界。业务抛错/进程强杀不必继续执行 verify;父进程只有确认 worker 退出后才能接管 manifest,不能把强杀画成 child 继续调用 finish。

流程 对应修改代码
D0 CRG recipe/deepswe/xtuner_dataset.py;CyberGym 对应 adapter 同样纳入 tokenizer 指纹
L0/P0–P3/Q0 XTuner agent_in_sandbox_loop.py、trial_process.py、trial_channel.py
O0/O1/C0 CRG recipe/cybergym/metrics.py、pipeline.py,本轮前的收尾职责重构
R0/R1/G0/A0–A1 XTuner runner.py、sandbox.py、lifecycle.py,同名事务、失败优先级与排空
J0/S0–S1 XTuner cleanup.py、locking.py、lifecycle.py,持久归属、删除确认、可重试关闭
V0/V1 Lagent provider gateway.py、dbox.py、lifecycle.py;CRG recipe/common/opensandbox_provider.py
I0/I1/B0 CRG recipe/cybergym/pipeline.py、environment.py;XTuner judger.py
X0/W0/Z0 XTuner run_control.py、supervisor.py、recycler.py,trainer/CLI/ray_utils 保留具名接触点

核心原理

  1. 先归属后等待。 在可能分配之前持久登记manifest和intent,平台返回ID即通知账本,ready失败和取消仍保留可恢复归属。同名并发获取在一个Lifecycle内串行,不同name仍并发。
  2. 任务隔离与恢复分离。 完整infer→verify在独立CPU进程;Ray actor保留模型代理、trace及共享创建许可。父进程只在worker确认退出后接管该任务manifest,迟到句柄也要终止、reap和恢复。
  3. 删除必须确认。 仅平台deleted/合法404算回收完成,DELETE接受与快照字段不能代替确认。阶段释放保留transport,最终关闭分别记录release/seal/handoff/close事实,重试不重写已移交账本。
  4. 退出优先,失败才后台回收。 先stop admission、排空、有限补扫;未完资源持久入队。每run单活动回收链,默认8路账本、6轮、2秒起退避至60秒、每轮30秒、总600秒;固定代际范围,耗尽祖先不续预算。正常训练不周期扫描全账本。
  5. 缓存身份覆盖实际tokenization。 相同缓存键必须对应相同tokenizer、chat template和提示配置。上层预计算指纹受信任;未提供时复用项目既有save_pretrained哈希工具。schema升级使旧键自然失效,不删除现有缓存文件。

核心实现与对应的单测

缓存问题的修复与复核

主要位置:CRG recipe/deepswe/xtuner_dataset.py::RLDeepSWETokenizeFn.__init__/hash、RLDeepSWETokenizeFnConfig.build;CyberGym对应的RLCyberGymTokenizeFn/Config使用相同契约。

# 当前实现的职责示意;没有新增运行时manager
build(tokenizer, tokenizer_hash=None):
    return TokenizeFn(tokenizer, tokenizer_hash=tokenizer_hash, **config)

hash():
    if self._tokenizer_hash is None:
        self._tokenizer_hash = tokenizer_xxhash(self.tokenizer)
    return stable_hash(schema=2, tokenizer_hash=self._tokenizer_hash,
                       max_length=..., system_prompt=..., tools_schema=...)

项目公共tokenizer_xxhash通过序列化tokenizer计算,包含chat template;没有重复实现一套词表/模板提取规则。惰性计算避免普通构造和__call__强迫save_pretrained;保留原有位置参数、config字段、task mount和judger mapping行为。实例使用期间tokenizer须保持不变,更换后重新build;上层提供hash时须与tokenizer一起更新,这与数据构建层原契约一致。

修前证据:将本轮cache增量逆向移除,得到冻结的修前dataset模块,再加载到真实XTuner JsonlDataset。两种recipe各测chat template和实际预分词规则变化,4/4在reused==fresh断言失败;不是将替身cache当作持久缓存,也不冒称命令在编辑产品前执行。修后同场景通过。

测试 验证方法 结果
test_tokenizer_cache.py::test_persistent_cache_tracks_tokenizer 两recipe×模板/预分词规则;同annotation/cache/tag,比较reused与fresh的有效样本、offsets、num_tokens 4项通过,旧错误过滤/旧超限样本均不再复用
同测试的缓存命中检查 重开相同tokenizer/config,把count_tokens设为立即失败 正常命中缓存,无重算
test_build_preserves_precomputed_tokenizer_identity 两recipe传不同预计算hash;禁止调用序列化helper,核对全部config字段 2项通过
test_tokenizer_hash_is_lazy_and_computed_once 两recipe监控helper调用,构造时0次,多次hash共1次 2项通过
test_constructor_keeps_existing_positional_arguments 原有位置参数构造两个Fn 2项通过
既有test_training_mapping.py 实际tokenizer、RolloutState/AgentRolloutItem、配置变化及持久缓存 9项通过
test_trial_budget.py 标准预算声明/启动校验,包括只实现tokenization的既有fake 5项通过

上述共24项定向测试,与recipe完整回归重合,不重复累计。独立静态复核确认:配置透传、惰性指纹和JsonlDataset键的消费相符,未发现该修复引入新问题。

本次PR新增清理能力与既有单测的对应

实现 主要单测 原理与审查结果
SandboxLifecycle.acquire_group XTuner sandbox_cleanup_cpu.py 同名owner/waiter、不同name并发、rollback、cancel、close组 锁覆盖整笔事务,完成信号纳入排空;未确认新增归属覆盖
CleanupJournal intent token、并发registration、创建取消、发布失败组 intent与归属动作具名持久化,线程写完成前不释放所有权
Lifecycle.finish与finalize_bounded final close重试、detach失败、handoff超时、transport失败、重复取消与主错组合 独立完成状态/有界终结;已成功交接不续预算、不覆写
run_trial_process与channel sandbox_trial_cpu.py crash/cancel/late spawn/parent death/identity/permit组 单任务进程,确认退出后精确恢复;许可仍由父actor共享
OFD/run_control/recycler kernel竞争、fork、guardian、stop/seal、successor、ancestor、fit ACK及head/peer组 lease所有权、不可变恢复范围、退出事实分离;未确认新增缺陷
Gateway/DBox/OpenSandbox Lagent tests/test_sandbox、CRG provider/pipeline测试及跨库Gateway契约 分配通知早于ready,取消补偿保留归属,删除确认不弱化
DeepSWE集成 hooks/capture/cleanup lifecycle/pipeline handoff/ProcessProbe兼容组 可选诊断不改业务结果,必需patch/reward仍必需,复用公开Runner入口
CyberGym本次改造部分 runner finalization、metrics、preflight、runtime与budget测试 顶层观察与执行职责分开,错误优先、URL隐藏和接口兼容;仅对新增语义作结论

以上表格说明代码与单测的对应,不代表本轮重新执行全部XTuner/Lagent套件。

抽象与信息隐藏评估

module/interface depth、locality、seam与deletion test 结论
Pool/Lifecycle Pool保留依赖规划和readiness;Lifecycle集中事务、归属、释放和交接。删除它会把规则摊回Pool 真实depth,保留
trial_process/trial_channel 进程协议与父进程共享permit是不同seam;不传live Pool/provider,model HTTP不经过permit通道 测试surface明确,有leverage
CleanupJournal/recycler/run_control 持久事实、失败重试、训练退出接入各自集中;调用方不读账本格式 信息隐藏合理,不增加调度manager
provider lifecycle Gateway/DBox/OpenSandbox是真实adapter差异,公共分配顺序共享 泛型如实表达client,不强制继承或新增adapter
metrics.observe_trial 隐藏身份/输出/usage和可选失败政策,删除后复杂度会返回Runner 有实际depth,不是纯转发wrapper
tokenizer缓存修复 原Fn内一字段,Config传递身份;复用已有tokenizer module,真实cache测试验证interface 未增加新class,规则locality改善

没有需要新增class解决的确认问题。固定schema、纯数据记录、ctypes ABI结构和异常类型不等同新增运行时manager;完整PR新增的Lifecycle、Journal、channel等各自隐藏真实规则,本轮缓存没有再叠管理层。

新增功能守则

既有类/入口 R1 R2 R3 结论
AgentInSandboxLoop 无进程管理字段,_run_item一次调用 无manifest/kill/recovery细节 无进程特性分支 满足
Trainer/CLI接入 具名scope与退出动作 账本/回收细节归run_control 政策不摊进训练循环 满足目标
CyberGymRunner 0新增管理字段,观察scope+执行两次具名调用 身份/IO/结果政策下沉module 类内无清理失败分支 满足目标
SandboxPool 1个_lifecycle字段,公开委托多于1–2次 无journal dict和recycler内部状态 不按持久模式分叉 已说明的兼容interface例外
GatewayProvider preflight/allocated/ready三个步骤 共同规则下沉,transport差异保留 后端路由仍有分支 真实adapter例外,不另套facade
缓存Fn/Config 原Fn增1身份字段,Config只透传 序列化细节复用现有tokenizer module 调用方无新功能分叉 满足最小接触目标

R1字面计数不完全满足的既有interface,不因此判为正确性缺陷;不建议合成字符串路由或增加浅class掩盖计数。未确认本次引入新的功能守则问题。

公开接口的线性业务流程评估

  • run_trial_process:校验→启动/等待→有界终结→结果验证→staging释放,步骤处在同一业务层级;细节动作具有真实depth。
  • Runner.prepare_trial_pool/run_with_pool:准备与执行分开,infer→validate顺序清楚,最终结果政策集中。
  • Lifecycle.acquire_group:登记获取→按name串行→准入/缓存重查→执行事务;内部callback只提供规划/readiness能力。
  • Lifecycle.finish:release→seal→handoff→close,独立完成状态支持失败后重试。
  • CyberGymRunner.run/DeepSWERunner.run:局部scope组织执行,未把新清理状态字段摊到recipe类中。
  • TokenizeFn.hash:确保已有指纹→构造完整配置身份→稳定摘要;Config.build只传递。无需再把每一步拆成wrapper。

没有新的线性流程改进项;不为满足形式上的Composed Method继续拆一行私有转发。

单测建议

已补齐这次缓存缺陷的真实消费测试,未仅验证hash字符串。保留修前冻结实现与修后日志,使旧过滤错误可复现。

后续平台验收应复用现有至少8沙盒/点矩阵,验证当前隔离/OFD组合下真实rollout→verify、跨节点owner保护和崩溃接管;完整proxy→父trace→训练字段、并发RSS和吞吐需独立测量。这些属于验收范围,不作为未证实的本PR代码缺陷。

其他 issues

本轮没有其他确认的本PR引入问题。对基线既有缺陷不重新评级或列为待修项,按用户要求排除;不把未测场景、无复现的推测或字面R1例外混作finding。

验证范围与证据

  • 缓存修复仅6文件;未改XTuner/Lagent产品源码,保留此前全部未提交修复。
  • 本轮静态检查覆盖完整96文件/86Python:Ruff0.9.10 lint/format、Python3.10 AST、base→worktree diff whitespace通过。AST不代表本轮在3.10实际执行。
  • 本轮recipe回归集合21个文件(覆盖本PR全部16个新增/修改测试文件及相邻契约),170项、95子测试全部通过;24项定向与此集合重合,不重复累计。结果以 diagnostics/sandbox-cleanup-cache-fix-20261117-1506/recipe-final.log/json 和 validation-final.json 为准。前轮XTuner192/Lagent84/Pool8/Gateway2没有在本轮重跑,不与本轮数字相加。
  • 本轮没有申请GPU或真实沙盒、未进行参数更新,也未提交/推送/更新PR。不以静态无finding或CPU回归通过宣称真实平台验收完成。
  • 最终证据为上述目录的 REPORT.md、validation-final.json、完整源码冻结与测试后核对。只保留有价值的修前失败和最终结果,中间重复通过日志清理;旧review不覆盖。

@Wuyh11

Wuyh11 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Subsequent full GPU/sandbox report — 2026-11-17 17:35

Test-source exclusion update: Current delivery heads: XTuner f7554574, Lagent 3a694e7e, CRG f00cc0a2. The confirmed 29 cleanup-owned test/script/fixture changes (XTuner 12, Lagent 5, CRG 12) have been reverted to their respective direct stack baselines; pre-existing baseline tests are preserved. All 33 latest local test copies, including 4 previously untracked files, are archived outside the delivery repositories. Runtime and documentation contents are byte-identical to the preceding heads; this is a test-only scope reduction, not a new experiment run. By the user's explicit scope choice, #2299 alignment is deferred: XTuner's current GitHub comparison still shows 15 inherited upstream-stack test files, outside these 29 cleanup-owned files.

Validated runtime before the test-only exclusion: XTuner 9735a334, Lagent 6680c358, CRG 35d91eb5. The retained report below predates these core-only commits, but all runtime file hashes match the experiment snapshot. Its old HEAD references mean those HEADs plus the then-uncommitted runtime fixes. All cleanup-owned test changes are excluded from the current delivery delta and retained in the local archive; documentation-only worktree changes remain uncommitted.

Current outcome: 64/66 points passed; S13 and I07 remain unresolved. The two failures are outside the current standard normal-training path, subject to the deployment and abrupt-termination restrictions explained in the adjacent review comment. All 608 resources were independently confirmed deleted, including 8 explicit external-CLI recoveries and 8 safety deletes; do not count the latter as automatic recovery. No new GPU run was performed for this publication.


16 卡沙盒清理实测报告

完成时间:2026-11-17T17:35:29.808662+08:00。结论:64/66 点通过,2 点未通过,整体未通过验收。

本轮共创建 608 个去重物理沙盒,每点至少 8 个;592 个自动删除,8 个在恢复进程全灭的预期边界下由显式外部 CLI 恢复,8 个因创建响应窗口缺失 ID 而安全补删。平台独立 GET 确认全部删除,无剩余活动沙盒。

GPU 挂载环境内核验共 524 份账本,516 份完成,8 份仍未决;未决账本和回收请求保留,未手工改写为 complete。

环境与范围

  • 使用 llmagent_gpu,两节点各 8 张 H200;沙盒项目 ailab-llmit,身份 wuyihao.p。
  • 模型为 Qwen3.6-35B-A3B。两节点分别部署独立 8 卡推理服务,均有真实模型响应;未创建优化器或更新参数,不代表 16 卡分布式训练验收。
  • 重跑原 39 个场景及 15 个补充场景,新增 5 个跨节点场景、7 个独立进程/创建窗口场景,共 66 点。Search、tooluse 按用户要求不测。
  • CyberGym、DeepSWE、TerminalBench 使用真实 recipe 和沙盒。原生验证回放明确使用既有真实 Patch/PoC,与连续 rollout→verify 分列;不以任务得分作为回收是否通过的标准。
  • 连续 rollout→原生 verify 覆盖 CyberGym 和 TerminalBench;DeepSWE 覆盖真实推理退出及 Patch 回放验证,不将其写成连续任务完成。
  • 测试当前三个工作区的冻结源码,共 2901 个文件;包含已有本地修复。测试前后源码、HEAD、分支和暂存区一致,未 commit、push 或更新 PR。
仓库 HEAD
xtuner-stack-sandbox-cleanup 5e91217e
lagent-sandbox-cleanup db9e46e3
crg-rl-projects-sandbox-cleanup e2a79977

未通过项

S13:控制容器与 GPU 挂载环境之间的锁保护不成立。 控制容器对 8 份活动账本实际调用恢复接口,全部进入 provider 解析分支。测试 resolver 在 DELETE 前强制拒绝,实际跨环境 DELETE 为 0;随后由原 GPU Owner 正常删除资源。此结果说明该组合中不能依靠文件锁允许控制容器在线接管。两台 GPU 节点之间的双向保护、崩溃接管和竞争补扫均通过,不能据此推导控制容器也安全。具体存储桥接原因尚未定位。

I07:平台创建成功但分配回调尚未记 ID 时强杀 worker,无法自动回收。 8 次真实 POST 响应已成功,测试在回调前暂停并强杀 8 个私有 worker;8 份账本均为 creating 且资源列表为空。前台恢复结束、后台回收器耗尽 6 轮并释放 worker 锁后,8 个沙盒仍存活。仅依据本轮外部审计记录的精确 ID 安全补删了这 8 个资源;产品账本和请求队列保持未决。故障注入放大了时序窗口,本轮不估计自然发生频率。

上述两项仍是当前方案的边界,不能将本轮“平台资源最终全部删除”解释为“所有退出路径均自动兜底”。后续需分别处理跨挂载域恢复准入,以及创建请求的持久标识与平台端精确查找/幂等创建能力。

测试明细

编号 测试点 怎么测 结果与资源处理 资源数 平台独立 GET
R01 公共正常结束 8 个 Runner 并发执行沙盒命令与模型请求,正常完成验证与关闭。 通过;8/8 自动删除 8 全部删除
R02 Pool 重复关闭(DBox) 8 个 VerifiedSandboxPool 完成 Runner 收尾后再次显式调用 close。 通过;8/8 自动删除 8 全部删除
R03 业务异常收尾 8 个任务完成真实模型生成后抛出 ValueError,检查异常传播与回收。 通过;8/8 自动删除 8 全部删除
R04 任务主动取消 8 个在途任务完成模型生成后调用 cancel()。 通过;8/8 自动删除 8 全部删除
R05 任务执行超时 8 个任务设置 0.2 秒超时窗口,触发真实 TimeoutError。 通过;8/8 自动删除 8 全部删除
R06 主从依赖资源组 8 个任务各持有主资源与依赖资源,验证结束后按依赖逆序关闭。 通过;16/16 自动删除 16 全部删除
R07 推理与验证阶段切换 8 个任务先调用 release_all() 释放推理沙盒,再复用原 Pool 创建验证沙盒。 通过;16/16 自动删除 16 全部删除
R08 临时删除故障恢复 阻断 8 个资源的 DELETE 请求触发失败交接,随后解除故障观察后台回收。 通过;8/8 自动删除 8 全部删除
R09 后台退避与并发限制 持续阻断 8 份账本的 DELETE 请求并配置最大恢复并发为 2,恢复连接后观察退避重删。 通过;8/8 自动删除 8 全部删除
R10 重试耗尽后退出补扫 持续阻断 DELETE 直至后台回收器耗尽轮次,解除故障后由后续退出补扫接管。 通过;8/8 自动删除 8 全部删除
R11 损坏请求容错隔离 8 个任务触发后台交接的同时向队列放入损坏的 JSON 文件。 通过;8/8 自动删除 8 全部删除
R12 创建失败回滚阻断 健康检查返回失败同时阻断回滚 DELETE,验证回滚未完成前不再继续重试创建下一组。 通过;8/8 自动删除 8 全部删除
R13 Worker 强杀后退出接管 强杀 8 个任务 Owner 进程,确认 Driver 存活期不触发全局停机,再退出 Driver 接管。 通过;8/8 自动删除 8 全部删除
R14 Driver 重复 SIGTERM 8 个任务在途时向 Driver 连续发送两次 SIGTERM。 通过;8/8 自动删除 8 全部删除
R15 Driver SIGKILL 崩溃接管 8 个任务在途时强杀 Driver 进程,由存活的 supervisor 观察进程接管。 通过;8/8 自动删除 8 全部删除
R16 租约读取临时 I/O 异常 向 supervisor 前两次租约读取注入 OSError,随后释放 Owner 并 SIGKILL Driver。 通过;8/8 自动删除 8 全部删除
R17 Ray 关闭阻塞超时守护 强杀 8 个 Owner 后令 Driver 关闭流程阻塞 1800 秒(设 3 秒守护阈值)。 通过;8/8 自动删除 8 全部删除
R18 fork 子进程退出隔离 任务在途时 fork 辅助子进程并发送 SIGTERM,检查父训练不受影响。 通过;8/8 自动删除 8 全部删除
R19 作业内恢复进程全灭(边界) 同时强杀本组 Owner、Driver 与 supervisor,验证账本保留并执行外部恢复 CLI。 通过(符合预期边界);自动删除 0/8,显式 CLI 恢复 8/8 8 全部删除
R20 SDK 阶段切换与重复关闭 8 个 DeepSWERunner 使用 OpenSandbox SDK 完成主阶段后切换创建 Verifier,结束时重复调用关闭两次。 通过;16/16 自动删除 16 全部删除
R21 SDK 业务异常收尾 8 个 DeepSWERunner 完成 SDK 命令与模型请求后抛 ValueError,并执行重复关闭。 通过;8/8 自动删除 8 全部删除
R22 SDK 主动取消收尾 8 个 DeepSWERunner 完成 SDK 命令与模型请求后触发取消,并执行重复关闭。 通过;8/8 自动删除 8 全部删除
R23 CyberGym / 连续 rollout → verify 4 对主从依赖资源(main + task-server)完成模型推理后进入原生 Verifier。 通过;8/8 自动删除 8 全部删除
R24 CyberGym / 推理步数上限退出 4 对原生主从沙盒将步数上限设为 6,触发上限退出。 通过;8/8 自动删除 8 全部删除
R25 CyberGym / 推理阶段主动取消 4 对原生主从沙盒在完成真实生成后、进入 Verifier 前取消正在运行的任务。 通过;8/8 自动删除 8 全部删除
R26 CyberGym / 原生验证正常返回 复用真实 PoC,4 对主从沙盒执行原生 Verifier 直至正常返回。 通过;8/8 自动删除 8 全部删除
R27 CyberGym / 原生验证主动取消 复用真实 PoC,4 对主从沙盒在远端 Verifier 启动后触发取消。 通过;8/8 自动删除 8 全部删除
R28 CyberGym / 原生验证超时 复用真实 PoC,将 4 对主从沙盒的原生 Verifier 时限设为 1 秒。 通过;8/8 自动删除 8 全部删除
R29 CyberGym / GPU 作业停止(rjob stop) 4 对主从沙盒在推理运行期间执行 rjob stop 停止本次 GPU 作业。 通过;8/8 自动删除 8 全部删除
R30 DeepSWE / 推理步数上限退出 8 个原生 DeepSWE / Mini-SWE 任务将步数设为 4,触发 LimitsExceeded。 通过;8/8 自动删除 8 全部删除
R31 DeepSWE / 上下文超限异常退出 8 个原生 Runner 上传超过 65,536 token 的输入发起模型请求,触发服务端超限报错。 通过;8/8 自动删除 8 全部删除
R32 DeepSWE / 原生验证正常返回 复用真实 Patch,8 个独立沙盒运行原生 Verifier 正常返回。 通过;8/8 自动删除 8 全部删除
R33 DeepSWE / 原生验证主动取消 复用真实 Patch,8 个独立沙盒在远端验证命令启动后触发取消。 通过;8/8 自动删除 8 全部删除
R34 DeepSWE / 原生验证超时 复用真实 Patch,将 8 个独立沙盒的原生验证命令时限设为 1 秒。 通过;8/8 自动删除 8 全部删除
R35 TerminalBench / 连续 rollout → verify 8 个独立任务完成真实模型生成并进入原生 Verifier 执行完毕。 通过;8/8 自动删除 8 全部删除
R36 TerminalBench / 验证阶段主动取消 8 个原生任务在观察到远端验证启动标记后请求取消。 通过;8/8 自动删除 8 全部删除
R37 TerminalBench / 验证阶段超时 8 个原生任务进入 Verifier,验证命令时限设为 1 秒。 通过;8/8 自动删除 8 全部删除
R38 TerminalBench / 环境初始化失败 8 个任务镜像在安装运行时前执行 uv --version,触发命令缺失退出码 127。 通过;8/8 自动删除 8 全部删除
R39 TerminalBench / 验证期间 Driver 崩溃 8 个任务进入远端验证后令 Driver 抛出 TypeError 退出,检查退出补扫。 通过;8/8 自动删除 8 全部删除
S01 跨阶段回滚独立预算 8组真实 infer→释放→等待旧期限过期→verifier健康失败且首个DELETE失败→安全重试 通过;24/24 自动删除 24 全部删除
S02 同阶段排空不续预算 8组依赖资源与在途verifier;真实取消消耗首轮预算,各组共享原期限并逆序删除 通过;24/24 自动删除 24 全部删除
S03 并发创建归属与intent隔离 8个Pool各2个命名获取;一请求失败/取消,另一请求归属和未决标记不得丢失 通过;16/16 自动删除 16 全部删除
S04 关闭排空与抵抗取消创建 8个真实创建在早期ID后阻塞;关闭不得提前封存/关连接,解除阻塞后二次关闭 通过;8/8 自动删除 8 全部删除
S05 Gateway早期分配恢复 通过Gateway兼容DBox路径获取真实ID,在就绪前退出,验证账本已记ID并回收 通过;8/8 自动删除 8 全部删除
S06 大文件上传与文件属性 8个DBox沙盒各上传3,072,013字节;上传中改动符号链接,检查原目标内容、另一文件不变、UID/GID 1000和0640权限保留,之后回收 通过;8/8 自动删除 8 全部删除
S07 最后一轮新请求代际交接 旧代8资源与新代8资源,故障恢复后确认新代不丢失且旧代不自动续预算 通过;16/16 自动删除 16 全部删除
S08 清理子进程失败与ACK 真实清理子进程删除8个孤儿资源后,以退出码7结束;必须保留失败事实,且不提前报告fit成功ACK 通过;8/8 自动删除 8 全部删除
S09 Runner scope失败与结果政策 8个实际Runner覆盖业务失败叠加最终关闭错误,校验失败回调与receipt/log顺序 通过;8/8 自动删除 8 全部删除
S10 DeepSWE诊断失败叠加取消 8个真实原生SWE任务生成后取消,同时注入可选progress/capture落盘失败,资源仍回收 通过;8/8 自动删除 8 全部删除
S11 fit ACK记录超时 8个真实资源补扫成功退出后,使记录fit ACK的实际子进程超时;资源确认不反转为训练清理失败 通过;8/8 自动删除 8 全部删除
S12 异步账本初始化叠加关闭取消 8个控制资源实际生成;另8个Pool真实共享盘初始化线程延迟,取消并关闭,验证无POST且迟到账本完成并释放锁 通过;8/8 自动删除 8 全部删除
S13 GPU节点与控制容器共享锁保护 以当前OFD实现重测GPU与控制容器活动账本;只读resolver禁止DELETE,先活跃后complete,失败原样记录。 未通过;8/8 活动账本误入恢复分支;DELETE 被测试拒绝,Owner 自动回收 8/8 8 全部删除
S14 SDK创建期间重复取消 8次真实线程POST在响应交回协程前阻塞,连续两次取消Runner,再释放响应;必须保留ID、执行分配回调和补偿删除,不得进入infer 通过;8/8 自动删除 8 全部删除
S15 GPU同节点独立进程锁保护 8个真实GPU任务Pool持有资源时,独立进程运行实际reconcile_file;确认全部active且不解析provider,关闭后独立观察complete 通过;8/8 自动删除 8 全部删除
M01 跨节点活动Owner保护 A→B 节点A持有8份活动账本并完成真实模型请求,节点B实际reconcile_file必须跳过且provider调用为0;A继续verify并关闭后,B确认complete。 通过;8/8 自动删除 8 全部删除
M02 跨节点活动Owner保护 B→A 交换A/B重复活动Owner保护,确认另一方向也不访问provider或停止活跃run。 通过;8/8 自动删除 8 全部删除
M03 Owner SIGKILL后远端peer接管 A→B A持8资源且关闭本地观察者,B先证明活动时跳过,再启动实际peer;SIGKILL A,B补扫删除8资源并确认删除发生在B。 通过;8/8 自动删除 8 全部删除
M04 Owner SIGKILL后远端peer接管 B→A 交换A/B重复SIGKILL与远端peer接管。 通过;8/8 自动删除 8 全部删除
M05 两节点竞争退出补扫且每ID仅一次DELETE 实际OFD独占持有run/recycler锁,另一节点必须受阻;Owner死后两节点同时执行真实退出补扫,每资源仅一次DELETE。 通过;8/8 自动删除 8 全部删除
I01 隔离任务正常执行 8个任务经公开run_trial_process,在独立CPU进程分配真实沙盒、模型请求、命令verify并完成精确账本恢复。 通过;8/8 自动删除 8 全部删除
I02 隔离任务拒绝取消并强制终止 8个隔离worker完成真实模型请求后持续忽略协作取消,父进程终止其私有进程组并按manifest恢复。 通过;8/8 自动删除 8 全部删除
I03 隔离任务进程崩溃 8个隔离worker分配并生成后os._exit(7),父进程确认崩溃后恢复其精确账本。 通过;8/8 自动删除 8 全部删除
I04 隔离任务超时且兄弟任务存活 8个目标隔离任务在模型生成后触发调用方期限,另8个正常兄弟任务必须完成verify并回收;同一父事件循环和模型服务保持存活。 通过;16/16 自动删除 16 全部删除
I05 同名并发获取只创建一组 8个Pool分别并发3次获取同名资源,必须每Pool仅一个client/ID和一次分配,随后真实命令、模型请求并关闭。 通过;8/8 自动删除 8 全部删除
I06 最终封存失败后二次关闭 8个Pool资源删除后首次detach发布注入一次OSError;lease仍持有,二次close必须封存完成、关闭transport并释放lease。 通过;8/8 自动删除 8 全部删除
I07 创建已成功但尚未记ID时强杀worker 8次真实POST响应在分配回调之前阻塞,确认账本creating且无ID后强杀各私有worker;先检查自动回收结果,未回收时只按本轮外部审计ID补删并单独记数。 未通过;自动删除 0/8;安全补删 8/8;账本仍未决 8 全部删除

预算与证据口径

项目 本轮通用测试配置 产品默认值
后台账本并发 8(R09 专项设为 2) 8
最多轮数/初始退避 6/2 秒;个别故障专项另设轮数 6/2 秒
退避上限/每轮预算/总预算 20/45/240 秒 60/30/600 秒
退出补扫预算 通用 120 秒;个别专项使用短期限 以实际训练配置为准
独立进程新增 I01–I04 execution=1200、stop=2、recovery=90 秒 未修改产品默认值

本轮主要验证状态、归属、交接和回收行为,不将测试中的短期限写成默认长预算验收。详细覆盖以各点脚本、故障标记、账本和平台原始状态为准。

准备及统计修正均保留记录:首次启动因共享模型管理接口 HTTP 500 在创建前失败;独立进程前四项因测试 Pool 缺少 type 在创建前失败,补齐后每点以 8 个资源重跑(兄弟任务点为 16 个);TB Driver 崩溃点改以原生返回消息的 request ID 与 verify 标记核实真实模型执行;最终作业停止点因测试脚本缺少 Path 导入在创建前失败,随后用独立 16 卡作业补测。以上准备失败均未创建沙盒,未修改产品源码或删除失败记录。

补测节点 1 的附加终态审计脚本曾因缺少 Path 导入退出;节点 0 随后在 GPU 挂载环境内完成覆盖全部 608 个资源和 524 份账本的全量核验,lease 探测错误为 0。该辅助脚本错误不作为产品清理失败,也不替代原始失败记录。

最后一次实际停止的作业:cleanup-stop-retest16g-20261117t171700-98130828。停止前两个 8 卡模型部署均就绪、16 个 GPU UUID 唯一,4 个 CyberGym 任务持有 8 个存活沙盒并完成真实模型请求,尚未进入 verify;随后实际执行 rjob stop。该点依据补测结果单独判定,前一作业的空场景停止不计入通过。

全部 GPU 作业均已核对 active=0,所有本轮自有模型路由均独立确认注销。终态 lease 采用 GPU 挂载环境内的只读核验:账本核验;控制容器只核对账本内容,不以其失效的锁探测证明远端 Owner 已退出。

关键材料

@Wuyh11 Wuyh11 changed the title [Feature] Reclaim run-owned sandboxes with bounded exit recovery [Feature] Isolate Agent sandbox trials and add bounded exit recovery Nov 17, 2026
Merge InternLM#2299 at 2c9ccbf without rewriting cleanup history. Preserve upstream
timeout training, trace export and multimodal reference release alongside
private trial processes and exit recovery. Derive provenance slicing from
the exported prompt length. Keep cleanup tests outside the delivery diff.
@jayhenry
jayhenry force-pushed the xs1997zju/agent-rl-stack-20261111/06-valid-attempts branch 3 times, most recently from 063d402 to b495aae Compare November 20, 2026 13:39
@jayhenry
jayhenry deleted the branch InternLM:xs1997zju/agent-rl-stack-20261111/06-valid-attempts November 20, 2026 13:54
@jayhenry jayhenry closed this Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants