Repository navigation
fix(riff): 宿主工具通道把网关 502 等非 JSON 应答报成状态码与响应摘录 - #2695
Merged
Merged
Conversation
沙箱访问宿主工具入口拿到网关的纯文本 502 时,CLI 先解析 JSON,只报出 JSON Parse error,看不出状态码和该查的配置。现在先读文本:worker 的 JSON 错误保留错误码并带上状态码;网关页、空响应、502/503/504 等非 worker 应答 报状态码加去掉凭据和控制字符、截断后的响应摘录,并指向 riff.hostToolsUrl / 平台远程访问 / BOTMUX_PUBLIC_URL 的配置说明;连不上时附错误码。直连客户端 不再构造 WHATWG Response,Node 下网关回 204 不再让 CLI 崩溃。编译版宿主机 的 CLI 下载命令在 curl 失败时给出同一条提示并停止。docs/riff.md 补排查说明。 宿主侧「本轮零请求即在群里补发未送达提示」无法与静默定时任务等本就不调 botmux 的轮次可靠区分,本次不做。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 2, 2026 15:26
Owner
Author
|
合入后核验(ac515ea64):
评审中提到的非阻断项,留作 follow-up(均未开 issue):
另:需求中的「宿主侧在群里补发回复未送达提示」本次未做,原因见 PR 描述「为什么没做」一节(无法与静默定时任务等本就不调用 botmux 的轮次可靠区分)。 |
deepcoldy
added a commit
to fangyeqing/botmux
that referenced
this pull request
Nov 3, 2026
|
🚀 Released in v3.57.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
v3.54.0(#2373)起,Riff 沙箱里的
botmux send等命令经宿主工具入口(/api/riff-host-tools)转到宿主机执行,直连飞书的兜底已关闭。有外部自部署用户的沙箱访问这个入口时,拿到中间网关返回的502,响应体是纯文本Bad Gateway:callRiffHostTool先response.json()再看状态码,报出的是JSON Parse error: Unexpected identifier "Bad",看不出是 HTTP 502、也看不出该查哪项配置;改了什么
src/cli/riff-host-tools.ts)running/completed应答才继续,其余一律报错,不再出现 JSON 解析错误。riff_host_http_403: riff_host_turn_unavailable,不附配置提示(请求已到达 worker,不是网络问题)。riff_host_http_502: Bad Gateway — check that the Riff sandbox can reach the botmux host-tools endpoint (botmux operator: set riff.hostToolsUrl, or platform remote access / BOTMUX_PUBLIC_URL; see https://github.com/deepcoldy/botmux/blob/master/docs/riff.md)空响应体显示
<empty body>,2xx 的非 JSON 页面显示riff_host_response_invalid (HTTP 200): …。***,再去掉 HTML 标签、C0/C1 控制字符和 bidi/零宽格式字符,合并空白,截到 120 个字符。riff_host_transport_unknown)附上错误码(ECONNREFUSED、ENOTFOUND、timeout等)和同一条配置提示;只取错误码,不带含私有地址的错误原文。Response包装应答:Node 下网关回204时,new Response(<空 Buffer>, { status: 204 })会在end回调里抛出未捕获的 TypeError,CLI 直接崩溃;现在改成只携带状态码和文本,任何状态码都按上面的规则报错。src/adapters/backend/riff-backend.ts):Linux x64 编译版宿主机注入的 CLI 下载命令,在curl --fail失败时多打印一行riff_host_cli_download_failed (see the curl error above): <同一条配置提示>并退出,不安装、不绑定。提示文本与 CLI 共用src/services/riff-host-hint.ts(不含依赖的叶子模块,沙箱 CLI 路径也会加载)。docs/riff.md「宿主机工具通道」补「排查:群里收不到回复,任务输出里有 502 等错误」小节(各报错的含义、入口地址的选取顺序、处理方法),常见问题表的「发消息后没回复」补第 ④ 条。为什么没做「宿主侧在群里补发回复未送达提示」
需求原定:worker 给某一轮签发了宿主工具绑定,但这一轮结束时一次请求都没收到,就在原群或原话题发提示;前提是能用「绑定之后有没有任何 riff-host-tools 请求到达(含 bootstrap 下载)」可靠区分「沙箱没连上」和「模型这一轮本就没调 botmux」,做不到就只做第 1 项。核实后做不到可靠区分,所以这一项没有做:
静默/silent定时任务(src/core/scheduler.ts的extractSilentMode)不发开始横幅,由模型决定是否botmux send,例如「挂了才报警」,一切正常的轮次不会发出任何宿主请求。按「零请求」判断会在这类轮次误报「回复未送达」。riff-host-bind只在沙箱本地写绑定文件,不联网;CLI 下载只在宿主是 Linux x64 编译版、且沙箱里 botmux 的 SHA-256 与宿主不同时才发生(通常只有新沙箱的第一轮),追问轮次和 npm / 源码部署根本没有下载步骤。riff_host_tools_v1)、参数在本地校验失败等情况,同样一次请求都不到达宿主,原因却不是入口不可达。沙箱连不上宿主时,宿主侧只剩 Riff 任务日志这一条信息来源(日志里的命令事件和输出文本)。靠它判断属于解析输出文本的启发式,依赖 Riff 的日志投影格式,不满足「判断要可靠」,所以没有采用。
对老用户的影响
botmux的报错文本有变化(模型和 Riff 任务日志可见):riff_host_turn_unavailable,现在是riff_host_http_403: riff_host_turn_unavailable(原错误码仍在其中,按子串匹配的判断不受影响);riff_host_transport_unknown; do not repeat automatically,现在在错误码后附原因码,并在末尾附配置提示。退出码不变(1)。这属于修 bug、改掉错误行为(标准 3.1 例外)。
<botmux_host_tools>里的下载命令在-o "$artifact"之后多了 317 个字符(约 80 token):curl … -o "$artifact"; printf '%s %s\n' <sha256> "$artifact" | sha256sum -c -; …curl … -o "$artifact" || { printf '%s\n' 'riff_host_cli_download_failed (see the curl error above): <配置提示>' >&2; exit 1; }; printf '%s %s\n' <sha256> "$artifact" | sha256sum -c -; …riff.hostToolsUrl的配置说明;curl --show-error只给出状态码,提示只能放在这条命令里(沙箱里还没有能输出提示的 botmux)。原命令已经set -e,失败后本来就会退出,加上exit 1不改变退出行为。影响面
callRiffHostTool与直连请求)和 Riff 任务引导命令。宿主侧网关(RiffHostTools.handle)、worker、其它 CLI 和其它后端都没有改动。验证
bun run build:通过(含 tsc、脚本与测试 mock 类型检查、构建/嵌入资源审计)。bunx vitest run test/riff-host-tools.test.ts test/riff-host-bootstrap.test.ts:78/78 通过;在isolate-run里连跑 6 轮,6 轮全绿。bun test单文件逐个跑:riff-host-tools46/46、riff-host-bootstrap32/32 通过。riff_host_http_502: Bad Gateway — …,只发了一次 POST;<empty body>,不再出现解析错误或 Node 下的崩溃;riff_host_response_invalid (HTTP 200): Sign in Login required — …;***,没有控制字符,摘录截到 120 字符;riff_host_http_403: riff_host_turn_unavailable,不附配置提示;riff_host_transport_unknown (ECONNREFUSED)…,报错里没有端口号;riff_host_cli_download_failed …riff.hostToolsUrl…,非零退出,原有 CLI 未被替换,没有执行绑定,输出里不含凭据。isolate-run里逐个注入,跑上面两个文件):12 处变异全部变红:Response→ 空 204 用例红(Node 下崩溃);|| { … exit 1; }→ 引导下载失败用例红。🤖 Generated with Claude Code