You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Proposal: compress the remote.mux WebSocket with permessage-deflate (one line) and bound the follow-stream opening snapshot — measured 5–8× smaller first paint on mobile/remote links.
Measured problem: opening an in-progress session pushes a 0.4–2.9 MB uncompressed opening snapshot over /api/remote.mux; on a ~25 KB/s mobile link every connection died mid-transfer (gateway access logs: DC/UC on 100% of mux connections in a 30-minute window), and each reconnect re-pushed the full snapshot — a repush storm that made session history unloadable on phones.
Fix A (main increment; no existing issue found): new WebSocketServer({ noServer: true, perMessageDeflate: true }) in the API gateway's RemoteStreamMuxServer. Browsers offer PMD by default; the ws library negotiates it natively and falls back silently. Measured 3.4× on identical content (834 KB → 249 KB via gzip level 1). Proxy-chain passthrough verified end-to-end through Cloudflare Tunnel + Envoy/Istio + Caddy (101 response carries sec-websocket-extensions: permessage-deflate).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
性能优化提案:压缩 remote.mux WebSocket(permessage-deflate)并为首屏快照设界——移动端/远端链路实测首屏缩小 5~8 倍
现象(网关日志实测)
环境:dsh web 0.1.5-rc.1,经反向代理 + Cloudflare Tunnel 暴露,iPhone Safari 蜂窝网络访问。
打开一个进行中的会话时,浏览器与 Host 建立
/api/remote.muxWebSocket(101),Host 把首屏快照整体推下。反向代理访问日志里,近 30 分钟内每一次 mux 连接都以异常告终:每次断连后客户端秒级重连 → 整份快照再次全量重推 → 再断,形成重推风暴;弱网(
20–30 KB/s 有效吞吐)下 2 MB 需要 70170 s,而移动端浏览器锁屏/切后台会静默挂起 WebSocket(#2842),传输几乎必然中途死亡——表现为「会话内容永远加载不出来」。进行中的会话最严重:快照随会话增长、且叠加 assistantStream 累加器快照与实时流帧。根因
follow()的 opening snapshot 是最近maxMessages=50条消息窗口内的全部持久化事件(实测两个真实会话 835 KB / 663 KB),以 JSON 文本帧原样下发。另需澄清一点(实测):v3 会话格式已不持久化
assistant/chunk(v2 日志读取时折叠进assistant/message)。在 0.1.5-rc.1 上对 v2/v3 两种格式各取一页验证,assistant/chunk等流式分块事件均为 0——#2654 / #2598 针对的分块膨胀已由格式迁移解决。当前载荷是真实消息与工具结果内容,需要的是压缩与设界,不是过滤。方案(两个独立改动,可分别采纳)
A. 一行开启 permessage-deflate(本提案的主要增量,检索未发现既有 issue/讨论)
packages/api/gateway(RemoteStreamMuxServer):ws库原生支持,协商失败时静默回落不压缩,无兼容性风险。perMessageDeflate: { threshold, zlibDeflateOptions }微调。B. 首屏快照设界(与 #1706 同方向,作用于 follow 首屏)
packages/api/session-controller(follow()的 opening snapshot 分页处):MAX_PAGE_EVENTS,切割仍落消息边界)——两者可合并:快照页同时受消息数与事件数约束。hasMore/loadOlder分页路径不变(实测 capped 首屏渲染正常、「加载更早」回翻正常、页间连续性断言不受影响)。组合效果(本机实测数字)
重连重推成本同比例缩小(2 MB+ → ~150 KB 量级),重推风暴随之消失。
验证
assistant/chunk)与 v3 日志各取一页,页面分块事件均为 0。与既有讨论的关系
English summary
Proposal: compress the remote.mux WebSocket with permessage-deflate (one line) and bound the follow-stream opening snapshot — measured 5–8× smaller first paint on mobile/remote links.
/api/remote.mux; on a ~25 KB/s mobile link every connection died mid-transfer (gateway access logs: DC/UC on 100% of mux connections in a 30-minute window), and each reconnect re-pushed the full snapshot — a repush storm that made session history unloadable on phones.new WebSocketServer({ noServer: true, perMessageDeflate: true })in the API gateway'sRemoteStreamMuxServer. Browsers offer PMD by default; thewslibrary negotiates it natively and falls back silently. Measured 3.4× on identical content (834 KB → 249 KB via gzip level 1). Proxy-chain passthrough verified end-to-end through Cloudflare Tunnel + Envoy/Istio + Caddy (101 response carriessec-websocket-extensions: permessage-deflate).Math.min(maxMessages, 15); best merged with [Bug] Web GUI cannot open very large sessions — session.history pages are unbounded by event count #1706's event-count cap, message-boundary cut). Zero client changes — the existinghasMore/loadOlderjournal path is untouched. Measured 835→584 KB / 663→393 KB.assistant/chunk(v2 logs fold chunks intoassistant/messagewhen read) — verified zero chunk events in pages of both formats on 0.1.5-rc.1, so chunk filtering is now redundant; the remaining payload is real content that needs compression and bounds.All reactions