Skip to content

[PR] fix: retain local preflight refusals across estimate demotion and retries - #3847

Open
0XCocoa wants to merge 2 commits into
ranxianglei:masterfrom
0XCocoa:codex/remember-local-preflight-refusal
Open

0XCocoa wants to merge 2 commits into
ranxianglei:masterfrom
0XCocoa:codex/remember-local-preflight-refusal

Conversation

@0XCocoa

@0XCocoa 0XCocoa commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #3846

After local preflight 413, rebuilding can replace the trusted token baseline with an estimate. A later request then re-enters estimate-only arbitration and forwards the oversized payload. Remember local refusals independently of billing evidence, scoped to upstream origin/model and the refused window.

Gate all four arbitration escapes after a matching refusal: estimate-only probe, image arbitration, rebuilt-view divergence, and fresh-session probe. A tighter window retains the refusal; a different origin/model or larger window can arbitrate independently. Payloads that fit continue normally. Metadata uses existing session persistence; no schema version, configuration, kernel, or release changes.

Adds a complete HTTP regression: seed 200 -> local 413 -> estimate demotion + metadata JSON round-trip + reconnect -> three 413 retries with no extra upstream streams -> trimmed request 200. Original code returns 200 on the first oversized retry.

Related: #2830; complementary to open PR #2928 rather than replacing its fold-first change.

Validation on master 85c27f0e:

  • 20/20 targeted tests passed: preflight-fail-fast, issue2313-probe-forward, issue2490-ledger-floor-doomed-probe, issue2847-doomed-nonretryable-status, issue496-forward-once-learn.
  • TypeScript typecheck and production build passed.
  • Existing legal first-time estimate/image probes remain covered.

Preflight is shared by plugin and proxy modes; this only changes eligibility for forwarding above the current window after a prior local refusal. It does not fabricate upstream usage. Full-suite verdict is left to GitHub CI.

@ranxianglei ranxianglei changed the title fix: retain local preflight refusals across estimate demotion and retries [PR] fix: retain local preflight refusals across estimate demotion and retries Oct 19, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

ework接单

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

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。 关联项核对:

标签: bug + codex + scope/kernel + p2(缺陷 PR;生产证据来自 Codex Desktop/Responses;动的是 preflight 压缩引擎核心;p2=能用但超窗重试会被反复转发烧钱,有绕行=裁剪 payload)。

审核进行中,正在做:①新回归测试在 base 85c27f0eb 上的 A/B(验证测试有牙);②PR 列出的 5 个定向套件;③typecheck+build;④rebase 到当前 master(1434ca7b0)后的复验(master 窗口内 #3801 只动了 server.ts 的 port-zone 区域,与 preflight hunk 零重叠);⑤与 #2928 head 的组合性检查。结论稍后按八问体例补上。

…al 413 gate

The !locallyRejected gate landed with only positive-direction coverage
(suppression + fitting passthrough). Add the two scoping rows per the
gate-test discipline (ranxianglei#3617): a stored refusal must NOT suppress the
estimate-only probe when the model differs or when the request arbitrates
at a larger window than the refused one. Both rows verified to fail
against an over-suppressed predicate.
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

审查结论:可合并(未发现缺陷;顺手直接修了一处测试覆盖缺口,已推送到 PR 分支)。全量回归以远程 CI 为准。

结构化八问

  1. 是什么问题:本地判定的超窗 413 之后,一旦会话的 token 基线被降级为 estimate(rebuild/reconnect),下一次同样 oversized 的重试会重新进入「forward once for evidence」仲裁,把已经证明放不下的 payload 转发出去——生产事故 [Bug][preflight] Local 413 is forgotten when the baseline becomes an estimate, reopening oversized probes #3846:upstream inputs 606K/620K/633K tokens,各自仅命中 32K 缓存。
  2. 什么原因导致的:本地拒绝只体现在响应里,没有持久化为会话状态;四个投机性转发出口的资格判定只看当前基线来源(estimate → 放行 probe)。基线一降级,「已被本地拒过」的信息就丢了。根因是状态载体缺失,不是判定逻辑错误。
  3. 影响范围与严重程度:满足「先发生本地 413 + 基线随后降级为 estimate + 客户端以同样 oversized payload 重试」的会话——客户端重试循环会反复转发数百 K 的 payload(浪费配额、诱发上游限流)。能用但有明显问题 → p2。
  4. 怎么修复的:把本地拒绝持久化进 session metadata(session.metadata.localPreflightRejections,按 origin+model upsert、limit 取 max),并在全部四个投机性转发出口加 !locallyRejected 门(estimate-only probe billion-context 卡死问题 —— 上报材料 usage获取不到导致上下文估计失误 #2313 / image arbitration PR #489 后续: 默认图片计费 b64/4 在像素 tile 计费上游(官方 Anthropic/OpenAI)会硬 502 误杀多模态会话 #496/疑似#767后续:图片计价高估会使preflight自动压缩永久失效,同时请求仍被转发 #1800 / rebuilt-view divergence 任何一轮没有拿到 usage 报告的请求,都会把上下文分母放大 12–20×(nudge 读到 >1000% usage、假 EMERGENCY、基线冻结数分钟) #1839 / fresh-session probe [Bug] 新会话(无 usage 基线)preflight 把字符数当 token——折叠其实成功(2263796→1111212)却 fail-fast 502,上游实际只计费 540828 #3146)。作用域规则:同 origin+model 且当前窗口 ≤ 被拒窗口 → 抑制;不同 model、更松的窗口、以及能放下的 payload 均不受影响。
  5. 是否有回归问题:逐项审过既有行为,无无意回归——
    • 合法的首次 probe 不受影响(首次不存在记录);
    • 能放下的 payload 走 fits 路径,不经过该门;
    • growth-armed 未设门(growth 超窗是 operator 意图);
    • usage-baseline 会话不受影响(probe 本就要求 baselineFloor≤0);
    • 边缘组合(locallyRejected ∧ unknownBaseline 同时成立):落到 exhausted-deterministic → 仍是 413,不会变成 502 重试风暴;仅错误文案从 doomed-bytes 措辞变为通用 exhausted 措辞(轻微);
    • metadata 为增量自由字段,无 schema 版本变化;数组规模受 distinct (origin,model) 对数约束。
  6. 是否破坏缓存:不涉及——不动 prefix cache / summary cache / 增量游标,只读写 session.metadata 自由字段。
  7. 是否改了设计方向:不涉及——不改压缩引擎与 wire 形态,只给转发决策增加资格条件;preflight 路径 plugin/proxy 两模式共用,行为对称。
  8. 是否引入了新的配置:无。只有增量 session metadata key localPreflightRejections(内部状态,随会话生命周期清除)。

行为变更披露:旧行为 → 本地 413 后若基线降级为 estimate,下一次超窗请求可经 estimate-only probe 被转发一次;新行为 → 存在匹配拒绝记录(同 origin+model、窗口不大于被拒时)期间,四个投机性转发全部抑制,只走折叠或 fail-fast 413。这正是修复目标本身。

独立验证证据

关于 #2928 的发现(非本 PR 缺陷)

#2928 的分支基于较旧的 master(早于 #2847/#3146 合入)。compose 验证显示两者语义兼容(doomed-probe 分支可并集合并),但 #2928 合入后其作者需要更新:issue2490-d / issue2915-cross-origin 中三处 502→413 状态期望,以及 issue2847 的两处消息断言(其 fixture 恰好有 11 个可折叠 range,在 #2928 下走折叠路径;413 / retryable:false / 绝不转发的契约完整保留,仅措辞从 byte-math 变为 post-fold futility 判决)。建议本 PR 先行合并,或 #2928 rebase 到包含本 PR 的 master 后再合。

结论:可合并。 CI 绿后建议直接合并本 PR;#2928 可随后 rebase 跟进。

This branch has not been deployed

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

Labels

bug Something isn't working codex p2 scope/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][preflight] Local 413 is forgotten when the baseline becomes an estimate, reopening oversized probes

2 participants