Skip to content

fix(test): key the Vcs render budget to the in-process bare-spawn ratio (#423) - #436

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/423-vcs-budget
Oct 19, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/423-vcs-budget

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #423.

Problem

vcs_segment_render_p50_within_the_render_budget false-armed master twice in two days on the 2-core shared CI runner:

  • run ce5f225: p50 47.7ms against the 45ms budget
  • run 76f148b: p50 49.4ms against the 45ms budget (max 73.2ms)

The segment is one git status --porcelain=v2 --branch spawn and nothing else; on that runner the bare spawn alone costs 45-50ms, so a unit-level absolute p50 has no verdict on shared hardware.

Fix (ticket option 2 primary, option 1 as backstop — #604's ratio shape over #337's hard/soft spirit)

Three-door composite in the same test:

  1. Primary, relative: segment p50 <= 1.5x the p50 of the bare spawn it wraps, mirrored flag-for-flag off git_prompt::read_status and measured in this process, interleaved sample-for-sample (21 pairs). A uniform runner slowdown moves both numbers and the ratio holds; a real regression does not — a second spawn doubles the ratio (~2x), a fixed quantum (drain thread ~15ms, the CREATE_NO_WINDOW console ~28ms) shows up as ratio on any machine. A 20ms floor guards the degenerate-zero baseline.
  2. Backstop, absolute: p50 > 135ms (3x the old budget) fails regardless of ratio, so a hang or an unbounded status sweep cannot hide behind a slow baseline. Worst CI sample ever observed: 73.2ms.
  3. Soft warn: the old 45ms budget is demoted to a printed warn (fix(perf): soft overs warn, hard cap still fails the release (run 38489787748 calibration) #337's soft-over-warn), so CI slowness stays visible without holding the gate.

Teeth (mutation-verified)

Mutation Result
+20ms sleep in the render path red — p50 42.3ms vs budget 29.9ms (the old flat gate would have passed this locally at 42.3 < 45)
budget multiplier shrunk to 1.02 (simulated real regression) red — true ratio 1.05 > 1.02
second git status spawn injected into read_status red — ratio 2.1

False-red immunity

10/10 consecutive green runs locally (worst healthy ratio 1.05-1.27). The 1.27 run is the money shot: background load pushed one sample to 353ms and p50 to 37.6ms while the interleaved baseline rose to 29.5ms in lockstep — the exact CI failure mode that armed the old gate — and the ratio gate stayed green.

Gates

  • cargo test -p niubash-runtime --lib -- --test-threads=1: 554 passed / 0 failed
  • cargo fmt --check --all: clean
  • RUSTFLAGS="-D warnings" on lib + test profiles: clean (clippy is not a CI gate here; the only clippy hits in the touched file are pre-existing at line 394, outside this diff)

…io (#423)

The flat 45ms p50 budget false-armed master twice on the 2-core shared
CI runner (ce5f225: p50 47.7ms; 76f148b: p50 49.4ms against max
73.2ms) - the bare `git status` spawn alone costs that much there, so
a unit-level absolute p50 has no verdict on shared hardware.

Three-door composite, #604's ratio shape with #337's hard/soft spirit:
- primary: segment p50 <= 1.5x the p50 of the bare spawn it wraps,
  interleaved sample-for-sample in-process. A uniform runner slowdown
  moves both numbers and the ratio holds; a real regression does not -
  a second spawn doubles the ratio, a fixed quantum (drain thread,
  hidden console) shows up as ratio on any machine.
- backstop: p50 > 135ms (3x the old budget) fails regardless of ratio,
  so a hang or an unbounded sweep cannot hide behind a slow baseline.
- the old 45ms budget is demoted to a soft warn, printed not gated.

Teeth proven by mutation: +20ms sleep in the render path -> red
(p50 42.3ms vs budget 29.9ms; the old flat gate would have passed this
locally); budget multiplier shrunk to 1.02 -> red; a second spawn
injected into read_status -> red (ratio 2.1). 10/10 consecutive green
runs locally, worst healthy ratio 1.27 (under background load that
pushed one sample to 353ms - the old gate's exact failure mode).
@caomengxuan666

Copy link
Copy Markdown
Member Author

CR 结论:APPROVE-WITH-NITS(无 BLOCKER)

独立复核(自建 worktree @ dde0174,merge-preview 对 origin/master b032a66 干净:master 新进的 #433 只动 repl.rs / typeahead_guard.rs / interactive.rs,与本 PR 唯一文件无交集,不冲突)。以下全部为本机/CI 实测,非转述实现代理。

1. 门设计审计(核心)

  • 逐 flag 镜像核实:bare_status_spawn 与 git_prompt::read_status(git_prompt.rs:170)九项配置逐项一致——-c core.fsmonitor=false、--no-optional-locks、status --porcelain=v2 --branch、同 cwd、null stdin、scratch 文件 stdout、null stderr、GIT_OPTIONAL_LOCKS=0 + GIT_TERMINAL_PROMPT=0、均无 CREATE_NO_WINDOW。基线只省掉段自己的 capped 重读 + parse——偏置方向正确(量的正是段的增量),无漏 flag 偏置。
  • 交错实现核实:21 对逐对交错(每对先基线后段),各自独立排序取 index 10 做 p50。p50 对瞬时尖峰稳健:本机一次 max 103ms、CI max 44ms 均未影响判定。
  • 与/或关系核实:两 assert 是 AND——比值门通过不豁免 135ms 硬上限。挂死场景读通:read_status 走满 STATUS_TIMEOUT=2000ms → p50≈2s ≫ 135ms 必红,无法靠慢基线隐藏。45ms soft warn 纯打印不拦,语义正确。
  • 判别力边界(给结论):实测健康带 CI 1.01 / 本机 1.04-1.13 / 负载形态 1.27,trip 线 1.5。固定量化回归的 trip 条件是 q > 0.5×baseline:桌面级 baseline(本机 ~18-22ms)时 +15ms drain 线程即红(~1.75x);但 CI-class baseline(39-50ms)下同一回归只有 1.33-1.38x,不红,仅 45ms soft warn 可见;+28ms 隐藏控制台在 baseline < 56ms 时红(1.56x@50ms,边际),baseline > 56ms 后也滑入放行带。**结论:牙齿在慢 runner 上按 0.5×baseline 衰减——这是票面方案 2 的固有代价(旧平面门已在同一 runner 两次假红,更差),而第二 spawn(~2.1x)这类决定性回归全带宽捕。接受,不构成阻塞。**漂移方向性:CI spawn 变慢 → 基线抬高 → 比值预算等比抬高(均匀慢化不产生新假红向量);唯一兜底变 135ms 硬上限,需 segment p50 > 135ms 才可触,对 CI 实录最差 p50 49.4ms 有 ~2.7 倍劣化余量。

2. 有牙复验(本机自跑)

+20ms sleep 注入渲染路径 → 红:p50 43.73ms vs 比值预算 30.64ms(比值 2.14),prompt_segments.rs:1124 的相对门 assert 触发、135ms 上限正确保持沉默。附带证实:43.7 < 45,旧平面门本会放行这一突变——PR 表述属实。突变已还原,worktree 树干净(git diff 0 行)。

3. 防假红复验

本机 10/10 连跑绿(比值 1.04-1.13)。更有说服力的是本 PR 自己的 CI run(打红 master 的那类 2 核共享 runner):VCS budget: baseline p50=39.4ms segment p50=39.9ms ratio budget=59.1ms max=44.1ms ——比值 1.01,比值余量 1.48 倍、硬上限余量 3.4 倍。ce5f225e/76f148b1 的负载形态(p50 47-49ms)落入新门绿区,闭合自洽。

4. 回归门禁(本机复跑)

  • cargo test -p niubash-runtime --lib -- --test-threads=1:554 passed / 0 failed
  • cargo fmt --check --all:干净
  • RUSTFLAGS="-D warnings" lib + tests 两档:干净
  • CI 11 项检查全绿(build-and-test、双 cross-check、4×cross-target、musl smoke)

5. 夹带扫描

单文件单提交(dde01742),+116/-14 全在 prompt_segments.rs;两个 hunk(994/1018 行)均在 mod tests(563 行起)内——无生产代码、无 Cargo.toml / CI workflow 夹带。

6. #423 票面

关闭引用评论已挂,ce5f225e 与 76f148b 两实录均给出新门下的比值复盘(≈1.05-1.10 → 绿),与我的 CI 实测(1.01)一致。

NIT(不阻塞,择机处理)

  1. VCS_BUDGET_RELATIVE_MULT 的 doc 称 1.5x 仍可捕 drain 线程(~15ms 固定量化)——这对桌面级 baseline 成立,但对本 PR 要救的 CI-class baseline(39-50ms → 1.33-1.38x)不成立,该场景只剩 soft warn。建议把这句收窄("在快基线上可捕")或补一句诚实记录:固定量化盲带 q < 0.5×baseline 不设硬门。防后人删 scratch 文件回退 drain 线程后在 CI 见绿而误判门仍有效。
  2. bare_status_spawn 在 File::create/spawn 失败时静默推入近零样本——单次失败 p50 无碍,纯理论边角,可不动。

不合并。复核用 worktree 已删除。

@caomengxuan666
caomengxuan666 merged commit f1e961d into master Oct 19, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/423-vcs-budget branch October 21, 2026 08:14
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.

CI 抖动:vcs_segment_render_p50_within_the_render_budget 计时预算在共享 runner 上会假红(ce5f225e 实录 p50 47.7ms/预算 45ms)

1 participant