Repository navigation
fix: re-sign the preflight summarization egress over its own body (#3226) - #3234
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3766-pr.3234.0783cd0This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3234.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 收到 [PR],开始独立审核(不照抄 issue 侧结论)。 查重:不重复。 按失败签名(preflight + resign / body hash mismatch / x-sdk-content-sha256)检索 open+closed issue 与 PR:在途修同一机制的只有本 PR;同族的 #1884/#1934/#1885/#1886/#2090 均已关闭且修的是「签名请求能否进 bili / 主转发能否重签」,与「预检摘要出口漏重签」是不同出口、不同机制。无并行重复工作。 初步状态:分支 接下来按规范走完整审核:原 issue 方向关 → 回归审查 → 代码审查 → 测试有效性 → diff 整洁度,本地只跑定向套件 + typecheck,全量以远程 CI 为准。结论稍后按结构化八问给出。 |
) On CodeArts/Huawei-APIG signed lanes (SDK-HMAC-SHA256), the #1884 re-sign arm covered the main forward but NOT the preflight summarization call. That call sends a body bili built itself while still carrying the inbound signature (computed over the ORIGINAL request body), so the gateway recomputes the body hash, sees a mismatch and answers 401 -- which bili treats as a non-retryable auth rejection, so the whole turn fail-fasts 502 preflight_compress_failed. Compression was dead on signed lanes the moment a session crossed the window. - PreflightDeps gains an optional resign(headers, body) hook; requestSummaryBody builds the outbound header set first and lets the caller re-sign it over the summary's OWN bytes before fetch. - Extract inboundResignCredential() shared by the main forward, the nudge-decide side channel and now the preflight egress, so every body-covering lane resolves the same credential source; the relay/nudge inline computations become pure dedup. - Regression test drives a signed armed request past the window through a mock upstream that validates every signature: pre-fix it fails with exactly the reported 401 "declared payload hash != sha256(body)" -> 502; post-fix it compresses + forwards (200) with no 401 and no marker leak.
3e5c48b to
64e5e33
Compare
(ai: vllm-qwen/qwen3.8-27b) 审核进展(续上条):分支已 rebase 到当前 master(effd544,含 #3218/#3210/#3213/#3195 等 ~30 个新提交)并推送,无冲突、单 commit 保持干净。rebase 前我核对过:最初 独立复现了红/绿两端,不采信 PR 自述:
代码层面已核完的关键点: 现在等 CI 在推送头上跑完,绿了给最终八问结论。 |
(ai: vllm-qwen/qwen3.8-27b) Review 结论:可合并 ✅(八问体例)1. 是什么问题:CodeArts / 华为 APIG 这类 SDK-HMAC-SHA256 签名车道上,会话一旦超过模型窗口,预检压缩必然失败——用户看到 2. 什么原因导致的:三条「覆盖请求体」的出口车道里,只有预检摘要这一条缺重签钩子。主转发( 3. 影响范围与严重程度:仅 SDK-HMAC-SHA256 签名车道 × 会话超窗;该场景下压缩完全不可用(整轮 turn 502)。未签名流量、未超窗会话、其他 provider 不受影响。严重度高、场景面窄。 4. 怎么修复的:让预检摘要出口走与主转发同一条重签路径—— 5. 是否有回归问题(既有行为逐项清点):
6. 是否破坏缓存:不涉及。前缀缓存路由(session id / system-hash 键控)未动,重试预算、去重键、增量游标均未受影响。 7. 是否改了设计方向:没有。按既有 #1884 重签臂的设计精确补上孤立缺口,不引入新机制,架构/边界/数据流不变。 8. 是否引入了新的配置:无。复用既有 行为变更(有意披露):签名车道上,预检摘要出口的出站 验证证据(全部独立复现,未采信 PR 自述):
判定:可合并。 请手动合并:#3234 |
…#3226) The #2952 bounded tier-distillation recovery funnels through the SAME requestSummaryBody egress as the normal preflight round, so the signed-lane 401 kills it too -- but its failure log only printed error.message ("upstream error 401"), dropping the UpstreamHttpError.body that names the real cause ("body hash mismatch x-sdk-content-sha256 header"). That made the turn's fail-fast 502 read as "futile round / net ~0 tokens saved" (exhaustion) instead of a signature rejection. Surface a bounded body snippet like the sibling normal-round log already does, so this second visible form self-diagnoses.
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.452-master.6b5b283 # this exact build
npm install -g billion-context@master # always the newest merged build
|
是什么问题
CodeArts / 华为 APIG 签名车道(
SDK-HMAC-SHA256)上,会话一旦超过模型窗口,预检压缩(preflight compression)必然失败:用户看到502 preflight_compress_failed … summarization call was rejected by the upstream (HTTP 401): … body hash mismatch x-sdk-content-sha256 header。#1884/#1934 的重签名分支在主转发上是激活的(日志有re-sign arm engaged),但预检摘要这条出口没有重签——压缩在签名车道上超窗即死。根因(已在当前 master 源码核实,非仅看 reporter 引用的 0.1.197 dist)
主转发有重签名:
src/server/relay.ts的applyResign闭包对每个出口体调用resignApig(...)。nudge-decide 侧信道(src/server.tsrunNudgeDecision,#2228)也早已对它自建的重建体重签——这是本修复镜像的既有先例。reasoning-guard(src/reasoning-guard.ts)同样已带resign回调。缺口是孤立的:
requestSummaryBody(src/preflight.ts:1226)发送时用的是{ "content-type": "application/json", ...summaryHeaders(deps) },没有任何重签钩子。summaryHeaders克隆了几乎所有入站头(含authorization和针对原始请求体计算的x-sdk-content-sha256),却配上一个 bili 自己新建的摘要体 → 网关按新体重算 body hash → 不匹配 → 401 → bili 把 401 当作不可重试的鉴权拒绝 → fail-fast 502。修法(策略层)
让预检摘要出口走与主转发同一条重签路径,对它自己的字节重签,而不是沿用入站签名:
PreflightDeps增加可选resign?(headers, body)钩子;requestSummaryBody先把出站头集合构好,再让调用方对摘要自己的字节重签后才 fetch。inboundResignCredential(reqHeaders, opts, upstreamUrl),主转发、nudge-decide 侧信道、预检出口三条体覆盖车道统一从同一凭据源解析;relay/nudge 里原先内联的判定成为纯去重(行为不变)。401 "declared payload hash != sha256(body)" → 502;修复后压缩+转发成功(200),无 401、无 marker 泄漏。验证
[preflight] summarization failed: HTTP 401 … declared payload hash != sha256(body)→502 preflight_compress_failed。re-sign arm active、转发 200。tests/apig-resign.test.ts(39)、tests/issue2260-inert-resign-passthrough.test.ts(4)、tests/issue1993-preflight-400.test.ts(5)、tests/preflight-compress.test.ts(5)、新测试(1) = 54 pass / 0 fail。tsc --noEmit干净。Config surface
无。没有新增/改名/改语义任何配置字段、env var、CLI flag。复用的是既有
resign凭据通道(x-bili-resign/x-bili-resign-credential),不引入新形状。Behavior change(有意变更披露)
authorization/x-sdk-date/x-sdk-content-sha256从「入站克隆」变为「按摘要体重算」。原因:旧值会让网关 body hash 校验失败(401),这正是本 bug。resign钩子仅在凭据可解析时注入)。Closes #3226