Skip to content

[PR] fix: measure completed preflight round before wall admission - #3732

Merged
ranxianglei merged 1 commit into
ranxianglei:2026-10-17_preflight-client-patiencefrom
ReineLan:2026-10-18_preflight-wall-admission
Oct 24, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:2026-10-17_preflight-client-patiencefrom
ReineLan:2026-10-18_preflight-wall-admission

Conversation

@ReineLan

Copy link
Copy Markdown
Contributor

The wall-clock admission gate in #3590 reads lastRoundMs before recording the just-completed round. The second admission therefore uses zero as its estimate and can start another slow round beyond the intended budget. The stop receipt also counts the rejected round as completed.

This is an additive fix based on #3590's exact head, c38381881d8bb43e6dd9cd8f4ef68af229f51d9e, targeting that PR's branch so its original commits and authorship remain intact. Related: #3573.

  • Record the completed round's duration before evaluating the next admission; count only completed rounds in the stop receipt.
  • Strengthen the HTTP proxy regression to require stopping after the first slow round, a nonzero next-round estimate, an accurate receipt, and persisted progress without cooldown.
  • Make the mock main upstream reject messages above its explicit 12,000-token fixture window, then verify later retries perform additional summaries and eventually fit. The fixture uses ceil(JSON.stringify(messages).length / 4), not a real model tokenizer.

Validation on the exact #3590 base and this fix:

  • Original source + strengthened test: expected failure; a second round was admitted, stopping at 645ms with a 600ms budget.
  • Fixed source: both target tests pass; the slow case stops after one round at 355ms with a nonzero next-round estimate.
  • 22 adjacent tests pass (round budget, emergency fold, client abort, fail-fast).
  • TypeScript typecheck and npm run build pass. Build emitted an existing unrelated CONFIG_DIR_NAME pi host stub warning.

Commands: node --import tsx --test tests/issue3573-preflight-client-patience.test.ts; node --import tsx --test --test-concurrency=1 tests/preflight-round-budget.test.ts tests/preflight-emergency-fold.test.ts tests/preflight-client-abort.test.ts tests/preflight-fail-fast.test.ts; node node_modules/typescript/bin/tsc --noEmit --project tsconfig.json; npm run build.

Only src/preflight.ts and its regression test change. Image sizing remains 1600; no configuration, version, kernel, or runtime installation changes. This fixes wall-clock admission in #3590; it is not a complete fix for the image-accumulation WebSocket 1009 issue. Local validation used real proxy HTTP requests and local stub upstreams; real-client/model E2E and the full remote CI suite have not been run. This stacked branch is not claimed to be rebased onto current master.

@ranxianglei ranxianglei changed the title fix: measure completed preflight round before wall admission [PR] fix: measure completed preflight round before wall admission Oct 18, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复。open+closed 全量检索 "preflight wall admission lastRoundMs round budget" 无命中;关联的 #3573(根因事故)、#3590(引入 wall gate 的前置 PR)、#3586/#3591(同事故的其他修复线)机制与范围均不同——本 PR 是 #3590 机制自身的缺陷修复,不是其中任何一条线的重复。

标签: bug + dsh + scope/kernel + p2 —— #3590 wall gate 的计时点缺陷;触发场景源自 dsh 长会话耐心问题(#3573);属压缩引擎域;能用但有明显超预算行为 → p2。

审核结论(结构化八问)

  1. 是什么问题:[PR] fix: stop preflight marathon rounds that would blow the client's patience wall clock (#3573) #3590 新增的墙钟准入在「记完本轮耗时」之前就读 lastRoundMs,于是第二次准入永远拿零估计放行(只要已耗时间未超预算就会再开一轮慢 summary),单次请求实际可超出耐心预算一整轮;停止回执还把被拒的那轮计入已完成数(off-by-one)。
  2. 什么原因导致的:操作顺序错误——测量点放在决策点之后,[PR] fix: stop preflight marathon rounds that would blow the client's patience wall clock (#3573) #3590 新代码自带的缺陷,不是 v0.1.198 升级后老会话丢失压缩状态:197 折叠过的会话以 117 万 token 原文重放,预压缩超过客户端耐心,老会话看起来「炸了」 #3573 根因的残留。回执侧 wallStopAfterRounds = round + 1 把 break 时未执行的第 N+1 轮算成了已完成。
  3. 影响范围与严重程度:所有 preflight 马拉松走到 ≥2 轮且 summary 上游偏慢的会话(v0.1.198 升级后老会话丢失压缩状态:197 折叠过的会话以 117 万 token 原文重放,预压缩超过客户端耐心,老会话看起来「炸了」 #3573 一类的大上下文场景)。每次受影响请求多跑约一整轮慢 summary(本地复现:600ms 预算下实际 615ms 才停),502 消息里的 "after N round(s)" 数字虚高一轮。折叠照常持久化、重试照常收敛,不丢数据 → 明显问题但可用,p2。
  4. 怎么修复的:把上一轮耗时测量挪到准入判断之前(一行移位),第二次起准就用真实 2×上轮时长估计;回执改为只数已完成轮(round + 1 → round)。生产代码净改动 4 行,另有回归测试强化(mock 主上游加 12k fixture 窗口拒绝,证明重试会持续补摘要直到 payload 真正装下且只放行一次)。
  5. 是否有回归问题:逐条过触碰路径的既有行为——首轮必放行:保持;emergency digest 豁免:保持(测量行在条件外,不改其行为);墙钟停止条件:有意变更(第二次准入从恒零估计改为 2×上轮,更保守、更早停),PR 描述已披露;停止原因文案/日志:数值变准确,字符串格式不变;轮数上限/summary 预算/保护区/tier recovery/wire 形状(502 retryable、无 cooldown):均未触碰,测试有断言钉住。本地实测:目标测试 2/2 过;相邻 22 个 preflight 测试(round budget/emergency fold/client abort/fail-fast)全过;typecheck 干净。变异验证:把 src/preflight.ts 还原到 [PR] fix: stop preflight marathon rounds that would blow the client's patience wall clock (#3573) #3590 原版再跑强化测试,精确失败于新断言(第二轮被放行、615ms 超 600ms 预算、回执误报 "after 3 round(s)" 而实际只跑了 2 轮)——测试有牙,不是假断言。
  6. 是否破坏缓存:不涉及——未触碰任何缓存键/去重/增量游标,折叠持久化路径不变。
  7. 是否改了设计方向:不涉及——仍是 [PR] fix: stop preflight marathon rounds that would blow the client's patience wall clock (#3573) #3590 同一机制,只是把测量点移到正确位置。
  8. 是否引入了新的配置:不涉及——无新 env/config/默认值;PREFLIGHT_WALL_BUDGET_MS=50s 及其 test override 维持 [PR] fix: stop preflight marathon rounds that would blow the client's patience wall clock (#3573) #3590 原样。

CI 与合入顺序(需要 owner 注意)

判定

代码层面通过:修法最小且打在根因(测量顺序)上,回归测试经变异验证有牙,无意外行为漂移,无配置/版本/kernel 变更。待办只剩流程项:#3590 先行合并后 rebase 本 PR 并等全量 CI 绿。合并由人执行。

@ranxianglei ranxianglei added bug Something isn't working dsh p2 scope/kernel labels Oct 18, 2026

@rahul05ranjan rahul05ranjan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traced the round accounting and this fixes two real problems with the wall-budget admission:

  1. The estimate was one round behind. Before the move, at the first admission check (round 1) lastRoundMs was still 0, so estNextMs was 0 and the check degenerated to elapsed > budget — a marathon attempt with a tiny wall budget would always admit a second slow round. With the update hoisted above the check, estNextMs is the duration of the round that just completed, which is the number the decision actually needs. Later rounds weren't stale before (they read the immediately preceding round), so the fix correctly changes only the first-check behavior, and the ×2 headroom in estNextMs keeps the stop from being timing-marginal.

  2. wallStopAfterRounds = round makes the receipt count the rounds that actually completed, matching the log line ("stopping after round ${round}") — the old round + 1 told the client one more round had run than it did, which would skew retry-side sizing.

The upgraded test is a real improvement: the main upstream now counts tokens and rejects >12k payloads, so the test can assert exactly one fitting payload ever reaches it, and the new 400 branch proves non-fitting attempts never leak past preflight. The stopsBefore indexing into the captured stop lines is sound given single-session log capture.

@poboll poboll left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving after independent verification — the diff, the mechanism, and the red/green behaviour all check out.

Root cause confirmed by reading the loop. lastRoundMs was assigned after the admission gate that reads it:

if (round > 0 && !emergencyFold) {
    const estNextMs = lastRoundMs > 0 ? lastRoundMs * 2 : 0;  // read
    if (elapsedMs + estNextMs > budget) { ... }
}
if (lastRoundStart > 0) lastRoundMs = admissionNow - lastRoundStart;  // written after

So on the second round the estimate still reflects the state before the round that just finished — it lags one round behind precisely when the gate needs it. Moving the assignment above the read is the minimal correct fix.

The receipt off-by-one is also right. The loop is for (let round = 0; ...) with the gate at round > 0. When the gate fires at round = N, rounds 0..N-1 have completed — N rounds — and round N never runs because the break precedes processTurn. So round + 1 overcounts by one and round is correct. I traced wallStopAfterRounds to its only consumer, the detail string at src/preflight.ts:2770, so the impact is confined to that receipt text.

Red/green reproduced locally. I ran the strengthened test against the parent commit c3838188 and it fails as the PR claims:

not ok 1 - #3573 slow summary rounds: ...
  error: 'attempt 1: the first slow round must prevent admission of a second round'

with the log showing the pre-fix behaviour — stopping after round 2 (a second round admitted) and stopped at the client-patience wall budget after 3 round(s) in the receipt. On the PR head both target tests pass.

Validation run here:

  • tests/issue3573-preflight-client-patience.test.ts — 2/2
  • the four adjacent suites named in the description (preflight-round-budget, preflight-emergency-fold, preflight-client-abort, preflight-fail-fast) — 22/22, matching the stated count
  • all 26 preflight* suites — 152 pass / 0 fail
  • tsc --noEmit --project tsconfig.json — clean

The scope is honest too: only src/preflight.ts and its regression test change, no config/version/kernel/runtime-install surface, and the body explicitly scopes this away from the image-accumulation WebSocket 1009 issue rather than quietly widening. The stacked branch not being rebased onto current master is stated up front rather than discovered later.

Good fix, and unusually well-evidenced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dsh p2 scope/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants