Skip to content

fix(frontend): proxy LangGraph SSE without buffering#2797

Open
LittleChenLiya wants to merge 1 commit intobytedance:mainfrom
LittleChenLiya:fix/langgraph-sse-proxy-buffering
Open

fix(frontend): proxy LangGraph SSE without buffering#2797
LittleChenLiya wants to merge 1 commit intobytedance:mainfrom
LittleChenLiya:fix/langgraph-sse-proxy-buffering

Conversation

@LittleChenLiya
Copy link
Copy Markdown
Contributor

@LittleChenLiya LittleChenLiya commented May 8, 2026

Summary

  • /api/langgraph/* 从 Next rewrite 改为 App Router Route Handler 代理,避免 SSE 响应被 rewrite 路径缓冲。
  • 代理时保留 upstream response body 的流式返回,并设置 Cache-Control: no-cache, no-transformX-Accel-Buffering: no
  • 将非 LangGraph 的 gateway API rewrite 改为显式列表,避免 catch-all /api/:path* 抢走 /api/langgraph/*

背景

本地复现时,直接访问后端 127.0.0.1:8001/api/threads/.../runs/stream 可以增量收到 SSE;但从前端同源路径 localhost:3000/api/langgraph/.../runs/stream 访问时,metadatamessagesend 会在 run 结束后一起到达,导致 UI 表现为等待较久后一次性刷新。

这个问题不是单纯缺少 messages-tuple stream mode;即使请求 messages-tuple,rewrite 路径仍会缓冲 SSE。

@LittleChenLiya LittleChenLiya force-pushed the fix/langgraph-sse-proxy-buffering branch 3 times, most recently from 3f368e5 to a4a6d0a Compare May 8, 2026 15:32
@LittleChenLiya LittleChenLiya marked this pull request as ready for review May 8, 2026 15:49
@WillemJiang WillemJiang requested a review from Copilot May 8, 2026 16:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes how the frontend proxies LangGraph-compatible gateway endpoints by replacing Next.js rewrites with an App Router Route Handler, aiming to preserve SSE streaming behavior (avoid response buffering) on /api/langgraph/*.

Changes:

  • Add /api/langgraph/[[...path]] Route Handler that proxies to the gateway while streaming the upstream response body and normalizing headers to discourage buffering/transforms.
  • Add unit tests to validate URL construction, header forwarding/stripping, and streaming response behavior.
  • Replace the previous /api/:path* catch-all gateway rewrite with an explicit allowlist to prevent it from intercepting /api/langgraph/*.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
frontend/src/app/api/langgraph/[[...path]]/route.ts Introduces a Node.js runtime Route Handler proxy for LangGraph paths with streaming response passthrough and header normalization.
frontend/tests/unit/app/api/langgraph-route.test.ts Adds unit coverage for URL encoding, header filtering, request body streaming, and response header normalization.
frontend/next.config.js Removes /api/langgraph rewrites and replaces the gateway catch-all rewrite with an explicit set of gateway route rewrites.

Comment thread frontend/src/app/api/langgraph/[[...path]]/route.ts
@LittleChenLiya LittleChenLiya force-pushed the fix/langgraph-sse-proxy-buffering branch from a4a6d0a to aae3c14 Compare May 8, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants