fix: 流的结局上桌——access log 补 proxy_stream 行 - #102
Merged
Merged
Conversation
线上诊断的直接教训:access log 只在 body 被读之前打一行,流被 deadline 掐断、被上游重置、被客户端挂断,全都落在 ProxyEvent.stream 的 report 里,而 logsReceiver 从不消费它——断流在日志里读作 outcome:"ok"。现在流结束时补一行 proxy_stream(outcome/bytes/ durationMs),与请求行靠 requestId 对上。 CPU 限额段落进 Body rewriting:免费版 10ms 是 CPU 时间不是墙钟, GitHub 量级的页面在 body 流完之前就击杀;签名是 cpuTime 钉死 10ms 的 exceededCpu。SSE 豁免改写所以 LLM 流不吃这笔账。 Co-Authored-By: Claude <noreply@anthropic.com>
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.
背景
线上诊断「LLM 反代总断流」的直接教训。两轮
wrangler tail(82 事件)证实:exceededCpu,cpuTime全部钉在 10ms = 免费版限额签名。凶手是 ClaudeBot 爬 GitHub 大 HTML 页,而该路由开了bodyRewrite,HTMLRewriter在免费版 10ms CPU 预算内根本改不动整页。超时开多大都救不了——路由四段超时只管墙钟/CPU 等待,不管HTMLRewriter的 CPU 计费。本 PR 修什么
1. 流的结局落地(logsReceiver)
ProxyEvent.stream早就把StreamReport(first_chunk_timeout/idle_timeout/upstream_reset/client_closed/complete+ bytes + durationMs)以 Promise 形式交给了 host,但logsReceiver从不消费——流被掐断在日志里永远读作outcome:"ok"、status 200,这正是断流查无可查的原因。现在:流结束时补一行结构化 JSON:
{"message":"proxy_stream","routeId":"bifrost","requestId":"...","upstream":"...","path":"/v1/chat","outcome":"idle_timeout","bytes":512,"durationMs":9800}与请求行靠
requestId对上。设计上仍然两行而非合并一行:请求行按库的既有约定在 body 被读之前打,合并意味着把每条 LLM 流的日志 hold 到分钟级。2. 免费版 CPU 限额写进 README(Body rewriting 一节)
把这次诊断的签名与判据沉淀下来:
cpuTime钉死 10ms 的exceededCpu= 免费版;CPU 是按请求终止(官方文档对 memory 才写 isolate 级行为,此处措辞已对齐);SSE 豁免改写所以 LLM 流不吃这笔账。验证
npm run check全绿(246 + 26 + 101 测试)部署侧建议(不在本 PR,需线上决策)
bodyRewrite(免费版改不动 GitHub 量级页面),或封 ClaudeBot,或升级付费计划。proxy_stream行上线后即可见。🤖 Generated with Claude Code