Skip to content

[PR] Pin-first (#3977): escape-hatch characterization pins, then size-evidence ledger + verdict state machine - #3979

Merged
ranxianglei merged 8 commits into
2026-10-20_batch-b-fold-budgetfrom
2026-10-20_size-evidence-ledger
Oct 24, 2026
Merged

ranxianglei merged 8 commits into
2026-10-20_batch-b-fold-budgetfrom
2026-10-20_size-evidence-ledger

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Implements the pin-first discipline of #3977: 先打桩,盯住测试和证明,然后开干。

Stacked on #3971 (batch-B integration) — retarget to master after that lands. This PR opens with the pins only; the extraction commits (steps 1-3 of the plan) land on this branch behind them.

为什么先打桩

纯抽取重构的护栏不是"相信等价",而是把当前每个逃生口的可观测行为锁死。#3846/#3918 已钉住 probe 口、verdict 分类、模型/origin 独立性;本 PR 补上没有钉的四条边:

Pin 锁住的行为
P-IMG-a 图片仲裁口本体:无证据时越窗图片载荷放行,由上游仲裁计费(#496/#1800)
P-IMG-b 图片仲裁口×拒签证据:scoped 413 之后同载荷保持本地拒绝,零上游调用(#3846 守卫)
P-DIV 拒签后可折载荷:折叠后 200 放行——证据关的是 forward-once 逃生口,不是合法的折后转发(边界)
P-LEARN 校准环边界:带真实 token 数的上游 400 今天什么都没教会(413 标题逐字节相同)——第 4 步 learnFromOutcome 的翻转目标(#3900)

验证

路线(后续提交落在本分支)

Closes #3977

Behavior change (step 4b — disclosed per review rule)

Status note (review round 2)

…ence ledger extraction

Characterization pins (先打桩), all locking CURRENT behavior on the batch-B
integration base so the pure-extraction refactor (steps 1-3 of #3977) has a
hard guardrail:

- P-IMG-a: image-dominated over-window payload with no local evidence rides
  for upstream arbitration (#496/#1800 hatch itself).
- P-IMG-b: after a scoped local 413 the same payload stays refused, zero
  upstream calls — the #3846 evidence guard on the image hatch.
- P-DIV: after a scoped local 413 a foldable payload folds and the POST-FOLD
  view forwards (200) — evidence closes the forward-once escape hatches, not
  the legitimate folded forward.
- P-LEARN: an upstream 400 whose body states the real token count changes
  NOTHING in the estimator's verdict (titles byte-identical) — @flip-target
  for step 4 learnFromOutcome(overflow-400) (#3900).
@ranxianglei ranxianglei changed the title Pin-first (#3977): escape-hatch characterization pins, then size-evidence ledger + verdict state machine [PR] Pin-first (#3977): escape-hatch characterization pins, then size-evidence ledger + verdict state machine Oct 20, 2026
ework-agent added 2 commits October 20, 2026 21:46
… and the final verdict classification

Zero behavior change (all 171 guard tests green, incl. the four #3977 pins):

- src/size-evidence.ts: localRefusals store (#3846: noteLocalRefusal /
  localRefusalCovers / shape-filtered read) and the preflightDeadEnd write
  side (#728) moved verbatim from server.ts. Metadata keys and shapes
  unchanged; legacy session files read exactly as before.
- src/preflight-verdict.ts: the final-verdict expressions (status ternary
  #3461, progressContinues #3918, retryable #2189, progress detail suffix,
  contentDeadEnd) moved verbatim as pure functions over a structural
  VerdictWalkSlice — server.ts keeps the walk object and calls these.
- The dead-end READ block stays inline (its replay/eviction semantics are
  exactly as rich as the block that owns them); its write now goes through
  armDeadEnd.

Step 2 (escape hatches consult fitEvidence) and Step 3 (single render
point) land behind this on the same branch.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复 —— 本条是 #3977 计划步骤 0(pin-first 打桩)的实现 PR,#3977 主线程已声明与 #3971(batch-B 集成底座)/#3916(状态板)的关系;open+closed 检索无同主题平行在途条目。

标签: bug scope/kernel p1(缺陷族根修实现;preflight 折叠判定核心域;伞下含 #3900 无限 400 环类)。

状态:本 PR 是本机此前开的(commit author ework-agent),按规则不重做——正在拉分支核对代码、查 CI、跑定向测试,随后按八问体例给审核结论。初步已发现两处待处理:① CONFIGURATION.md/zh 混入了一对互相矛盾的重复配置行(与本 PR 目的无关,需回退);② P-LEARN 钉子的基线对比方式有个漏洞(只比了 400 之后的两次标题,没和 400 之前的基线比,一次性的 k̂ 漂移抓不住)——核实后直接在 PR 分支上修。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Step 1 落地(95e7808 + 9151d22):纯抽取,零行为变化。

Step 2(逃生口改走 fitEvidence/转移表)、Step 3(单一渲染点)、Step 4(learnFromOutcome 翻转 P-LEARN)按 checklist 继续。

@ranxianglei ranxianglei added bug Something isn't working p1 scope/kernel labels Oct 20, 2026
Review fix on the pin-first PR: the original P-LEARN compares two POST-400
titles, so a one-time uptake of the stated count (single k recalibration or
a one-off overflow-arm floor) would leave them equal and pass vacuously —
exactly the drift class step 4 flips. The control session refuses the same
payload without ever seeing the 400; today both titles are byte-identical,
and learnFromOutcome(overflow-400) must move the treated title away from it.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Step 0(打桩)+ Step 1(纯抽取)审核通过,两处小问题已直接修进分支。

独立复核(不是照抄你的验证清单)

已修两处(已推)

  1. 19bea6790 P-LEARN 补对照会话(P-LEARN-b):原 P-LEARN 比的是两个「都见过 400」之后的标题——stated count 被一次性吸收(单次 k̂ 重标定或一次性 overflow-arm floor)时两个标题照样相等,pin 空转。补一个「从未见过 400」的对照会话,断言同载荷拒签标题逐字节一致;今天绿(本地 5/5),Step 4 翻转后 treated 标题必须偏离对照——这才是真正的 flip-target。
  2. PR 正文补了 <!-- ework-agent-pr --> 标记(agent 自唤醒环路防护)。

更正首条回复:CONFIGURATION.md 重复行噪音是 stale-base 产物——batch-B base 推进到 b9f439e(docs regenerate)后,当前完整 diff 零文档变更,无需回退。

八问(Step 0+1 轮)

  1. 是什么问题:size-evidence 账本迁移的第一步——把散在 ~700 行 if-chain 里的证据存储和最终判决分类搬出去,行为零变化。
  2. 什么原因导致的:Root fix: server-side size-evidence ledger + preflight verdict state machine (fold-budget/eligibility B-class family) #3977 根因(知识与策略融合、逃生口各自只认出生时的 store);本步只搬家不改判。
  3. 影响范围与严重程度:对用户零可见影响;若抽取破坏字节等价则是 p1 级 wire 漂移——已被钉+全量测试排除。
  4. 怎么修复的:verbatim 搬到 src/size-evidence.ts(store)+ src/preflight-verdict.ts(纯函数),调用点换同参调用;另加一个对照会话 pin。
  5. 是否有回归问题:触碰路径承担的既有行为(五判决表达式、localRefusals 读写、dead-end 武装、fail-fast 消息渲染)逐项审过——全部保持;高危模式逐项过:无语义漂移(逐字符一致)、无阈值/时序/输出格式漂移(消息模板含进度后缀逐字节 diff 一致)。
  6. 是否破坏缓存:不涉及——缓存/prefix-affinity 路径未触碰;metadata key 不变,既有持久化会话不受影响。
  7. 是否改了设计方向:是,但正是 Root fix: server-side size-evidence ledger + preflight verdict state machine (fold-budget/eligibility B-class family) #3977 规划的方向(判定收口到单一模块,Step 2/3 跟进);Step 1 本身不引入新机制。
  8. 是否引入新配置:无。

状态:截至当前,Step 2 的两个提交(5c3856b2/007a19d6)还没出现在远端分支上,落地后我继续审(重点:8 个逃生口改走 fitEvidence/转移表后的等价性 + 新增三钉)。Step 4 按规划等拍板。判定:Step 0+1 可放行,继续。

ework-agent added 4 commits October 20, 2026 22:34
…ence (#3977)

Every forward-once escape hatch now consumes one adjudication
(fitEvidence in size-evidence.ts) instead of a raw localRefusals
read: localRefusalCovers becomes module-private, server.ts derives
localRefusalHere from evidence.verdict === "cannot-fit".

Zero behavior change by construction (the gate delegates to the exact
predicate it replaced); the indirection is the contract — a store
added in step 4+ lands in the adjudicator and every hatch consults it
the same moment (invariant A of the ROOT-FIX plan).

Verified: pins 4/4, #3846/#3918 families 9/9, tsc clean,
docs/unused-exports gates clean.
The ring/publish logic moves verbatim into its own function pairing a
REAL measured token count for the payload just sent against the
pending local estimate recorded at prepare time. settleUsageReport now
delegates — behavior identical (calibration families 35/35 green).

Step 4b will feed the same learner from armOverflowShrink: a 400 body
that STATES its counts ("N in the messages") is the same physical
event as a usage report — upstream measured a payload bili estimated
(#3900: the k-hat loop currently only learns from successes).
…bration ring (#3977/#3900)

armOverflowShrink now calls learnCalibrationSample when the 400 body
STATES the rejected payload's counts ("N in the messages, K in the
completion"): upstream MEASURED a payload bili estimated — the same
physical event as a usage report. The messages share is the estimator's
input domain (the completion share is a reservation, never a sample).

The ring's existing guards do all the gating: pending pair set by THIS
request at prepare, same route (origin-gated), plausibility band
x[0.2,5], >=2 agreeing samples within x2 before k-hat publishes,
per-(origin,model) keying, #3211 route policy at publication. The arm
(#3450) and the learner never collide — the arm writes lastInputTokens,
the learner reads the pending-estimate pair; and a successful usage
report retires the arm (#1110) so the loop converges instead of
oscillating.

P-LEARN pin flipped with the behavior, both directions pinned:
- two agreeing stated-count 400s (via the image-arb ride, recovery
  requests retiring the arm between detours) publish k-hat ~2.2 and
  flip an under-window 12K-token payload from forward-direct to
  fold-first (real summary call before the forward);
- a window-only 400 (no per-part counts) arms but never teaches: no
  samples, no publication, the same payload still forwards directly.

Families unchanged through the hook: stated-count + calibration suites
74/74 (their single-shot 400s never reach >=2 agreeing samples), pins
4/4, tsc clean, docs/unused-exports gates clean.
… pinned

Review fix 19bea67's premise (a stated-count 400 must move the treated
title) meets the flipped semantics: publication needs TWO agreeing
stated samples, and its fixture 400 was the window-only shape.

(i) window-only 400: arms but never teaches — title stays byte-identical
    to the never-saw-400 control (the original assertion, preserved);
(ii) two stated-count 400s: k-hat publishes, the calibrated estimate
     scales, the refusal title MOVES away from the control — and the
     payload still never reaches the upstream.

Pins 5/5, families 83/83, tsc clean, gates clean.
@ranxianglei

Copy link
Copy Markdown
Owner Author

Steps 2 + 4 landed (74499b5 → 45be60b)

Step Commit What
2 74499b5a fitEvidence — the single adjudicator over persisted size evidence; localRefusalCovers goes module-private, server.ts derives localRefusalHere from evidence.verdict === "cannot-fit". Zero behavior change; the indirection is the contract (a store added later lands in the adjudicator and every hatch consults it the same moment).
4a bc04fe97 learnCalibrationSample extracted verbatim from settleUsageReport — the ring/publish logic in one function. Calibration families 35/35 green through the extraction.
4b a26d604e learnFromOutcome(overflow-400) (#3900): armOverflowShrink feeds the learner when the 400 body states per-part counts ("N in the messages, K in the completion") — upstream MEASURED a payload bili estimated, the same physical event as a usage report. The messages share is the estimator's input domain; the completion share is a reservation, never a sample.
4b test 45be60b4 P-LEARN flipped with the behavior (both directions), and review fix 19bea679's P-LEARN-b upgraded to the two-directional pin: window-only 400 → title byte-identical to the never-saw-400 control; two stated-count 400s → k̂ publishes and the title moves away.

Why the arm and the learner can't collide: the arm writes lastInputTokens (#3450), the learner reads the pending-estimate pair; a successful usage report retires the arm (#1110) so the loop converges instead of oscillating — the flip test uses exactly that recovery pattern between detours (the second identical detour would otherwise be locally 413'd by the arm it just set, which is the emergency shrink working as designed).

Step 3 (single-render enum exits) is deferred by design: its substance — verdict classification as pure functions + one evidence gate — is delivered by Steps 1–2; a mechanical all-exits-return-enum refactor adds churn without new behavior. Tracked in #3977 for a follow-up if the ledger migration (ROOT-FIX-PLAN §4) proceeds.

Verification: pins 5/5 (incl. both flipped directions), stated-count + calibration families 74/74, #3846/#3918 families 9/9, tsc clean, docs-sync + unused-exports gates clean. The observed flip: two agreeing stated-count 400s (k̂ ≈ 2.2) turn a 12K-raw-token under-window payload from forward-direct into fold-first with a real summary call before the forward.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

全 PR 审核完成(pins + Step 1/2/4a/4b @45be60b4c),通过。 独立复核,不是照抄验证清单:

Step 2(fitEvidence) — 零行为变化成立是构造性的:grep 审计确认 localRefusals 在 src 侧唯一读者就是 size-evidence.ts;fitEvidence 的 cannot-fit 分支逐字委托给被替换的 localRefusalCovers 谓词,server.ts:3215-3216 单点派生 localRefusalHere,五个逃生口插点(3278/3324/3622/3655/3686)全部消费同一 verdict。不变式 A(新 store 落进 adjudicator,所有口同时继承)已成立。

Step 4a — verbatim 抽取;调用点 cache-ledger.ts:1540 位于 s.total > 0 门内,与 docstring「调用方自行 gate」一致。环的全部守卫(plausibility ×[0.2,5]、≥2 samples within ×2、#3211 per-route policy、#2117 B model-keying、clamp)逐字保留。

Step 4b — 臂写 lastInputTokens(#3450)、learner 读 pending-estimate pair,两条路不相交;usage report 退役臂(#1110)→ 收敛论证成立。边界审过:只带 per-part counts 的 400 才教(window-only 与无 window 的都不教,保守方向);completion share 永不取样。观测到的翻转(12K raw under-window → fold-first)有真 summary call 断言钉住,不是恒真。我的 P-LEARN-b 对照 pin 被正确吸收升级成三会话双向钉——谢谢。

本地定向验证 @45be60b4c:pins 5 + #3846/#3918 族 9 + 校准/stated-count 族 = 83/83 绿;tsc --noEmit 0 错。CI @45be60b4c:8 条 e2e lane 全绿。主矩阵(ci.yml)因 base 仍是 batch-B 分支未触发(pull_request 限定 base=master)——retarget 后以矩阵为准。

本轮动作

  1. PR 正文补了「Behavior change (step 4b)」披露节(old→new + 用户可见后果 + 边界)+ 状态注记——行为变更按规则必须显式披露,见 PR body。
  2. 立项 CI noise: every push creates a phantom failed run of the manual-only Gate Plugins workflow #4000(bug/scope/ci/p3):每次 push 产生一条 Gate Plugins(manual-only workflow)幻影红 run——非阻塞噪音,证据 run 39438100549(event=push、0 jobs、created==updated 同秒)。
  3. 一个待确认:原 roadmap 里 Step 4 含 FAIL_FAST(class="send-guard") 预留(Mid-session wire/dialect switch sends one request far beyond the declared window (upstream ContextWindowExceededError); no send-time size guard #3872),本 PR 代码里没有(grep 无 send-guard)——请确认它留在 Root fix: server-side size-evidence ledger + preflight verdict state machine (fold-budget/eligibility B-class family) #3977/Mid-session wire/dialect switch sends one request far beyond the declared window (upstream ContextWindowExceededError); no send-time size guard #3872 跟踪,而不是被静默丢掉。

八问(全 PR)

  1. 是什么问题:Root fix: server-side size-evidence ledger + preflight verdict state machine (fold-budget/eligibility B-class family) #3977 根修的第一个闭环——尺寸证据收口到单一 adjudicator(fitEvidence)、最终判决分类纯函数化、overflow-400 stated count 进校准环(修 [BUG] acp-proxy upstream HTTP 400: Request with 1,198,269 tokens exceeds the model's 1,048,576 token limit, consistently | [BUG] acp-proxy upstream HTTP 400:请求 1,198,269 tokens 超过模型上限 1,048,576,一直复现——是插件压缩未生效,还是 DSH 的问题? #3900 无限 400 自愈不了)。
  2. 什么原因导致的:知识与策略融合在 ~700 行 if-chain,每个逃生口只认出生时存在的 store(N×(N-1) 遗忘咨询边);学习环选择偏差——只从成功 usage 学,400 携带的真实 token 数被丢弃。
  3. 影响范围与严重程度:仅 Step 4b 改变用户可见行为——k̂ 发布后,原本 forward-direct 的部分载荷变 fold-first(多一次 summary 上游往返+计费)。触发条件窄:同 (origin,model) route 见到两个一致的 stated-count 400 且落在 plausibility band 内。其余步骤零用户可见影响。
  4. 怎么修复的:store 收口 + gate 委托被替换谓词(零变化 by construction);learner 抽成单一函数供「usage report」与「stated-count 400」两个物理事件共用;全部 gating 复用环既有守卫,不加新旋钮。
  5. 是否有回归问题:逐项审过的既有行为——五判决表达式/localRefusals 读写/dead-end 武装/fail-fast 消息渲染:保持(字节一致);校准族:保持(74/74 绿,[Bug] 虚报线路把 k̂ 学成 1.86 后,决策数反超上游自身报数 47%、长期压在压力带:到 10W 线就折一次、每次只折 1W 多 #3211/[Bug] 上下文展示估算 206K,usage 返回后为 98K:希望校准估算并区分安全上界 #2117/clamp 全在);高危模式逐项过:无 fail-fast→吞错、无阈值漂移(band/ratio 原样复用)、输出格式唯一变化是 k̂ 重标定后的 413 标题数字移动——即有意变更,已披露。
  6. 是否破坏缓存:不涉及——prefix cache/cache ledger wire 路径未触碰;校准只改 bili 本地 meter。
  7. 是否改了设计方向:是,Root fix: server-side size-evidence ledger + preflight verdict state machine (fold-budget/eligibility B-class family) #3977 规划的方向本身(判定收口单一模块);Step 3 enum 重构按 owner 决定延期(实质已由 Step 1–2 交付),Root fix: server-side size-evidence ledger + preflight verdict state machine (fold-budget/eligibility B-class family) #3977 跟踪。
  8. 是否引入新配置:无新 env/config 字段。

判定:全 PR 可放行,ready for retarget-to-master → 主矩阵 CI 绿 → 人工合并。前置两件:① retarget 后矩阵全绿;② send-guard 预留的去向确认(上面第 3 点)。

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

Labels

bug Something isn't working p1 scope/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant