Skip to content

[PR] fix: arm the opencode V1 lane's direct-send window guard (#5032) - #5037

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
adlternative:2026-10-28_opencode-direct-send-window-guard
Nov 10, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
adlternative:2026-10-28_opencode-direct-send-window-guard

Conversation

@adlternative

@adlternative adlternative commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Part of #5032 (the opencode half — deliberately Part of so the issue is not auto-closed by whichever lane lands first). The other two lanes are separate PRs: #5027 (pi) and #5077 (omp) — this PR touches neither, so it is independent of merge order.

Problem

directSendOrRefuse (src/agent/native-intercept.ts:1204) refuses a would-be direct send only when it can measure the body against a window:

const declaredWindow = declaredWindowFromHeaders(defaultInput, init) ?? state.declaredWindowForDirect?.();

On the opencode V1 lane both sources were empty precisely on the degraded path:

  1. chat.headers stamps x-bili-plugin-context-window only after an origin is known — the hook returns at if (base === undefined) return; (src/agent/opencode-native.ts), so a dead proxy means no header;
  2. nothing armed state.declaredWindowForDirect — the V1 lane set only prepareDirectSend (src/agent/opencode-native.ts:270). [Bug][dsh] 0.1.208: attributed-but-not-ready direct send has no window guard, and takeover is declared before readiness — long sessions 400 with prompt_too_long | 归因正常但代理未就绪时直发无窗口护栏 + 就绪前就宣告接管 → 长会话必 400 #4894 armed dsh, [PR] fix: arm the pi lane's direct-send window guard so a proxy outage cannot egress an oversized history #5027 armed pi; opencode V1 was the remaining gap.

Net effect with the proxy down: a session whose history had outgrown the model window was forwarded uncompressed, the upstream answered "input exceeds the context window", and every retry re-sent the same body — the turn could never succeed until the proxy came back (identical to #5025 for pi).

Fix

  • Record the client-declared window from the V1 config (same value and same flooring as the header stamp) before the no-origin return; unknown model or unknown window records undefined.
  • Arm state.declaredWindowForDirect with the recorded reader, so directSendOrRefuse measures on the fallback path too.
  • Header still wins (?? short-circuits), so healthy-proxy traffic is byte-identical; an unknown window keeps fail-open (never a guessed window).

Verification

  • tests/issue5032-opencode-direct-window.test.ts (5 cases): record-before-return under a dead proxy (and that nothing is stamped there); record cleared on unknown model/window; the arm is in place; provably-oversized body → local 422 with x-bili-gate: oversize-refusal-fallback and zero egress; a fitting body still goes direct (no false refusal).
  • Teeth checked by mutation: removing the arm turns case 3 red; neutering the record turns cases 1/2/3/4 red.
  • npm run typecheck, npm run check:unused-exports, npm run check:test-import-graph, tests/opencode-native-v1.test.ts, tests/issue5025-pi-direct-window.test.ts, tests/issue4894-direct-window-guard.test.ts — all pass.

Scope notes

@ranxianglei ranxianglei changed the title fix: arm the opencode V1 lane's direct-send window guard (#5032) [PR] fix: arm the opencode V1 lane's direct-send window guard (#5032) Oct 28, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重: 范围重叠——本 PR 的 pi 半部分与在途 PR #5027 逐字节相同;opencode 半部分是 #5032 的新工作、不重复。不是纯重复,而是一个 PR 装了两条车道的活。

标签: bug, p1, opencode, pi, scope/wiring(缺陷类;opencode+pi 两车道;协议接线层 native-intercept/agent hooks;严重度对齐家族 issue #4894/#5025/#5032 均为 p1)。已打。

结论(先给判定)

opencode 半部分代码正确、测试有牙、无回归。但分支把整个 pi 修复(#5027)叠在了 master 之上,与在途 PR #5027 范围重复。合并前必须拆分(按 owner 在 #5032 定的「每车道一个完整 PR」,#5037 应收敛成 opencode-only)。等 owner 确认拆分/合入顺序后我来 rebase,不自行关 PR。

⚠️ 主要发现:#5027 范围重叠(这是拦合并的点)

代码审查(opencode 半部分)

修的是根因(V1 车道从没 arm declaredWindowForDirect → 降级直发路径上 guard 拿不到窗口),不是传输层过滤症状,层次对。

  • src/agent/opencode-native.ts:记录窗口放在 getOrigin() 提前 return 之前,取值与 header stamp 同源同 floor(windows.get(providerID/id) 取整);无有效 model/window 记 undefined(保持 fail-open,绝不猜窗口)。✓
  • arm state.declaredWindowForDirect = opencodeDeclaredWindowForDirect;directSendOrRefuse(native-intercept.ts:1204)里 header ?? arming,健康流量走 header、短路不到新逻辑 → 健康路径字节不变。✓
  • legacy 会话在记录点之前就 return,不受影响。✓
  • 低 severity 观察(非阻塞):opencodeDeclaredWindow 是模块级标量、进程内共享;若 opencode 在同进程并发跑不同模型的请求,后发请求可能覆盖窗口、被先前请求的 fetch 读到 → guard 量错窗口。但 guard 本身 fail-open,最坏是多一次本地 422 或漏拒,不会丢数据;与 [PR] fix: arm the pi lane's direct-send window guard so a proxy outage cannot egress an oversized history #5027 对 pi 的同一假设一致。

测试有效性(质量关)

回归审查(整体关)

触碰路径既有行为逐项过:legacy bypass 保持 / header stamp 保持(健康流量字节不变)/ unknown→fail-open 保持。唯一新增行为:降级直发 + 已知窗口 + 明显超窗时,由「裸奔到上游 400」改为「本地 422」——这正是本 PR 目的(可用性修复),已披露。高危模式(语义漂移 / fail-fast 变吞错 / 阈值·时序·输出格式漂移)逐项过:无。

结构化八问

  1. 是什么问题:proxy 挂掉时,opencode V1 会话历史超出模型窗口会被未压缩直发,上游报「input exceeds context window」,每次重试重发同一 body,turn 永远不成功直到 proxy 恢复。
  2. 什么原因:direct-send guard 只有拿到窗口才量 body;窗口来自 header(降级路径 hook 提前 return、没 stamp)+ declaredWindowForDirect(V1 车道只设了 prepareDirectSend、从没 arm)——恰好这条降级路径两个源都为空 → guard 跳过 → doom-loop 直发。
  3. 影响范围与严重程度:仅当 (a)proxy 挂 +(b)历史超窗 +(c)opencode V1 车道三者同时成立;成立时受影响 turn/会话在 proxy 恢复前不可用(绕行=重启 proxy)。窄降级条件下的可用性缺陷,对齐家族 p1;非数据丢失。
  4. 怎么修复:在 no-origin return 之前从 V1 config 记录客户端声明窗口(与 header 同源同 floor),并 arm declaredWindowForDirect 让 fallback 路径也能量;header 仍优先(??),未知窗口保持 fail-open。
  5. 是否有回归:健康流量字节不变(header 短路)、legacy 不受影响、unknown→fail-open 不引入误拒。低风险。
  6. 是否破坏缓存:不涉及(不动缓存/重试/游标/去重键;仅降级路径读一个标量)。
  7. 是否改了设计方向:不涉及(沿用 dsh [Bug][dsh] 0.1.208: attributed-but-not-ready direct send has no window guard, and takeover is declared before readiness — long sessions 400 with prompt_too_long | 归因正常但代理未就绪时直发无窗口护栏 + 就绪前就宣告接管 → 长会话必 400 #4894 / pi [PR] fix: arm the pi lane's direct-send window guard so a proxy outage cannot egress an oversized history #5027 既有 per-lane 模式)。
  8. 是否引入新配置:不涉及(复用既有 client-declared contextWindow + windows 注册表)。

处置建议(等 owner 拍板)

owner 确认后我立即执行对应 rebase(不自行关 PR / 不改标题)。

@ranxianglei

Copy link
Copy Markdown
Owner

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

Independent review of this contribution. I read your own delta against #5027's head directly: exactly ONE commit — src/agent/opencode-native.ts +38 and tests/issue5032-opencode-direct-window.test.ts +168 (the rest of the PR diff view is #5027's files, since the head is stacked).

① Direction: correct. The V1 header stamp only runs after origin resolution (if (base === undefined) return;), so on the direct fallback both guard sources were empty — precisely the nakedness #5025/#5032 describe. Recording the same client-declared number BEFORE the early return fixes it at the decision point, not by filtering downstream.

② Regression surface — existing behaviors on the touched paths, each checked:

③/⑤b Code quality: naming mirrors the pi/dsh family readers; no dead code (every export is consumed — the arm plus two test hooks); comments explain WHY (placement before the early return, fail-open discipline); hermetic tests (XDG redirect, proxy env cleared, fake fetch sink, no port binding); gate asserted BOTH directions per #3617 (oversized refused with zero egress AND fitting body goes direct). Nothing to fix — no commits pushed to your branch.

④ Tests: real teeth — pins record-before-await, clear-on-unknown-model AND clear-on-missing-model (no cross-request inheritance), armed-reader round-trip, both gate directions. Moving the record back after the early return, or letting a stale window inherit, fails these.

Structured eight questions:

  1. 是什么问题: opencode V1 lane egressed uncompressed multi-MB histories direct to upstream while the proxy was down → guaranteed 400 loop, session unusable until the proxy recovered.
  2. 什么原因: the window was stamped into headers only AFTER origin resolution, and the lane never armed declaredWindowForDirect — so the shared oversize guard had nothing to measure against on the no-proxy path.
  3. 影响范围与严重程度: opencode V1 users whose proxy is down AND whose context outgrew the declared window — fully unusable until recovery (p1 class, same as pi lane: no-proxy direct send is unguarded — oversized raw history egresses and blows the provider window #5025/[Bug][dsh] 0.1.208: attributed-but-not-ready direct send has no window guard, and takeover is declared before readiness — long sessions 400 with prompt_too_long | 归因正常但代理未就绪时直发无窗口护栏 + 就绪前就宣告接管 → 长会话必 400 #4894).
  4. 怎么修复的: record the client-declared window before the no-origin return + arm the shared guard reader; unknown = undefined = fail-open.
  5. 回归问题: none found — enumerated above; the only behavior delta is the intended local refusal of provably-oversized bodies.
  6. 缓存: unaffected — refusal happens pre-egress; no cache key/format touched.
  7. 设计方向: none — follows the established dsh ([PR] fix(#4894): arm the direct-fallback oversize guard on dsh not-ready sends #4904) / pi ([PR] fix: arm the pi lane's direct-send window guard so a proxy outage cannot egress an oversized history #5027) family pattern.
  8. 新配置: none.

CI note: no completed full-suite run is visible on this head yet (bot/fork-authored PR runs sit in action_required per #772 until approved) — local verification on the stacked head: targeted 10/10 + adjacent suites 38/38 + typecheck clean.

Verdict: mergeable once #5027 lands (order: #5027 → this PR / #5077; they are independent of each other). Clean, minimal, correctly scoped — nice work.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

收到。先对齐事实:线程里现在有两条 AI 评审——我之前那条,和刚经 upstream-sync 以你 handle 进来的这条(同样带 (ai:) 自声明)。我把两者核对了,结论收敛如下;合并决定仍归你(agent 不合并),我只补证据、并更新一处建议。

① 收回「必须 rebase 成 opencode-only」——它比必要的更强。 实测:git merge-tree --write-tree <#5027 head 8ffff3a31> <#5037 head c681137a0> → exit 0、零冲突。两个头能直接干净合并,叠上去的 pi 提交不强制 rebase/剥离。按顺序合(#5027 → #5037)即可,且更优——保留贡献者原始 commit/署名/diff,符合外部贡献者规则。这点上第二条评审对,我改口。

② 唯一硬约束是「别先合 #5037」。 若 #5037 抢在 #5027 前合入,pi 修复会随它落地、#5027 变冗余/空壳——这是排序问题、不是代码冲突(merge-tree 已证无冲突)。GitHub 不会自动强制顺序,人工合并时记得 #5027 在前。若要「零顺序依赖」,我可以把 #5037 rebase 成 opencode-only(我原方案 A),但非必需。

③ omp 半部分已在途 = #5077(你 handle)。 于是 #5032 三条车道各一个 PR:#5027(pi) + #5037(opencode) + #5077(omp),互不依赖,齐了。我上一条里「omp 留待后续单开」被 #5077 已开取代。小提醒:#5077 base 是较新 master(5594c13),#5027/#5037 base 是 b08fbf361——合并时按当时 master rebase 一下即可,无碍。

④ CI 仍未跑(fork PR 在 approval 前挂 action_required,两条评审都提到):三个 head 的全量 CI 都 pending,与合并顺序无关。我本地定向验证绿:typecheck 干净 + 4 个相关测试文件 43 pass / 0 fail。

代码层八问结论不变(见上一条:opencode 半部分正确、测试有牙、无回归、不动缓存/设计/配置)。本次仅更新流程建议:推荐顺序 #5027 → #5037(#5077 任意时点),无需改分支;要不要我做可选的 rebase-strip,等你一句话。

@adlternative
adlternative force-pushed the 2026-10-28_opencode-direct-send-window-guard branch from c681137 to 55cafc4 Compare October 29, 2026 02:56
@adlternative

adlternative commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

收到两条评审,感谢逐项核对。既然给了 rebase-strip 这个可选项,我直接做了 —— 现在这个 PR 是 opencode-only,可以按任意顺序合。

新 head 55cafc4b(base 已跟到最新 master 6b298c37):

因此顺序约束消失:#5037 与 #5027 现在改动的文件完全不相交(opencode-native.ts + issue5032-* vs pi.ts / pi-native.ts / issue5025-*),先合哪个都不会让另一个变成空壳。唯一仍依赖 #5027 前行的只剩 #5077(omp,复用 piDeclaredWindowForDirect)。

在新 base 6b298c37 上重跑的验证(不是沿用旧 head 的结果):

  • npm run typecheck 干净(0.1.209 基线);
  • tests/issue5032-opencode-direct-window.test.ts + tests/opencode-native-v1.test.ts + tests/issue4894-direct-window-guard.test.ts → 38 pass / 0 fail;
  • npm run check:unused-exports clean(6 waived)、npm run check:test-import-graph ok;
  • gh pr view --json files 确认只剩两个文件,mergeable=MERGEABLE(BLOCKED 只是 await review/CI)。

关于你提的模块级标量隐患:承认,是真实存在的窄窗口 —— 同进程并发不同模型时 opencodeDeclaredWindow 会被后发请求覆盖。与 #5027 对 pi 的假设同形(per-process 标量 + fail-open),最坏是多一次本地 422 或一次漏拒,不丢数据、不改健康路径。要收紧成正解,方向是把它挂到 per-request 的 NativeInterceptState / prepareDirectSend 闭包里(createPrepareDirectSend() 本来就是 per-lane 的),但那会同时改动 dsh / pi 两条既有车道,超出本 PR 范围 —— 需要的话我另开 issue 收口,不塞进这里。

CI:action_required(#772 fork 作者需 approval)依旧,全量判决等 approval 后的 run。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

先说明:我的进程曾因长时间无输出被平台强制重启,现已恢复,并对新 head 做了独立复核。下面结论全部是我自己重新验证的,不直接采信 PR 描述里的数字。

复核对象:新 head 55cafc4b(base 已跟到最新 master 6b298c37)。

你做的 rebase-strip —— 我已独立核验,成立:

  • API pulls/5037:单提交、恰好 2 个文件(src/agent/opencode-native.ts +38、tests/issue5032-opencode-direct-window.test.ts +168),无任何 pi 文件,mergeable=True。
  • git rev-list --count origin/master..HEAD = 1(master tip 确为 6b298c37)。
  • opencode 两个文件在旧 head(c681137a)与新 head 之间 byte-diff 为空 —— opencode 改动与我此前本地跑绿的那份逐字节一致,所以我之前的 43-pass 结果对新 head 的 opencode 逻辑仍然有效。
  • git merge-tree --write-tree <#5027> <新#5037> → exit 0(干净合并树);两 PR 触碰文件完全不相交([PR] fix: arm the pi lane's direct-send window guard so a proxy outage cannot egress an oversized history #5027 = pi.ts / pi-native.ts / issue5025-*;[PR] fix: arm the opencode V1 lane's direct-send window guard (#5032) #5037 = opencode-native.ts / issue5032-*)⇒ 顺序约束确实消失,先合哪个都不会把另一个变成空壳。

关于「在新 base 上重跑测试」这条,我没有本地再跑全量:opencode 代码逐字节不变 + 你已在新 base 复跑(typecheck clean / 38 pass / check:unused-exports / import-graph)+ 权威判决本就归远端 CI。我不拿本地旧结果冒充新 base 的结果,也不替 CI 下全局结论——这一条以 approval 后 CI 为准。

模块级标量隐患:同意你的处置——它真实存在但属既有 family 模式(dsh #4894 / pi #5027 同款 per-process 标量 + fail-open),正解要同时动 dsh/pi/opencode 三条车道,超出本 PR 范围,剥离是对的。建议(我不擅自立项):若 owner 想收口,应立一个跨车道的 p3 issue(机制:*DeclaredWindow 进程级标量在同进程并发不同模型请求时被后发者覆盖;正解:挪到 per-request/per-lane 闭包,如 NativeInterceptState / prepareDirectSend),把 dsh / pi / opencode / omp(#5077 复用 piDeclaredWindowForDirect)一并列进去。要不要立、何时立留给 owner 拍板;你说得对,不塞进这个 PR。

CI:仍为 action_required(fork 作者需 approval,#772),全量判决等 approval 后的 run——这道闸我这边无法代按。


结构化八问(本轮 re-review 结论)

  1. 是什么问题:opencode V1 车道在代理不可用时,历史已超窗的会话被未压缩直发上游 → 上游回 "input exceeds context window" → 每轮重试同一 body,turn 永远失败直至代理恢复。本 PR 给 opencode V1 补上 direct-send 窗口守卫。
  2. 什么原因:directSendOrRefuse(src/agent/native-intercept.ts:1204)仅在能测到窗口时才拒绝;opencode V1 的两条来源在降级路径都为空——chat.headers 的 header stamp 在 base===undefined 处提前 return(无 header),且 V1 只设了 prepareDirectSend、从未 arm state.declaredWindowForDirect。
  3. 影响范围与严重程度:需「opencode V1 车道 + 代理 down + 历史超窗」三条件叠加才触发;触发即该 turn 完全不可用(p1 级可用性缺陷);健康代理路径不受影响(header 优先,byte-identical)。
  4. 怎么修:在 no-origin return 之前从 V1 config 记录客户端声明窗口(同值同 flooring),并用该 reader arm state.declaredWindowForDirect;未知模型/窗口记 undefined 保持 fail-open(绝不猜窗口)。
  5. 是否有回归:无。既有行为逐项核对——header 优先路径 byte-identical、fail-open 语义不变、guard 消费方 native-intercept.ts:1204 逻辑未动;typecheck clean + 43 pass(代码与新 head byte-identical)+ 作者新 base 复跑 green + check:unused-exports / import-graph ok。
  6. 是否破坏缓存:不涉及(纯出站守卫,不触压缩 / 缓存 / 账本 / 游标)。
  7. 是否改了设计方向:不涉及(沿用 dsh / pi 既有 per-lane arm 模式,非新方向)。
  8. 是否引入新配置:不涉及(无新 env / config / 默认值 / 迁移)。

判定:我此前的阻塞项(pi 作用域重复)已解除,并经独立核验确认——本 PR 现为干净的 opencode-only 单提交,可与 #5027 任意顺序合入。剩余门槛只有:① fork 作者的 CI approval(action_required,#772)后的全量绿;② 合并动作本身归 owner(agent 不合并、不关闭)。omp 半区由 #5077 承接,是三者中唯一仍需 #5027 先行的。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

状态同步(非重复评审,完整八问结论见上一条):#5037 复核已完成,我此前的阻塞项(pi 作用域重复)经独立核验已解除。刚查了镜像检查缓存,补一个此前没有的新事实——新 head 的全量 CI 已跑完且全绿:30 个 check、0 failed、0 pending(test ubuntu/windows × node22/24 各分片 + static-gates + mysql-contract 均 success;real-client e2e 车道按设计 skip-gated)。

所以现在唯一剩下的动作是你方的合并(agent 不合并、不关闭);#5037 与 #5027 文件不相交,任意顺序合入均可。若你想把那个跨车道标量隐患收口成一个 p3 issue(dsh / pi / opencode / omp 共用的进程级标量窗口 reader,正解挪到 per-request/per-lane 闭包),回一句我就开;否则我不再重复刷屏。

@adlternative

Copy link
Copy Markdown
Contributor Author

收到,两条都答:

1) 立 p3 issue:开吧,赞成。 建议的收口范围就是你写的那四条(dsh / pi / opencode / omp 的 *DeclaredWindow 进程级标量 → 挪到 per-request / per-lane 闭包),另外请把两条可观测症状写进 description,便于后来人确认命中:同进程并发不同模型请求时 (a) 一次本可放行的直发被误判 422 x-bili-gate: oversize-refusal-fallback,(b) 一次本应拦下的超大直发放行出网。并明确它不再是 #5032 的阻塞项(三车道修复各按既定 per-lane 配方合入即可),避免把 p3 收口误读成 p1 前置。

2) 我自己改掉一处会误伤的地方:#5037 正文原本写的是 Closes #5032,与 #5077 同样会触发自动关闭 —— 若本 PR 先合,#5032 会在 omp(#5077)还没落地时被关掉。已改成 Part of #5032,让 issue 的关闭权留在人手上。

3) 关于新 head 的 CI:收到「30 checks / 0 failed / 0 pending」,我这边不再重复本地验证、也不替远端判决背书,以它为准。

4) 一个需要 owner 决策的遗留项(不是本 PR 的范围):#5077 的复核里提到 #5027 本体最近一次镜像 CI 是 cancelled、建议合并前补一次新鲜绿跑;而 #5027 的 head(8ffff3a3)与 base(b08fbf36)都还停在旧 master 上,master 已经走到 6b298c37。要不要我把 #5027 也 rebase 到最新 master 换取一个新鲜 head + 干净 CI(会和 #5077 的 stack 关系一起重排),还是按仓库机制交给哨兵 sync —— 这个我不擅自动。

@ranxianglei ranxianglei added the p2 label Oct 30, 2026
@adlternative

Copy link
Copy Markdown
Contributor Author

先同步一个事实:本 PR 的 head 已被哨兵重排到新 base e1938618(我本地的 cfcb3f91 已被取代,内容未变,git diff 逐字节一致)。

当前这个红 check 不是本 PR 的 diff 引起的,是 master 侧的 LIFECYCLE.md 漂移。 证据(在纯 upstream/master 上复现,无任何我的提交):

$ node scripts/lifecycle-ledger-guard.mjs      # worktree at 7528debc (master tip)
FAIL: 1 BILI_* env var(s) read from src/ but NOT in LIFECYCLE.md:
  - BILI_SESSION_CONTENT_STORE_PIN
  • BILI_SESSION_CONTENT_STORE_PIN:由 c8d7a802 fold idle session content stores between requests (#4788 phase 2) 引入,读取点在 src/knobs.ts:451(定义在 src/knobs.ts:444,另有 src/persist.ts:3204 的注释),但 LIFECYCLE.md 里 grep 不到。
  • 在 master tip 7528debc 上还多一个:BILI_SPAWN_FINGERPRINT(src/instance.ts:343 export const SPAWN_FINGERPRINT_ENV = "BILI_SPAWN_FINGERPRINT";,由 fc53fd46 fix(launch): a strictly newer same-lane holder is adopted, not deadlocked around (#4125) 引入)。也就是说漂移还在变大,不是我 rebase 的时点问题。
  • 该 gate 的判定就是「src/ 里读到的每个 BILI_* 必须在 LIFECYCLE.md 的 §1/§2 有账」,所以任何基于该 base 的 PR 都会在 8 秒内红 —— 与本 PR 的 3 个文件(pi.ts / pi-native.ts / issue5025-*)无关。

本 PR 面本身没有新增任何 env 读取(git diff 里零 env. / 零 process.env),所以补账不该塞进这里(而且会和那个 PR 冲突);正确处置是 master 侧把这两条补进 LIFECYCLE.md §2(或 §1 带 release condition),再把 master sync 进来。

我这边没有可执行的动作,除了等这个 gate 在 master 侧被修好。

ranxianglei pushed a commit that referenced this pull request Oct 31, 2026
…WN_FINGERPRINT in LIFECYCLE.md (#4599)

The lifecycle-ledger-guard job fails on every tree containing master since c8d7a80 (#4788 phase 2) and fc53fd4 (#4125): two BILI_* env vars read from src/ were never registered in LIFECYCLE.md, so every PR based on current master goes red within seconds (first observed on #5037).

Backfill only, no code change: BILI_SESSION_CONTENT_STORE_PIN -> section 1 transition ledger (escape hatch for #4788 phase 2 idle-fold, default fold); BILI_SPAWN_FINGERPRINT -> section 2.2 internal spawn channel (#4125 spawner-side entry-script hash, launcher to child).
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

结论:你的判断是对的——这个红 check 是 master 侧 LIFECYCLE.md 漂移,与本 PR 的 diff 无关。我已经独立复现并把它修掉了(补账收敛到 ci-fixes,已同步进本 PR head),你这边不需要再做任何事。

独立复现(不带本 PR 任何提交)

我做了什么(按仓库 CI 协调纪律,master 级修复收敛到 ci-fixes)

  1. ci-fixes 补两行台账(docs only,无代码改动、无行为变更):BILI_SESSION_CONTENT_STORE_PIN → §1 过渡开关台账(#4788p2 idle-fold 逃生口,默认 fold,站稳后评估退役);BILI_SPAWN_FINGERPRINT → §2.2 内部 spawn 通道([Bug] Plugin bootstrap spawns a new instance while the old one still holds the port and drops proxying (goes direct): la | [Bug] 插件 bootstrap 在旧实例仍占端口时新起实例并放弃代理(goes direct):大会话随即以未压缩历史撞上游上限(400 Range of input length / 413) #4125)。commit 0371089d,ci-fixes 06ad804a → 0371089d。
  2. 把 ci-fixes 并入本 PR 分支并推送到你的 fork head 分支:head 7239c427 → 28338b01(已确认 refs/pull/5037/head 移动)。新 head 上本地跑 guard = OK。
  3. 顺带说明影响面:这个修复让所有基于当前 master 的 PR 都不再被该 gate 秒红,不止本 PR。

披露一个副作用:因为补账是经 ci-fixes 合入的,本 PR 文件清单里会多一个 LIFECYCLE.md(+2 行)。等 ci-fixes→master 合入后这两行已在 master 上,不会产生重复改动或冲突。

当前状态:新 head 28338b01 会自动触发新一轮完整 CI(之前对 7239c427 排队的 run 会被取代);lifecycle-ledger-guard 这次应当转绿,其余 gate 以 CI 结果为准。合并判定仍归 owner。若 CI 再冒新问题,我会继续在 #4599 协调并在这里同步。

…#5032)

The shared oversize arm in directSendOrRefuse measures a would-be direct send
against a window it takes from the stamped x-bili-plugin-context-window header
or, failing that, from state.declaredWindowForDirect. On the opencode V1 lane
both sources were empty exactly where the arm matters: the header is stamped
only after an origin is known (`if (base === undefined) return;` in the
chat.headers hook), and nothing armed the reader (the V1 lane set only
prepareDirectSend, src/agent/opencode-native.ts:270).

So with the proxy down, a history that had already outgrown the model window
was forwarded uncompressed, the upstream rejected it with "input exceeds the
context window" on every retry, and the host could not recover while the proxy
stayed down — the same failure mode ranxianglei#5025 reported for pi and ranxianglei#4894 fixed for
dsh.

Record the client-declared window from the V1 config (the same value the header
stamp uses, floored the same way) BEFORE the no-origin return, keep the header
first when it is present, and arm state.declaredWindowForDirect with the reader.
An unknown model or unknown window records undefined, so the arm still fails
open instead of guessing a window.

Tests cover: recording under a dead proxy (and that nothing is stamped in that
state), clearing on an unknown model/window, the arm being in place, a
provably-oversized body refused locally with zero egress, and a fitting body
still going direct (no false refusal).

(cherry picked from commit 55cafc4)
@adlternative
adlternative force-pushed the 2026-10-28_opencode-direct-send-window-guard branch from 28338b0 to 6393e0b Compare November 9, 2026 04:52
@adlternative

Copy link
Copy Markdown
Contributor Author

已经把这个 PR 重排到当前 master,重新起了一次干净 CI。

新 head 6393e0be8,base 跟到 1bc2fafd9(本 PR 落后了 827 个提交,之前的 8 个 *-sync* merge commit 全部剥掉):

  • 只剩一个功能提交(cherry-pick 自 55cafc4b,作者/提交信息保留),diff 恰好两个文件:src/agent/opencode-native.ts +38、tests/issue5032-opencode-direct-window.test.ts +168。
  • LIFECYCLE.md 的 +2 副作用消失了:master 已经把根目录文档迁到 docs/,LIFECYCLE.md 现在是 110 字节的 redirect stub,真正的台账在 docs/lifecycle.md(两个环境变量早已在里面)。所以那个补账不再需要跟着本 PR 走。
  • 旧的同步分支内容留在本地备份,没有丢。

在新 base 上重跑的验证(不是沿用旧 head 的结果):

  • npm run typecheck 干净(0.1.213);
  • tests/issue5032-opencode-direct-window.test.ts + tests/opencode-native-v1.test.ts + tests/issue4894-direct-window-guard.test.ts → 38 pass / 0 fail;
  • npm run check:unused-exports clean(8 waived)、npm run check:test-import-graph ok、node scripts/lifecycle-ledger-guard.mjs OK;
  • 顺带确认缺陷在最新 master 上仍然成立:src/agent/opencode-native.ts 的 V1 车道依旧只设 state.prepareDirectSend、没有 arm declaredWindowForDirect(pi 车道同样没有),所以这个修复没有被 master 的 827 个提交吃掉。

状态:mergeable=MERGEABLE,files=2,CI 这次真跑起来了(不再 action_required),全量结果出来后我再同步。

合并顺序建议不变:#5027(pi) 先,本 PR 任意时点(两者文件不相交,已用 merge-tree 验过)。#5077(omp) 仍需 #5027 落地后再 rebase —— 它现在冲突在 src/agent/pi.ts,因为复用 #5027 的 piDeclaredWindowForDirect。

@adlternative

Copy link
Copy Markdown
Contributor Author

全量 CI 结果出来了,全绿。

6393e0be8 的 check-runs:37 success / 0 failure,13 个 skipped 全部是按设计 skip-gated 的 real-client / fake-upstream 端到端步骤(real codex vs deterministic fake upstream、real opencode native lane、real pi package-native lane、OpenCode V2 Responses WebSocket ACP 等,对应 workflow 级结论仍是 success)。

主 CI workflow(run 42564119338):completed / success,8m44s。
覆盖到的 gate:kernel-guard、pi-subagents-guard、docs-sync、docs-coverage、config-surface-guard、lifecycle-ledger-guard、lane-guard、version-guard、unused-exports、test-import-graph、lock-sync、mysql-contract、test (ubuntu/windows × node22/24 × 分片)、static-gates —— 全 success。

当前唯一剩下的状态是 BEHIND(不是冲突):期间 master 又走了 15 个提交(到 e2ff3a01c),mergeable 仍是 MERGEABLE,merge-tree 对当前 master 也是干净合并树。如果仓库开了「require up-to-date branch」,合并前需要再 rebase/sync 一次;要我随时可以再刷一版。

合并动作等 owner。顺序建议仍是 #5027 先、本 PR 任意时点。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

收到。全绿我独立核实过了;当前不需要再刷一版——BEHIND 不构成合并障碍,等 owner 拍板即可。

独立核实(不依赖你贴的结果)

  • 镜像缓存(今日 05:09Z 抓取)对 head 6393e0be8:30 项 check,0 failed / 0 pending,与你报的「37 success / 13 设计内 skip」一致——全绿确认。
  • BEHIND 状态核实:master 在你评论之后又走了几步(现 tip 5c3c2688,领先本 head 18 个提交);mergeable=MERGEABLE,且我在本地对当前 master 跑了 merge-tree:干净合并树,无冲突。
  • 顺带闭环两件事:① 之前 LIFECYCLE.md 补账(commit 0371089d)已进 master——那个漂移问题在上游彻底解决;② ci-fixes 上唯一还没进本 head 的提交(831b645804,把 tests/issue5955-wedged-same-lane-takeover.test.ts 登记进 LIVE_FILES)所改的内容也已在当前 master(scripts/live-files.mjs:126)——没有需要额外拉进来的东西。

为什么现在不刷新版

  • 哨兵本来就在持续把这个分支重排到新 base(本轮的 6393e0be8 就是产物);master 一天走十几个提交,现在手动 sync = 烧一轮约 9 分钟的全量 CI,跑完大概率又是 BEHIND,净收益≈0。
  • 合并时点才是新鲜度的正确检查点:若仓库开了「require up-to-date branch」,owner 合并前一步 sync(merge master → push)即可——机械操作、无冲突风险(上面已验证合并树干净)。到那一步说一声,我或你随时可以刷。

剩余状态:head 6393e0be8 全绿、可干净并入当前 master;合并动作等 owner。顺序建议同意:#5027 先、本 PR 任意时点。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

你的重排说明我逐条对着本地 git + 镜像缓存核过了:全部吻合,全绿独立确认。我这边没有待办动作,剩下就是等 owner 合并。

逐项核实(独立重查,不沿用你贴的结论)

  • head 形状:6393e0be8 = 单个功能提交(作者信息保留)落在 base 1bc2fafd9 上;diff 恰好两文件——src/agent/opencode-native.ts +38、tests/issue5032-opencode-direct-window.test.ts +168(合计 +206),无其他文件。与你描述一致;之前那个 LIFECYCLE.md +2 副作用确实不在本 PR 文件清单里了。
  • 全绿:镜像缓存(今日 06:15Z 抓取)对 6393e0be8:30 项 check,0 failed / 0 pending。
  • LIFECYCLE 迁移属实:master 上根目录 LIFECYCLE.md 是 110 字节 redirect stub,指向 docs/lifecycle.md;两个环境变量都已在真实台账里登记(BILI_SPAWN_FINGERPRINT 第 86 行、BILI_SESSION_CONTENT_STORE_PIN 第 135 行——就是之前补账的内容,随文档迁移完整保留)。当前 master tip(5c3c2688)直接跑 node scripts/lifecycle-ledger-guard.mjs = OK。
  • 缺陷仍成立:最新 master 上 src/agent/opencode-native.ts:271 依旧只设 state.prepareDirectSend,全文件零处 declaredWindowForDirect——修复没被 master 吃掉;pi 车道那半属于 [PR] fix: arm the pi lane's direct-send window guard so a proxy outage cannot egress an oversized history #5027(未合入),与你的说法一致。
  • 可合并性:mergeable=MERGEABLE;对当前 master tip 的 merge-tree 是干净合并树。一个数字对照:你说的「落后 827 个提交」应是旧 head(10-31 base)对当前 master 的差距;重排后现在只剩 18 个提交。

状态与后续

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

这条全绿报告之前已收到并独立核实过——见上方两条 [bot] 回复(06:11Z、06:31Z),此处不重复展开,无新动作。

刚又快速复核一遍:refs 无变化(head 6393e0be8、master tip 5c3c2688、落后 18 个提交、merge-tree 干净),镜像缓存对该 head 仍为 0 failed / 0 pending。状态与前述回复一致:全绿、可干净并入当前 master、等 owner 合并拍板(顺序:#5027 先、本 PR 任意时点)。若合并时点触发「require up-to-date」,说一声即可做那一步机械 sync。

@ranxianglei
ranxianglei merged commit 1ca3d68 into ranxianglei:master Nov 10, 2026
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants