Repository navigation
Conversation
Signed-off-by: lusendong.6789 <lusendong.6789@bytedance.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google · self_reported
动机 / Motivation
受影响方与运行场景:面向所有执行 DSH 插件本地预合并验证(loopx canary premerge / examples/canary/dsh-loopx-plugin-validation.py --phase quality)的开发者、维护者与自动化门禁。loopx/canary/package_profiles.py 对 dsh-loopx-plugin 的 quality 阶段施加了单检查 120 秒超时预算,而该阶段包含 TypeScript 类型检查、vitest run(16 个文件共 405 个用例)、smoke:peer-range 与 smoke:mcp-transport。
改动前后场景对比:改动前(base 0950cea53f8e),packages/dsh-loopx-plugin/tests/admission-closeout.integration.spec.ts 中的全部 15 个真实 CLI 集成用例按顺序串行执行,本机复现耗时 64.90s(慢速/高负载环境可达 192.21s 并触发 120s quality 阶段超时);改动后(head 0d5699838551),前 3 个 PATH 与 Pause/Start 竞争用例保持串行,后 12 个独立用例改为 Vitest 默认有界并发(maxConcurrency=5),同机单文件实测降至 25.40s–31.55s,完整 quality 阶段仅需 28.00s。
可观测结果与非目标(Non-goals):同一批 16 个测试文件与 405 个用例(本文件 15 个用例、106 处 expect 断言)逐项保留且结果一致,无临时目录残留,完整 canary premerge --tier quick(quality 28.00s / package 4.69s / runtime 15.02s)全部通过。非目标:不修改任何生产运行时代码(src/)、不调整 120s 门禁预算上限、也不处理与本文件无关的远端 split-installation Hosted Core package smoke 问题(另由 #9646 负责)。
改动思路 / Approach
本 PR 采用最小化测试调度改造而非放宽门禁超时或拆分测试文件,其核心架构边界如下:
- 串行与并发的安全切分:将需要独立观察外部
PATH覆盖与托管启动器日志的keeps managed Core across a different agent PATH,以及通过start_new_session=True制造逃逸旧 Pause 子进程并与新 Start 竞争真实file/sqlite权威状态的fences an escaped old Pause after a newer Start on real %s authority(2 组)保留在并发组之前串行执行,避免 SQLite 锁竞争或 100ms 超时窗口受并发 CPU 抖动干扰。其余 12 个均使用独立file权威目录的准入与收口场景切换为it.concurrent.for/it.concurrent,依托 Vitest 4.1.12 默认的maxConcurrency=5实现有界并发。 - 每用例显式上下文绑定与清理顺序:在 Vitest 并发模式下,顶层导入的
onTestFinished无法可靠绑定到并发任务。改动将fixture()改为显式接收TestContext['onTestFinished'],并将参数化用例从.each切换为传递TestContext的.for签名(显式传入{ timeout }选项对象与{ expect, onTestFinished }上下文)。在settles the queued exact receipt once用例组中,fixture(onTestFinished)先注册rm(root),随后再注册onTestFinished(() => driver.dispose());实查@vitest/runner4.1.12 实现确认test.onFinished以 LIFO("stack")逆序执行,因此driver.dispose()必然先于临时目录清理完成。其余两组并发用例在try ... finally中显式await driver.dispose(),同样早于onTestFinished的目录删除。 - 当前 PR 边界与复用判断(架构评估
retain):直接复用 Vitest 原生it.concurrent/it.concurrent.for与TestContext['onTestFinished'],零新增抽象层且不修改任何生产运行时或 canary 预算合同。当前 PR 边界严格限定在单个集成测试文件packages/dsh-loopx-plugin/tests/admission-closeout.integration.spec.ts(+27/-19行),无需拆分或后续收尾。
| 观测维度 | Base (0950cea53f8e) |
Head (0d5699838551) |
说明 |
|---|---|---|---|
| 收集用例数(单文件 / 全量) | 15 / 405(16 files) | 15 / 405(16 files) | 15 个用例标题与 106 处 expect 完全一致 |
| 单文件实测耗时 | 64.90s(串行,85% CPU) | 25.40s / 31.55s / 30.30s(并发,~2.1x–2.5x 提速) | 连续 3 次独立运行 + 1 次全量运行全部通过 |
canary premerge quality 阶段 |
易超出 120s 预算(PR 报告 192.21s) | 28.00s(package 4.69s,runtime 15.02s) |
全部远低于 120s 单检查超时预算 |
/tmp/dsh-loopx-closeout-* 残留 |
0 | 0 | 4 次运行后检查无任何临时目录泄漏 |
具体改动 / Changes
本 PR 仅修改 1 个测试文件:packages/dsh-loopx-plugin/tests/admission-closeout.integration.spec.ts(+27 / -19 行),未改动任何生产源码、配置文件或文档。本改动属于面向 loopx/canary/package_profiles.py 既定 120s quality 预算的测试执行效率优化,无单独成文的设计规格文档(spec_basis: no_spec,验收依据来自 examples/canary/dsh-loopx-plugin-validation.py --phase quality 与 admission-closeout.integration.spec.ts 原有断言契约)。
关键代码讲解
fixture(onTestFinished, provider)(packages/dsh-loopx-plugin/tests/admission-closeout.integration.spec.ts:121-270):移除对顶层onTestFinished的隐式依赖,改为通过TestContext['onTestFinished']参数注册每用例独立的rm(root, { recursive: true, force: true })清理钩子。每个并发用例通过mkdtemp(join(tmpdir(), 'dsh-loopx-closeout-'))独占自己的project、runtime、.loopx/registry.json(显式写入common_runtime_root: runtime)以及全新内存对象session/agent,从而确保LoopXContinuationDriver的全局sessionRetention(WeakMap<Agent['session'], SessionDriverRetention>)按对象引用彻底隔离,且不触碰模块级单例goalBarCoordinator。- 串行保留用例
keeps managed Core...与fences an escaped old Pause...(packages/dsh-loopx-plugin/tests/admission-closeout.integration.spec.ts:306-448):前者在回调中解构{ onTestFinished }并保持串行;后者由it.skipIf(...).each(...)改为it.skipIf(...).for(['file', 'sqlite'] as const)(..., { timeout: 30_000 }, async (provider, { onTestFinished }) => ...),在拿到TestContext的同时保留串行执行,避免 100ms 逃逸进程超时窗口与真实sqlite权威写入受并发负载干扰。 - 6 场景准入到收口并发组
it.concurrent.for([...])(packages/dsh-loopx-plugin/tests/admission-closeout.integration.spec.ts:452-704):将compatibility、progressive、configured off、read-only selection、read-only paged revalidation、lost response on a later page6 个完整闭环用例迁移至it.concurrent.for并配置{ timeout: 90_000 },回调解构{ expect, onTestFinished },在fixture(onTestFinished)之后注册onTestFinished(() => driver.dispose())以利用 LIFO 逆序先释放驱动再删除临时目录。 - 配额关闭拒绝与 5 场景渐进抓取守卫并发组(
packages/dsh-loopx-plugin/tests/admission-closeout.integration.spec.ts:706-857):rejects queued work when quota closes during the next pre-step hook改为it.concurrent(..., 45_000),5 个keeps one guard when the progressive capture is %s场景改为it.concurrent.for(..., { timeout: 45_000 }),均解构{ expect, onTestFinished }并在finally中await driver.dispose();所有 106 处断言与原基线逐行一致。
对主干的风险 / Risks
- 并发隔离审计(无阻断风险):逐项核查了临时目录、端口/套接字、环境变量、SQLite 锁、内存单例与子进程回收:(1)所有 12 个并发用例均不监听端口/套接字、不修改
process.env,仅在每次spawn时传入局部env对象;(2)context-read抓取文件与.reader.json引用全部写入各自fixture.runtime目录,且所有并发用例使用file权威无跨用例 SQLite 锁;(3)LoopXContinuationDriver的sessionRetention以每用例新建session引用为WeakMap键,不跨用例共享状态,且测试直接构造驱动而不调用apply(),不会污染全局goalBarCoordinator。 - 反事实负向验证与非阻断观察:代码审查中注意到辅助函数
record()、array()、fixture()与executablePlanArgs()仍调用文件顶部导入的expect,而非传入TestContext['expect']。我们在 Vitest 4.1.12 下构造了it.concurrent.for并发失败反事实探针(让并发中间用例在辅助函数内触发顶层expect(null).not.toBeNull()失败),实测结果显示仅目标失败用例精确报出AssertionError(1 failed / 2 passed),无误归因或污染相邻并发用例。原因在于这些辅助函数仅执行同步抛出型断言,不涉及toMatchSnapshot、expect.soft()或expect.assertions();若后续有人向这些辅助函数添加 soft/snapshot 断言,再改为透传TestContext['expect']即可,当前不构成阻断。 - 范围适配、比例与边界检查:
scope_fit属于纯测试覆盖/执行效率边界(coverage-only,无新增生产调用方或 CLI/协议变更);change_proportionality高度匹配(+27/-19 行即可消除 120s 门禁超时瓶颈);default_off_isolation与authority_semantics对纯测试文件均无新增开关或公共协议语义扩张(not_applicable);未触及任何共享状态词汇或 RFC 文档。
| 验证项 | 命令 / 检查 | 状态 | 观测结果 |
|---|---|---|---|
| 并发稳定性与清理(Head x3) | vitest run tests/admission-closeout.integration.spec.ts |
PASS | 3 次独立运行均 15/15 通过(25.40s / 31.55s / 30.30s),0 临时目录残留 |
| 基线对照(Base) | vitest run tests/admission-closeout.integration.spec.ts @ 0950cea53f8e |
PASS | 15/15 通过,耗时 64.90s,用例名与 106 处断言与 Head 完全一致 |
| DSH 完整 quality 阶段 | python3 examples/canary/dsh-loopx-plugin-validation.py --phase quality |
PASS | typecheck + 16 files / 405 tests + peer-range + mcp-transport 全通(32.13s) |
| Premerge 门禁(quick) | loopx canary premerge --from-git-diff --git-diff-base 0950cea53f8e --tier quick |
PASS | 4/4 direct checks + 3/3 DSH canaries(quality 28.00s / package 4.69s / runtime 15.02s)全通 |
| 负向反事实(并发辅助断言失败) | Vitest 4.1.12 it.concurrent.for helper expect 失败归因探针 |
PASS | 失败精确归因到 case bad,相邻并发用例通过(1 failed / 2 passed) |
| 公共边界 / RFC / 格式检查 | loopx check --scan-path ...、check_rfc_bilingual.py、git diff --check、ruff |
PASS | 0 错误、0 警告、无私密边界泄露 |
我的整体评价 / Verdict
- 目标与结果影响(
outcome_impact):long_horizon评估为improved(消除 DSHquality阶段 120s 超时波动,使长程迭代中的本地预合并门禁稳定可在 ~28s 内闭环);user_experience评估为preserved(开发者与 CI 运行同一组 405 个用例且诊断输出与失败归因保持一致);visual_review为not_applicable(本次仅修改后端/CLI 集成测试文件,未涉及任何前端或渲染界面,unverified_scope: none)。 - 语义等价、体量与边界:
observable_semantics判定为equivalent(15 个集成用例标题、106 处expect断言及真实 CLI 收口不变量在 base/head 间保持一致,且反事实验证了并发失败归因与目录清理顺序);code_volume判定为necessary(+27/-19 行,兼容性评估not_applicable,无需进一步简化);change_proportionality判定为proportionate(架构评估retain);default_off_isolation、authority_semantics与semantic_alignment均为not_applicable(无新增共享词汇或运行时开关)。 - 残余风险与新鲜度:残余风险极低——仅存在低优先级风格观察(辅助函数
record/array/fixture/executablePlanArgs仍引用模块级expect,当前仅同步抛出断言故安全),以及高负载机器上 Vitest 5 路并发同时起 Python 子进程可能带来短暂 CPU 峰值(已通过 4 次实跑与完整canary premerge验证在 120s 预算内留有充足余量)。已确认远端 exact head 仍为0d569983855142961ae9e091228f0a13e83550f6,未发生漂移。
英文简短结论
English verdict: APPROVE — Verified exact head 0d569983855142961ae9e091228f0a13e83550f6 with zero blocking findings; all 15 closeout integration cases (106 assertions, 405 suite tests) preserve isolation and parity while cutting file wall-clock from 64.90s to 25.40s–31.55s and passing loopx canary premerge --tier quick (quality 28.00s, package 4.69s, runtime 15.02s).
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
动机 / Motivation
评审提交 0d569983855142961ae9e091228f0a13e83550f6,提案比较基线 0950cea53f8eedfd7e56a397a447eecfc87bcc50,核对主干 f2a9c7ecd62fe02dc2bff282aa1116cd8ed34054。在本地预合并处运行 DSH 插件 quality 的开发者和维护者。 15 个原生 admission/closeout 用例在同一文件串行。上游的配额和结算行为原先已有正反用例。 变更限于集成测试调度和 test-context 收尾,120 秒门禁、Python 作业权限和 DSH 持久状态保持。
三项时间敏感用例保持串行,十二项独立用例以 Vitest 本身的并行度执行。用例身份、预期结果、超时与 production runtime 保持。
改动思路 / Approach
每项独立生成临时 registry、runtime、Session 与 Driver。Vitest 的 per-test 清理通过上下文注册。 Pause/Start 的 File、SQLite 两类竞态与 managed launcher 路径复用原序列。其余真实 CLI 场景同时执行。 Vitest 负责边界内调度与归属,DSH Driver、CLI 和 typed settlement 继续负责效果。
具体改动 / Changes
- fixture 从当前 TestContext 注册目录回收。在 driver 释放、临时目录及子进程方面,现有隔离和顺序依旧。File 和 SQLite 两种 Pause/Start 情况仍为串行检查。
- 采用 Vitest 内置有界并行执行剩余十二项,保持真实 CLI 调用、只扣额一次与失败断言。采集比对证实 16 个文件中的 405 个用例逐项对应。
- 既有 120 秒 quality 预算未动。相同工具链实测提升,并在当前主干新增 Todo Unit Fold 的 Driver 上组合跑旧闭环和新用例。
- timely_quality 保持既有 quality 预算及运行项 对应位置
- retained_cases 原有正反用例保持语义与收尾 对应位置
- latest_driver 组合当前 Driver 并验证结算和折叠逻辑 对应位置
对主干的风险 / Risks
真实回执场景仍校验重复只结算一次、拒绝和丢页;当前主干组合依赖最新 driver,集成与 Todo Unit Fold 共 31 项通过。 墙钟结果来自这台 macOS 主机的成对执行。并行组同时拉起多条 Python CLI 进程,慢宿主的可用 CPU 和进程开销会影响余量。Windows、Linux 和不同限额宿主的尾部耗时待各自验证。
我的整体评价 / Verdict
批准。保留已有回执覆盖并缩短 DSH 质量门禁在本机的执行时间。 相同采集的 405 项测试全部通过。macOS arm64、Node 24.21、pnpm 10.33、Python 3.11 本机 quality 从 87.4 秒降至 38.0 秒。 原生 quick premerge 的 quality、package、runtime 都通过。采用当前主干上的额外组合验证,保留原 405 个测试身份。
English verdict: APPROVE at 0d56998. Independently verified the same 405 test identities, unchanged closeout outcomes, and a 87.4s to 38.0s native quality-phase comparison. The current-main composition also passed 31 focused admission and Todo Unit Fold cases.
…46-queue-current Signed-off-by: lusendong.6789 <lusendong.6789@bytedance.com>
…queue-current Signed-off-by: lusendong.6789 <lusendong.6789@bytedance.com>
Problem
The DSH quality phase has a 120-second per-check budget. The real CLI admission and closeout cases ran serially and pushed the quality phase to 192.21 seconds on the current base.
Change
Run the independent admission and closeout cases with Vitest's bounded concurrency. Each case registers cleanup with its own test context. The managed launcher and timing-sensitive Pause/Start race scenarios run serially before the concurrent group.
Validation
Hosted Core package smoke
The matched split installation reached the CLI and a ready TypeScript Effect runtime. Deep Doctor then looked for the monolithic paths
loopx/cli.pyandscripts/loopx. The required failures and missing paths match #9829. The split installation owner is addressed in #9646, where the hosted Core installation check passed. This PR's changed file is the DSH integration test.DSH PR package job · Goal configuration PR package job · Installation owner package job
Review follow-up
Revision
4fabc2b250againstmain@5d7ac0e622. The complete admission-to-closeout integration suite passed all 15 cases on the updated revision (91.6 s). In a separate single-case comparison, the read-only selection scenario passed on this revision and timed out in the main-branch test. The changed file remains limited to integration tests.