fix(frontend): proxy LangGraph SSE without buffering#2797
Open
LittleChenLiya wants to merge 1 commit intobytedance:mainfrom
Open
fix(frontend): proxy LangGraph SSE without buffering#2797LittleChenLiya wants to merge 1 commit intobytedance:mainfrom
LittleChenLiya wants to merge 1 commit intobytedance:mainfrom
Conversation
3f368e5 to
a4a6d0a
Compare
Contributor
There was a problem hiding this comment.
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. |
a4a6d0a to
aae3c14
Compare
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.
Summary
/api/langgraph/*从 Next rewrite 改为 App Router Route Handler 代理,避免 SSE 响应被 rewrite 路径缓冲。Cache-Control: no-cache, no-transform与X-Accel-Buffering: no。/api/:path*抢走/api/langgraph/*。背景
本地复现时,直接访问后端
127.0.0.1:8001/api/threads/.../runs/stream可以增量收到 SSE;但从前端同源路径localhost:3000/api/langgraph/.../runs/stream访问时,metadata、messages和end会在 run 结束后一起到达,导致 UI 表现为等待较久后一次性刷新。这个问题不是单纯缺少
messages-tuplestream mode;即使请求messages-tuple,rewrite 路径仍会缓冲 SSE。