Repository navigation
Conversation
`test-shard` runs `--splitting-algorithm least_duration`, which needs one duration map covering the whole collection. Nothing in the repository or the workflow produced that map (`git log --all -- .test_durations` is empty), so the algorithm silently degrades to equal-weight rotation. The workflow comment on the shard run already states this, and the last measured `main` run shows the consequence: every shard was handed 7307-7308 cases, and in the same 3263s deadline they finished 3694 / 3993 / 4632 / 4708 / 6275 / 6891 -- a 1.86x spread in per-case cost. This makes the splitter measurable: - each shard runs with `--store-durations`, writing the `.test_durations` subset it actually executed; - the subset is uploaded as `python-durations-<shard>`; - a new `test-durations-merge` job unions all six subsets into one baseline and saves it to the Actions cache; - the shard job restores that baseline before collection, keyed by commit with a prefix fallback so the newest available baseline is used. Duplicate ids keep the larger duration. An optimistic weight would place a slow case into a shard that already runs long, which is exactly the failure this baseline exists to prevent. `scripts/ci/merge_test_durations.py` owns the merge: it drops non-finite, negative, boolean and non-numeric entries, treats a non-object payload as an explicit error, discovers subsets anywhere under a `download-artifact` tree, and writes a sorted map atomically so a half-written baseline is never readable. `scripts/ci/test_merge_test_durations.py` covers each of those boundaries plus the empty-input exits. Degradation is deliberate: a first run has no cached baseline, so the split is unchanged until the first merge job saves one. `.test_durations` is gitignored and never committed. Verification: `python3 -m unittest discover -s scripts/ci -p 'test_*.py'` -> 32 tests OK (8 new). The workflow parses to 21 jobs with the merge job and the three shard steps present. Limits: this balances the split; it does not add capacity. The reconstructed demand in loopx-project#9567 (>=60,036 CPU-seconds against 39,156 available) still exceeds the current six-lane, two-worker budget even under a perfect split, so this is a prerequisite for that capacity decision rather than a substitute for it. The baseline only becomes effective after a run has saved one, so the benefit is visible from the second run onward. Refs loopx-project#9567 Signed-off-by: ChengLong GU <88359731+gcl-coder@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
动机 / Motivation
依赖 Python Tests 为提交提供完整回归结论的维护者和贡献者。 原工作流没有耗时缓存,同一测试集合按等权分到六片。问题记录了各片耗时差距和超时后未跑完的用例。 一次全量运行中,六个分片可在不同时间启动。第一个分片在没有缓存时选组,后面的分片恢复可用的耗时基线。 同用空缓存或同用一份缓存时,18 项均恰好执行一次。把第 1 片的无缓存结果与第 2–6 片的有缓存结果组合,六片均退出 0,却漏掉 test_case_11,并重复 test_case_06 和 test_case_12。 在 macOS 用 Python 3.11、pytest-split 0.11.0 与 xdist 3.8.0 执行实际分片。用独立目录模拟恢复,在本地执行合并 CLI。未查询托管 CI,未测实际缓存服务时序或整轮提速。 历史测量与问题范围
改动思路 / Approach
runner 恢复耗时,pytest-split 按耗时选组并写数据。新任务归并 JSON,然后将派生数据另存以供下轮使用。 pytest-split 仍拥有选组。工作流负责确定矩阵使用的快照和发布条件。覆盖率及上游成功继续由原资格门消费。 在创建矩阵前固定一份只读耗时快照,让六片共同使用该快照,或一起按等权回退。只有获准且产出实测数据的分片才能触发缓存发布。 当前 PR 的交付范围应是既有六分片共享同一输入,以及按原工作流准入发布耗时,保留现有类型检查范围。
具体改动 / Changes
评审提交 3c1b27d,共同祖先 811c1a1。4 个文件净改 +275/-1。实际共同祖先用于提案 diff,当前 GitHub 目标主干用于验收规范。 以 d0df4f9 的现行规范核对「六片互斥并覆盖同一全量集合」「分类豁免保留」「原资格门独立」。新增单测验证重复键取最大值、过滤异常值、确定顺序和空输入退出。忽略规则为本地缓存提供排除路径。 仓库验收规范
关键代码讲解
- Restore the Python test duration baseline。每个矩阵成员独立按可变前缀恢复。 源码
- Upload the measured duration subset。插件 0.11.0 默认保留旧键再写入本片测量,热启动产物含原快照。 源码
- test-durations-merge。仅排除取消,未检查 test-shard 资格。 源码
- merge_durations。相同 ID 取最大值。热启动产物中的旧高值会参与归并。 源码
- main。扫描、校验、原子替换。文件缺失或条目为空时退出 1。 源码
- Type-check kernel contracts。为现有 kernel 类型门启用静默导入遍历。 源码
对主干的风险 / Risks
[P1] 缓存不一致会漏跑和重复执行用例。 同用空缓存或同用一份缓存时,18 项均恰好执行一次。把第 1 片的无缓存结果与第 2–6 片的有缓存结果组合,六片均退出 0,却漏掉 test_case_11,并重复 test_case_06 和 test_case_12。 当前六条并发队列独立恢复可变缓存,后启动的分片可能命中不同输入。原汇总检查成功状态和覆盖报告,这两项都不足以证明每个用例执行一次。在创建矩阵前固定一份只读耗时快照,让六片共同使用该快照,或一起按等权回退。只有获准且产出实测数据的分片才能触发缓存发布。 恢复步骤 缓存匹配规则
[P2] 无 Python 分片时仍尝试合并。 未启用全量 Python 的运行会跳过 test-shard。新合并任务只检查工作流未取消,一样进入下载。没有分片产物时,实际合并命令以 1 退出。 沿用 Python 分片准入条件,区分已有部分测量、无输入与取消。让无输入跳过可选采集。 新作业条件 Actions 状态函数
[P2] 耗时补丁缩小现有类型门范围。 kernel-contracts 也改用 --follow-imports=silent,停止报告仅由 import traversal 带入的文件中的诊断。原工作流明确把这个检查和下方显式静默遍历的 adapter 检查区分开。 保持当前类型检查命令,将范围变更与其验收另行提交。 现行工作流 候选
CI 工具 unittest 32 项、Python 工作流测试 1063 项、净 diff whitespace 检查通过。既有六分片测试为各片提供同一输入,不能检出矩阵执行期间缓存发生变化。 同一 run 的两次 attempt 展开得到相同保存键,无法覆盖已存在的缓存。热启动测量还保留旧键,取最大值会把历史高点继续写入。缓存生命周期可以随基线范围一同明确。 GitHub 运行变量
我的整体评价 / Verdict
REQUEST_CHANGES。当前 PR 的交付范围应是既有六分片共享同一输入,以及按原工作流准入发布耗时,保留现有类型检查范围。 改动限于工作流、合并脚本、测试和忽略规则,无产品页面变更。 实际 runner 上的基线建立、重跑与整轮耗时仍待验证。
English verdict: REQUEST_CHANGES at 3c1b27d. Mixed timing inputs omitted and duplicated tests even though all six real shard processes passed. Pin one input for the matrix, gate the optional merger on actual shard admission, and preserve the current type-check scope.
| with: | ||
| path: .test_durations | ||
| key: python-test-durations-${{ runner.os }}-${{ github.sha }} | ||
| restore-keys: | |
There was a problem hiding this comment.
[P1] 缓存不一致会漏跑和重复执行用例
同用空缓存或同用一份缓存时,18 项均恰好执行一次。把第 1 片的无缓存结果与第 2–6 片的有缓存结果组合,六片均退出 0,却漏掉 test_case_11,并重复 test_case_06 和 test_case_12。 在创建矩阵前固定一份只读耗时快照,让六片共同使用该快照,或一起按等权回退。只有获准且产出实测数据的分片才能触发缓存发布。
There was a problem hiding this comment.
Fixed in d03a2cdc3. Your reproduction is the right failure mode: divergent weights produce different partitions, so cases duplicate and vanish while all six shards exit 0.
test-durations-snapshot now materializes the baseline once, before the matrix exists, and publishes python-durations-baseline. All six shards download that single artifact — identical for every shard, or absent for every shard. With no history the snapshot pins {}, which pytest-split reads as equal weights, so a first run splits exactly as today. The download is continue-on-error, so even a snapshot failure degrades to that same equal-weight split rather than turning six shards red.
Per-shard subsets are now python-durations-shard-<n> so the merge pattern (python-durations-shard-*) cannot pick up the snapshot artifact and cannot resurrect durations for deleted tests.
| test-durations-merge: | ||
| # Feed the next run's split with measured cost instead of equal weights. | ||
| # Writes are keyed by run id so a re-run never collides with a saved cache. | ||
| if: ${{ !cancelled() }} |
There was a problem hiding this comment.
[P2] 无 Python 分片时仍尝试合并
未启用全量 Python 的运行会跳过 test-shard。新合并任务只检查工作流未取消,一样进入下载。没有分片产物时,实际合并命令以 1 退出。 沿用 Python 分片准入条件,区分已有部分测量、无输入与取消。让无输入跳过可选采集。
There was a problem hiding this comment.
Fixed in d03a2cdc3. The merge job now reuses the shard admission (always() && python_tests == 'true' && !cancelled()) instead of only checking for cancellation.
On the script side the three cases are now distinct: no subsets produced → skip, all subsets empty → skip, and neither writes an output file; malformed input still raises. Tests assert the skip paths leave no .test_durations behind, so an absent run cannot overwrite a good baseline with an empty one.
| # import traversal, so the gate never reports its own 17 files clean. | ||
| - name: Type-check kernel contracts | ||
| run: python -m mypy | ||
| run: python -m mypy --follow-imports=silent |
There was a problem hiding this comment.
[P2] 耗时补丁缩小现有类型门范围
kernel-contracts 也改用 --follow-imports=silent,停止报告仅由 import traversal 带入的文件中的诊断。原工作流明确把这个检查和下方显式静默遍历的 adapter 检查区分开。 保持当前类型检查命令,将范围变更与其验收另行提交。
There was a problem hiding this comment.
Correct, and it was my mistake — I copied the workflow between two worktrees and carried the kernel-contracts change along with the split work. d03a2cdc3 reverts it to python -m mypy; this branch now touches only the split baseline, and the scope change stays in #9602 where it is approved and reviewed on its own terms.
The note that the original workflow deliberately separates this check from the adapter boundary below is exactly why it should not have been folded in here.
…ission Review follow-up for loopx-project#9604. **P1 — divergent weights duplicated and dropped cases.** Every shard restored `.test_durations` on its own. A cache saved mid-run, or branch-scoped visibility, lets one shard split with measured weights while another splits with equal weights. Different weights produce different partitions, so some cases run twice and others never run, while all six shards still exit 0. Now `test-durations-snapshot` materializes the baseline once, before the matrix exists, and publishes it as `python-durations-baseline`. All six shards download that one artifact, so the input is identical for every shard or absent for every shard. With no history the snapshot pins `{}`, which pytest-split reads as equal weights — a first run therefore splits exactly as it does today. The download is `continue-on-error` so a snapshot failure degrades to that same equal-weight behaviour instead of turning the suite red. **P2 — the merge ran with no shards.** `if: !cancelled()` let it start when `test-shard` was skipped, download nothing, and exit 1. It now reuses the shard admission (`python_tests == 'true'`), and `merge_test_durations` separates the three cases: no subsets produced and all-empty subsets are skips that write nothing, while malformed input still raises. Its tests assert exactly that, including that a skip leaves no baseline file behind. **P2 — the type gate leaked into this branch.** The workflow copy carried the `kernel-contracts` `--follow-imports=silent` change, which belongs to loopx-project#9602. Reverted to `python -m mypy`; this branch now touches only the split baseline. Per-shard subsets are published as `python-durations-shard-<n>` so the merge pattern cannot pick up the snapshot artifact and would not resurrect entries for deleted tests. `scripts/ci/test_review_gate.py` asserted `needs == ["changes", "chat-bundle"]` for every heavy lane. That invariant is about admission, and it still holds: the shard's `if` never reads the snapshot. The assertion now allows a data-only prerequisite as long as it stays out of the predicate, and the ancestor set includes it explicitly. Verification: `python3 -m unittest discover -s scripts/ci -p 'test_*.py'` -> 34 tests OK. Workflow parses to 22 jobs; shard `needs` includes the snapshot, merge `if` requires `python_tests == 'true'`, merge pattern is `python-durations-shard-*`, and `kernel-contracts` runs bare `python -m mypy`. Refs loopx-project#9604 Signed-off-by: ChengLong GU <88359731+gcl-coder@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
动机 / Motivation
维护者和贡献者依赖六片 Python Tests 的完整结果。Python Tests 需要在既有六片、每片两个 worker 的预算内完成同一套测试。这个 PR 为 pytest-split 增加实测耗时反馈,让后续运行能按耗时分片。本地用同一个 18 case 案例集执行真实 pytest-split 0.11.0 和 xdist 3.8.0。六片使用同一份已知快照时,每个 case 恰好执行一次。旧路由让第 1 片使用空快照,其余片使用已知快照,六片都成功退出,但两项漏跑、两项重复。整轮容量和托管 runner 的墙钟收益仍待验证。 原始问题 六片覆盖约束
改动思路 / Approach
固定一份缓存快照,再由 pytest-split 负责分组。各片运行后上传耗时,归并器校验输入、聚合同轮测量并原子写出下一轮 JSON。复用现有分片、准入、合并门和 pytest-split 格式。共享快照解决了输入不一致。要闭合持续反馈,每片还需要把本轮实测与上轮估计区分开。
具体改动 / Changes
评审提交 d03a2cd,提案共同祖先 811c1a1,当前目标主干 d0df4f9。完整 diff 为 5 个文件,+339/-3。此轮新增共享快照,合并任务以 Python 分类为条件,恢复原 kernel mypy 命令。按规范逐项核对后,六片完整分组 complete-six-way-split 和空产物处理 skipped-python-lane 通过,实测耗时替换旧值 fresh-duration-observations 仍未满足。归并器区分缺失、全空与畸形产物;新增工作流结构和脚本边界测试,忽略规则排除本地耗时缓存。
关键代码讲解
- test-durations-snapshot。在矩阵前一次性恢复耗时,缺历史时写入空 map,再发布单份输入。 源码
- test-shard。每片读取同一 artifact,保留六片与两个 worker。下载步骤会使用正常失败处理,未下载到输入的分片停止。 源码
- test-durations-merge。只匹配分片产物,按分类和取消条件运行。CLI 无输入时退出 0 且不生成文件,畸形 JSON 仍以非零退出。 工作流 归并入口
- merge_durations。读取并滤除无效条目,重复 ID 取最大值,然后原子发布。输入格式相同,读取历史和写入实测仍共用一个文件。 源码
- kernel-contracts。原
python -m mypy及其 import traversal 已恢复。 源码
对主干的风险 / Risks
[P2] 合并仍会让旧估计覆盖本轮实测。 当前命令启用 --store-durations,插件会在恢复的 map 上覆盖本片执行过的 ID,并把其他 ID 保留在同一文件。固定快照后,未执行某个 case 的其他五片都携带该 case 的旧值。六片实跑各自更新了本片值,18 项最高实测约 0.0003 秒;用候选的归并 CLI 处理六份真实产物后,18 个 100–219 秒的合成旧权重全部原样返回。只将同一测试命令加上 --clean-durations,归并器就返回 18 项新值,分组和覆盖保持一致。请让分片上传只含本轮实际观测的记录,再按明确规则继承本轮缺测条目,并在热启动的六片归并回归中检查旧高值能下降。 插件 0.11.0 当前分片命令
原「六片各自恢复」缺口已修复。空历史六片也恰好完成 18 个 case。原空输入退出失败已修复,畸形输入仍拒绝。34 项 CI 脚本单测、净 diff 检查及标准预合并门禁通过。GitHub 的 run_id 在 rerun 中保持相同,此版保存键仍需处理重跑产生更新样本时的复用问题。这里用实际本地分片及归并验证耗时反馈,托管缓存重跑、真实权重分布和全轮收益均未实测。 GitHub 运行变量
我的整体评价 / Verdict
REQUEST_CHANGES。保留单快照和原 Python 分片准入,补上实测子集与旧估计的归并边界。修订后复跑同输入的六片正反对照。当前准确的结果是分片覆盖已恢复,热启动仍可把已过时的估计写回下轮。
English verdict: REQUEST_CHANGES at d03a2cd. One pinned snapshot restores exact six-shard coverage. The current writer still republishes every stale weight over fresh measurements in the real six-shard replay.
Motivation
test-shardsplits with--splitting-algorithm least_duration, which needs oneduration map covering the whole collection. Nothing produced that map: the
repository has no
.test_durations, andgit log --all -- .test_durationsisempty. The workflow comment on the shard run states the consequence plainly —
Without timing history least_duration alternates equal-weight tests.The last measured
mainrun shows what equal weights cost:Nearly identical case counts, a 1.86× spread in cost (0.947 s/case on the
lightest shard, 1.766 s on the heaviest). The split is balanced by count and
therefore unbalanced by time.
Changes
.github/workflows/python-tests.ymltest-shardrestores.test_durationsfrom the Actions cache beforecollection (
actions/cache/restore, keyed by commit with a prefix fallback sothe newest available baseline is used).
--durations-path .test_durations --store-durations, soeach shard writes back the subset it actually executed.
python-durations-<shard>.test-durations-mergejob unions the six subsets into one baseline andsaves it with
actions/cache/save. The save key carriesrun_id, so a re-runnever collides with an already-saved cache.
scripts/ci/merge_test_durations.py— owns the merge. Duplicate ids keep thelarger duration: an optimistic weight would place a slow case into a shard
that already runs long, which is the failure this baseline exists to prevent. It
drops non-finite, negative, boolean and non-numeric entries; treats a non-object
payload as an explicit
ValueError; discovers subsets anywhere under adownload-artifacttree; and writes a sorted map through a same-directorytemporary file so a half-written baseline is never readable.
scripts/ci/test_merge_test_durations.py— 8 boundaries: max-value merge,malformed entry rejection, non-object payload, artifact-tree discovery, missing
directory, deterministic sorted output, and both
main()failure exits..gitignore—.test_durationsis a cache artifact and is never committed.Verification
8 of those are new. The workflow parses and resolves to 21 jobs:
Degradation, stated up front
back to equal weights exactly as today. The benefit appears from the second run
onward — this PR establishes the loop, it does not itself turn
maingreen.(≥60,036 CPU-seconds against 39,156 available across six shards × two workers)
still exceeds the budget under a perfect split. Balancing is a prerequisite for
that capacity decision, not a substitute for it.
as-is; no smoothing across runs. If maintainers want it, an exponential decay
over cached history is a natural follow-up, but it is not taken here.
Refs #9567
🤖 Generated with Claude Code