Skip to content

fix(#739): forward fitting payloads when a stale usage baseline wedges preflight - #1004

Closed
asuan-dev wants to merge 2 commits into
ranxianglei:masterfrom
asuan-dev:fix/739-preflight-stale-baseline
Closed

asuan-dev wants to merge 2 commits into
ranxianglei:masterfrom
asuan-dev:fix/739-preflight-stale-baseline

Conversation

@asuan-dev

Copy link
Copy Markdown

问题

preflight 触发以 session.stats.lastInputTokens 兜底,但早前 #300 的"as-is 转发"会把 baseline 钉在窗口之上。线上会话:257,613-token 兜底 vs 256,000 窗口,而真实 prepared payload 只有 ~127k — 每轮都重跑 fold walk:3 次 60s 非流式 summary(~3.4min 停顿)→ upstream 500 → 结构化 502 → 5 分钟 dead-end cooldown,循环往复。

修复

src/server.ts:已知 baseline 的会话,payload 估算 fits window 而测量 baseline 停在窗口之上时,直接 as-is 转发(#301:as-is 是安全的,下一次 usage 上报会自愈 baseline)。窗口内 folding 逻辑不变 — codex headroom target 仍走 fitting 90-100% payload。

验证

tests/preflight-fail-fast.test.ts:fitting payload + stale floor above window → 零 summary 调用,直接转发。typecheck clean。

Stack: 基于修复 #739 的 restart 修复(#1003)。

阿酸 added 2 commits September 19, 2026 20:35
…a frozen watermark

Three root causes behind "session hangs / context keeps growing after a
restart or model switch":

1. A plain prompt_cache_key is not plugin ownership. Only a real omp
   registration or a persisted pluginAgent may unwrap the |sub: namespace;
   otherwise instructions drift (model switch, async tool registration)
   forked the main conversation into an empty namespace whose compression
   state was gone, so every existing block was invalidated.
2. Existing conversation mappings now restore their original session and
   compression blocks instead of minting a fresh bare-id session.
3. A failed preflight freezes the original history BOUNDARY rather than
   the range worklist it happened to select: every successful fold changes
   which ranges stay viable, so replaying a stale worklist compressed
   nothing and the retry looked bigger. The walk now recomputes remaining
   viable ranges against that boundary after each fold, including the
   soft-protected recent zone under overflow, while turns appended during
   the failure window stay out of the compression input.

# Conflicts:
#	CHANGELOG.md
#	src/plugin.ts
#	src/preflight.ts
#	src/server.ts
…eline wedges preflight

The preflight trigger floors on session.stats.lastInputTokens. After an
as-is forward under preflight (ranxianglei#300) the measured baseline can stay pinned
above the window while the prepared payload itself fits (~127k against a
256000 window on a live session). Every turn then re-ran the fold walk on
ranges the payload no longer needed: three 60s summarization attempts,
structured 502 on upstream 500, dead-end cooldown, repeat.

Forward as-is when a known-baseline session's payload estimate fits and
its measured baseline sits above the window (ranxianglei#301: as-is is safe; the next
usage report self-heals the baseline). Inside-window folding is untouched —
the codex headroom target still walks fitting 90-100% payloads.

# Conflicts:
#	CHANGELOG.md
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到 #1004。这是 [PR] 类 issue,我先定位对应 PR、拉取分支核对代码与 CI 状态,再跑本地验证(typecheck + test + build),稍后给出结论。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 ## Review: PR #1004 (head 87f64f7, branch fix/739-preflight-stale-baseline)

Scope check. 本 PR 相对 master 含两个 commit:#1003 的 restart 修复(eeaf10c,7 files)叠加本 PR 增量(87f64f7,仅 3 files:src/server.ts +9、tests/preflight-fail-fast.test.ts ±6、CHANGELOG.md +3)。#1003 在其自己的线程(#1003)审;这里重点审增量。

代码审查(src/server.ts:3029) — 逻辑正确,边界都核过了:

测试审查(tests/preflight-fail-fast.test.ts:150) — 回归测试正确复现楔死态:r1 用 claude-big(400k 窗口)让 mock upstream 上报 300k input tokens 钉死 floor,r2 同会话切到 claude-small(20k 窗口)+ ~13k 的 fitting payload。断言从旧的 "至少尝试过一次 summary 调用(然后靠 #301 兜底转发)" 收紧为 非流式调用 == 0,精确钉住本修复。端口走 listen(0),确定性 OK。其余 5 个用例未动。

本地验证(PR head 87f64f7 上实跑):

需要 owner 注意的事项(不阻塞代码本身):

  1. 合并顺序:stacked on fix(#739): restore compression across restarts and within a frozen watermark #1003,必须先合 fix(#739): restore compression across restarts and within a frozen watermark #1003。当前对 master mergeable_state=dirty,我做了 dry-run merge:唯一冲突在 AGENTS.md(master 侧 fix: single-writer plugin guard — never overwrite host-managed copies (#991) #995 与本 PR 各自加了一行,union 即可解),无代码冲突。fix(#739): restore compression across restarts and within a frozen watermark #1003 落地后把本分支 rebase 到新 master、解掉那一处文档冲突即可。
  2. CI 未跑:该 PR 来自 fork(asuan-dev/billion-context),截至审查时刻仓库 Actions 对该 head 没有任何 workflow run(check-runs total=0)。上面的绿是我在本机对同一 SHA 实跑的结果;建议 rebase 进主仓后确认 CI(ubuntu/windows × node 22/24 矩阵)转绿再合。
  3. E2E 缺口:本环境到不了 127.0.0.1:8199 的 sglang upstream(codex 二进制在,upstream 不通),AGENTS.md §3 要求的真实 codex 4-phase E2E 我没跑成。改动落在 preflight 热路径,建议在能连 upstream 的机器上补跑一次 ACP_TEST_E2E=1 … tests/e2e/e2e-codex.test.ts(或等 e2e-fake-codex CI job)。
  4. nit(非阻塞):CHANGELOG.md 的 ### Fixes 下多了两行连续空行,顺手删一下更干净。

结论:增量修复最小、打在根因上(stale floor 不该驱动 fold 决策,fitting payload 按 #301 先例直接转发并靠 usage 自愈),guard 边界(codex headroom、image hatch、anonymous、estimate-source baseline)全部核过无副作用,回归测试钉住了原症状。属于 preflight/wire 相邻行为变更 + fallback 策略产品决策,按 §7.4 需人工合并。#1003 先合 → rebase 解 AGENTS.md 单点冲突 → CI 绿后可合。


一句话中文摘要:核实了 PR #1004 —— 当 stale usage baseline 卡在窗口之上而真实 payload 其实 fit 时,preflight 跳过无效的 fold walk 直接 as-is 转发(下次 usage 上报自愈 baseline);guard 边界(codex headroom/image hatch/anonymous)无副作用,本机 typecheck+1952 项测试+build 全绿,待 #1003 先合、rebase 解一处 AGENTS.md 文档冲突、CI 转绿后即可合并。

@ranxianglei

Copy link
Copy Markdown
Owner

pr没看到,只盯着issue列表了 你提交了几个pr,ework看有对应issue吗 没有的话帮忙建一下 本作者所有的pr都扫描一遍

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到。正在扫描 asuan-dev 名下本仓库所有 PR(含已关闭),逐个核对 ework issue 列表里有没有对应的 [PR] issue,缺的我会补建并汇报清单。稍等。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 ## 扫描结果:asuan-dev 名下全部 PR ↔ ework issue 核对

用 GitHub search API 扫了该作者在 ranxianglei/billion-context 的所有 PR(含已关闭):共 4 个,全部 open(今天 12:41–12:56Z 创建)。逐个核对 ework issue 列表:

PR 对应 ework issue 状态 daemon 处理情况
#1003 restore compression across restarts/frozen watermark ✅ #1003 [PR] 存在 open 已审完:rebase 到当前 master 验证全绿,并推了可直接合并的镜像分支 2026-09-19_pr1003-rebased(cd08ba2)
#1004 forward fitting payloads(stale baseline wedge) ✅ #1004 [PR] 存在(本 issue) open 已审完(见本线程上一条):待 #1003 先合 + rebase 解 AGENTS.md 单点冲突
#1006 make compress failures retryable ✅ #1006 [PR] 存在 open 已审完:代码本身绿,但分支混入两个未合并的 #739 commit、fix(#743) 引用了错误的 issue、base 过期 —— 需拆分/rebase/更正引用(格式回归我已在分支直接修掉 8ab59e6)
#1008 name the live compressible span in receipts ✅ #1008 [PR] 存在 open 已审完:本地全绿;需 rebase 解 AGENTS.md 冲突(仅文档,按并集解)

结论:4 个 PR 全部有对应的 [PR] issue,没有缺的,无需补建。 你之前没看到是因为它们都以 issue 形式躺在列表里(标题带 [PR] 前缀),issue 号 = PR 号。

顺带提醒(影响合并顺序):这 4 个是一个 stack,必须按 #1003 → #1004 → #1006 → #1008 的顺序合,每合一个把下一个 rebase 上去;#1003 可以直接合我推的 rebased 镜像分支。另注意 #1006 的 fix(#743) 引用错了(#743 是无关的已关闭 PR),它修的行为目前没有对应的 bug-report issue —— 需要的话你从线上观察开一个,我再把引用改对。


一句话中文摘要:扫描了 asuan-dev 名下全部 4 个 PR(#1003/#1004/#1006/#1008,均 open),每个在 ework 都有对应的 [PR] issue、且都已被审完,无缺失、无需补建;它们是同一 stack,请按 1003→1004→1006→1008 顺序 rebase+合并。

@ranxianglei

Copy link
Copy Markdown
Owner

Closing as stacked — contains #1003, contained in #1008 (e4a4700), which carries this commit (87f64f7) verbatim and is the tip that will be updated and merged. (Queue triage per #1020.)

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.

2 participants