Skip to content

fix: threads-lane reforge side-call hits the chat endpoint instead of the bare origin - #3579

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-17_fix-3569-threads-reforge-endpoint
Oct 17, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-17_fix-3569-threads-reforge-endpoint

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3569

Also resolves the dispatcher half of #3516 item 4④ (src/server/threads-lane.ts raw fetch bypassing the proxy dispatcher → forced-proxy deployments stall each turn up to the side-call timeout): the side call now rides the same proxy decision as the main forward.

What was wrong

The threads-lane reforge (rollout BILI_ROLLOUT_ANTHROPIC_THREADS_REFORGE, default off) summarizes the folded prefix with one non-stream Anthropic-style side call. It was POSTed to the upstream origin (route.upstream, e.g. https://api.anthropic.com) because handle.ts passed (route0?.upstream ?? opts.upstream ?? "") straight into executeThreadsReforge, which fetched that URL verbatim. Real providers 404 the root path, so every over-window continue failed open: full transcript re-uploaded + ~0.4 s latency per turn, and foldedBefore stayed 0 forever. The #3332 fake upstream answered any path with 200, so the suite never saw it.

Changes

Behavior changes (old → new)

Area Old New Why
Side-call URL bare origin (e.g. https://api.anthropic.com) full endpoint incl. path/query, same as the main forward the origin always 404s — the bug
Side-call egress raw fetch, no proxy fetchWithTimeout + proxy dispatcher, same decision as the main forward forced-proxy deployments hung the side call every turn (#3516 item 4④)
Side-call timeout hard 120 s total 120 s idle watchdog (re-armed per chunk) consistency with all other outbound calls (#551); effectively equivalent for a non-streaming JSON answer
Side-call redirects implicit follow manual (3xx lands in the fail-open path) same policy as the main relay
Failure log summary side-call failed (HTTP 404) adds error.type=… / error.message=… + URL path diagnosability without leaking hosts
Retry cadence after a failure every continue 10 min per-session cooldown stop re-uploading doomed transcripts

No client-visible wire change beyond what the rollout already defines: the lane stays byte-faithful pass-through and fail-open in both modes; only bili's own internal side call changes.

Surface checks

  • Config surface: none (no new env/config keys; the cooldown is an internal constant).
  • Kernel: untouched (no kernel-change).
  • Tests: targeted suites green locally (tests/threads-lane.test.ts, tests/issue2701-threads-continue.test.ts — 14/14); typecheck clean. Full-suite verdict comes from CI on this head.

Out-of-scope note flagged for owner decision: the threads budget window reads top-level opts.modelContextLimit (src/server/prepare-anthropic.ts:107) while the rest of the anthropic prepare uses the route-resolved value — provider-level compress.modelContextLimit therefore does not reach the threads lane. Reported in #3569 as uncertain-if-intentional; left untouched here because it changes the reforge trigger threshold.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-17_fix-3569-threads-reforge-endpoint (567c9fd)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4229-pr.3579.fded700

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr3579.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。本条是 PR #3579(修 #3569)的 [PR] 镜像;按「threads reforge」「summary side-call」「executeThreadsReforge」检索 open+closed issue/PR,无同症状同机制的其他条目。关联项:#3516 条目 4④(threads-lane 裸 fetch 绕过代理 dispatcher)与本 PR 同一处代码、同一次修复,已并入;#3583(CI wire-exit-gap-cells flake 家族)是独立问题,与本 PR 无关。

这是本仓库 agent 已完成的 PR,我不重做工作——现在做独立审查:拉分支核对代码、回归清点、CI 状态确认,随后给出结构化八问结论。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

独立审查完成。没有复用 issue 侧已有结论——代码、测试、CI 全部自己重新核过一遍。

审查依据(独立验证)

  • 拉取分支 @ 567c9fd8e,base = 当前 master tip(b10c52576),无需 rebase,GitHub 报 mergeable=true。diff 共 3 文件 +112/-14,每一行都与本修复相关(diff 整洁)。
  • 逐行核了 buildForwardTarget/forwardUpstreamUrl/resolveProxyDecision/proxyDispatcher/fetchWithTimeout 全链:reforge 分支里 route0 就是主转发用的同一个 route(handle.ts:286 解析一次,全程复用),所以 side-call 的 URL 与代理决策和主转发同源同函数;出口契约(idle 看门狗按 chunk 重挂、redirect manual、无代理时 directDispatcher 兜底且传输层超时匹配)与仓库标准出站调用一致,且与既有的 nudge-decide 侧调用(runNudgeDecision)完全同构——这是仓库内已有先例,不是新发明。
  • 回归网有牙(对照实验):把修复前的代码检出、只换上本 PR 的测试文件跑——路径断言(forwardedPaths[1] === "/v1/messages")和冷却测试双双转红;在修复头 14/14 全绿。即这两个断言对原始 bug 直接敏感,不是恒真测试。
  • 本地定向:threads-lane + issue2701-threads-continue 两套 14/14 绿;typecheck 干净;tsc 无任何新告警。
  • executeThreadsReforge 签名变更已清点:src 内唯一调用点(handle.ts)已同步更新,tests 无直接调用者(grep 确认),安全。
  • 定时器生命周期逐行核过:clearTimer 在 finally 中调用;fetchWithTimeout 自身 throw 前会自清理;冷却 Map 在测试重置钩子里清空。无泄漏路径。

结构化八问

  1. 是什么问题:threads 折叠前的总结小呼叫错了地址——POST 打到上游「域名根」而不是聊天端点(如 /v1/messages),真实 provider 恒 404,折叠从未完成,每个超窗 continue 都原样白传整个 transcript 换回一个 404 + ~0.4s 延迟。
  2. 什么原因导致的:handle.ts 把「域名基址」语义的 route.upstream 直接传给 executeThreadsReforge,后者原样 fetch 且文件内无任何路径拼接;Anthropic Threads lane: unified-store mirror + over-budget reforge into fresh creates (#2926, #2884) #3332 的 fake upstream 对任意路径都答 200,测试网没牙。附带缺陷:该 fetch 还是裸 fetch,绕过代理 dispatcher(强制代理部署每回合卡到超时,v0.1.198 release blockers found in final pre-release review | v0.1.198 发版前终审发现的阻塞项清单 #3516 条目 4④)。
  3. 影响范围与严重程度:仅影响开了 BILI_ROLLOUT_ANTHROPIC_THREADS_REFORGE=1(默认关)且镜像超窗的用户;该条件下折叠功能完全不可用——不崩溃(fail-open),但功能永久失效 + 每回合带宽/延迟浪费。
  4. 怎么修复的:side-call 目标改由主转发同款函数 buildForwardTarget(req, opts, route) 派生——URL 与代理决策与主转发逐项一致,比手拼 /v1/messages 更稳(自动覆盖 mitm:// 改写、route.rewrittenUrl、绝对 URL 请求等形态);出口统一走仓库标准 fetchWithTimeout + proxyDispatcher 契约;失败加每会话 10 分钟冷却(抑制期间零成本提前返回,不重建请求体);日志补 error.type/error.message + URL path(只打路径不打 host,守脱敏纪律);测试补路径断言 + 冷却行为断言。
  5. 是否有回归问题:无。触碰路径既有行为逐项清点如下(见下节);两处语义漂移(超时总时长→空闲、重定向跟随→manual)是有意对齐仓库其它出站调用的既定策略(上游长时间 prefill(首 token 前无输出)被 undici 默认 bodyTimeout=300s 掐断,UPSTREAM_TIMEOUT_MS=10min 配置形同虚设,大上下文请求必超时 #551 / forward-proxy 正确性),PR 正文表格已披露旧值→新值。
  6. 是否破坏缓存:不涉及。不动 prompt cache/前缀缓存、重试游标、去重键;新增冷却状态是进程内 Map,重启即清,测试钩子单独清,不进持久化。
  7. 是否改了设计方向:不涉及。lane 架构(mirror/budget/reforge/fail-open)不变,只修正内部 side-call 的出口细节。
  8. 是否引入了新的配置:无。冷却窗口是内部常量 SUMMARY_RETRY_COOLDOWN_MS(10 min),刻意不暴露为配置面。

回归审计清单(审过的既有行为及结论)

  • 非 threads 请求:改动严格限定在 prepared.threadsReforge !== undefined 分支内(rollout 门控,默认关)+ 一条纯增量 import → 不受影响;
  • threads rollout 关(默认态):同上,不受影响;
  • rollout 开:create/continue 字节忠实直通、镜像捕获、预算计算、fold 点记录、reforged create 构造(system/tools 字节保真)、post-reforge 继续、legacy 存储降级、fail-open 姿态、re-create 重置 fold tracking——原有测试全数覆盖且本地 14/14 通过 → 保持;
  • 冷却 Map 增长性:只为失败会话建项、每次 arm 时顺带清过期项,量级与既有 warnedSessions 模式一致 → 可接受。

CI 状态(head 567c9fd):44 条 lane 全部 completed,43 条 success(含被门控跳过的 e2e 类),唯一红的是 test (windows-latest, 22, 2)——check-run id 117404718718,仍是原始那次 push(13:12Z)的结果,重跑还没发生。我的独立核查:挂掉的 wire-exit-gap-cells gap 3 不在本 PR diff 内;该测试文件对 threads/reforge 零引用(rollout 默认关,改动的 handle.ts 分支在该测试中根本不会执行);本地单跑 5/5 全绿。与 #3569 线程里的分析一致:毫秒级墙钟平局假红,已立项 #3583,与本 PR 无因果链。mergeable_state=blocked 由这条红 required check 造成。

发现(非阻塞)

  1. 覆盖缺口:v0.1.198 release blockers found in final pre-release review | v0.1.198 发版前终审发现的阻塞项清单 #3516 条目 4④ 那一半(side-call 真的走上游代理)没有直接测试钉住——现有 harness 没搭 fake 上游代理。风险低:机制与主转发同源(同一 buildForwardTarget 决策 + 仓库标准 proxyDispatcher),且 reporter 开 flag 复测时用的正是强制代理部署,等于真实环境验收。建议作为后续小补强,不扩本 PR 范围。
  2. 维持 PR 正文的待拍板项:threads 预算窗口读顶层 opts.modelContextLimit(prepare-anthropic.ts:107)而非 route-resolved 值,provider 级 compress.modelContextLimit 到不了 threads lane——改它会动 reforge 触发阈值,本 PR 正确地没碰,等 owner 定夺。

判定:方向对(修根因不修症状)、实现干净、测试有牙(对照实验证明)、无回归、diff 整洁。可合并——唯一前置是那条 windows 红 lane:请 owner 点一下 Re-run failed jobs(run 链接见 #3569 线程 floor 7),预期转绿;若重跑仍挂在同一断言,那将推翻假红假设,按真回归处理再深挖。合并动作本身归人工(系统规则禁止 agent 合并)。

@ranxianglei
ranxianglei merged commit 63956ea into master Oct 17, 2026
43 of 44 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.538-master.63956ea (rolling master tag).

npm install -g billion-context@0.0.538-master.63956ea  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

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

Labels

None yet

Projects

None yet

1 participant