Repository navigation
[PR] fix: re-sign CodeArts traffic under the request's own account (#3106) - #3335
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4647-pr.3335.f8a17e3This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3335.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复。 本 PR(#3335,head 身份确认:这是 ework-daemon 自己提的 PR(分支 已核完的部分:
发现一个测试覆盖缺口(正在补):新增的 4 个用例只把两半各自当纯函数测了( |
…into the resolver
(ai: vllm-qwen/qwen3.8-27b) Review 完成。独立走了一遍 diff(方向 / 回归 / 代码 / 测试有效性 / 整洁度),没有照抄 issue 侧结论。发现一个覆盖缺口并当场补进了本 PR。 补充动作(review 发现的小问题,已当场修进本 PR):新增 4 个用例只把两半各自当纯函数测了,接缝没钉住——没有任何测试断言 intercept 真把解析出的入站 AK 作为第三参传给 resolver(现有 结构化八问(独立结论)
判定:方向打到根因(不是治标),代码 / 测试 / diff 均达标,接缝缺口已补。可合——但按仓库规则属 wire-behavior + 凭据选择逻辑,不走 auto-merge,需人工合并;合并前等 CI 在新 head |
rahul05ranjan
left a comment
There was a problem hiding this comment.
Reviewed this on a spare host — couldn't run the repo suite there (no dependency install), so I extracted the two new functions verbatim from the PR branch (pickCodeartsResignCred and inboundApigAccessKey) and ran them standalone under Node's type stripping, covering your four new scenarios plus extra edges. Everything below is what I actually executed.
What I confirmed:
- The mechanics match the described bug. Old code kept one global cache slot and always returned the first resolvable pool credential; new code prefers the account named in the inbound
Access=<ak>and only falls back to pool order when nothing matches. The single-account path is byte-identical (verified same result both ways), and the old first-valid semantics survive for unknown/missing AKs, exactly as the behavior table promises. - The regex handles the shapes that matter:
Access=AK,Signature=…,Access=at end-of-string, and it does not bite on aXAccess=lookalike (\bholds up). Empty/absentAccess=returns undefined and lands in the fallback rather than throwing mid-dispatch. - Cache behavior: per-
akkeying no longer clobbers across accounts within the TTL, a hit genuinely skips re-resolution, and an expired entry (11.5s > 10s TTL) re-resolves. I also checked that a fallback request with no inbound AK can't accidentally get a different account's cached entry — the fallback'scachedOf(cred.ak)is keyed on the account it just resolved, so that's sound. - Fail-soft is intact: a resolver that throws for the first candidate is skipped and the loop continues, in both the match loop and the fallback loop; all-candidates-failing returns undefined into the refusal lane, not a crash.
- Wiring:
native-intercept.ts:794passes the parsed AK as the third arg inside the existing try/catch, and the new seam test pins that — good call, since dropping the argument would pass every other test while silently regressing multi-account pools.
Two small things, neither blocking:
Access=is matched case-sensitively (src/agent/native-intercept.ts:227). The Huawei SDK always emits capital-AAccess=, so real traffic is fine, but a hand-rolled client using lowercaseaccess=would silently drop back to pool-order re-signing — i.e., the exact bug this PR fixes. A/ion the key name (not the scheme word) would cover it.- When
inboundAkdoesn't match any pool account (removed mid-flight), every candidate gets resolved twice within the same call — once in the match loop, again in the fallback loop. Harmless for the rare edge and a cheap local resolve, just noting it.
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.645-master.be3c58a # this exact build
npm install -g billion-context@master # always the newest merged build
|
背景
dsh-codearts-auth(jet-hub 里的反代)配 bili 时「一半模型废掉」。根因在 bili 侧重签路径:bili 对每个出站 body 重新签名时,不沿用入站请求原本用的那个账号,而是自己在账号池里挑第一个能解析出来的凭据,再用一个全局单槽 10s 缓存把它钉死。多账号池因此塌缩成一个凭据——家账号 ≠ 池里第一个可用账号的那些模型,重签出来用的是别人的 AK/SK,上游按签名校验直接拒(表现为这些模型全挂)。单账号用户不受影响。
对应 owner 的「缓存 miss」直觉:是 bili 自己的凭据缓存把池子塌缩了,不是上游 KV。
修复思路
让 bili 用入站请求自己签名的那个账号去重签(AK 就在入站
Authorization: SDK-HMAC-SHA256 Access=<ak>,…里),凭据缓存改为按 ak 分键。只有当池里找不到与入站 AK 匹配的账号、或请求没带 AK 时,才退回原来的「池序第一个可用」兜底。改动点:
src/agent/native-intercept.ts:抽出共享的headerRecordOf;新增inboundApigAccessKey()(从 Authorization 解析Access=<ak>);resignCredentialFor类型加可选第三参inboundAk(向后兼容)。src/agent/dsh-native.ts:抽出纯函数pickCodeartsResignCred()(同账号优先 → 兜底池序首可用,按 ak 分键缓存,逐候选 fail-soft),state.resignCredentialFor收敛成薄封装。tests/apig-resign.test.ts:4 个回归用例(AK 解析;同账号压过池序;按 ak 缓存跨账号不串号 + 命中不重复 resolve;未知/缺失 AK 回退首可用)。Access=<ak>解析),缓存按 ak 分键原因:旧实现把「请求该用哪个账号」和「bili 手里有哪些账号」两件事混为一谈,多账号下必然错配。属 wire-behavior 变更,需人工 review(不走 auto-merge)。
配置面
未新增任何配置/env/默认值。 账号选择由入站请求自身携带,无需用户配置。
测试
tests/apig-resign.test.ts:44/44 通过(含 4 个新回归用例;既有 40 个重签用例不变,无回归)。tsc --noEmit干净。结构化八问
Fixes #3106