You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "Harry33t (via GitHub)" <gi...@apache.org> on 2026/04/26 10:18:03 UTC

[I] [book-flight-ai-agent] 前端未返回 Set-Cookie,可能导致 context 无法跨请求保持 [dubbo-go-samples]

Harry33t opened a new issue, #1086:
URL: https://github.com/apache/dubbo-go-samples/issues/1086

   ## 问题描述
   
   我在本地测试 book-flight-ai-agent sample 时,发现访问首页后,响应头中没有返回 `Set-Cookie`。
   
   但是 `go-client/frontend/handlers/chat.go` 中的 `Index` handler 看起来会在没有 `current_context` 时创建新的 context,并写入 session:
   
   ``` go
   func (h *ChatHandler) Index(c *gin.Context) {
       session := sessions.Default(c)
       ctxID := session.Get("current_context")
       if ctxID == nil {
           ctxID = h.ctxManager.CreateContext()
           session.Set("current_context", ctxID)
           session.Save()
       }
       ...
   }
   ``` 
   如果浏览器或 HTTP client 没有收到 cookie,后续请求就无法携带同一个 session,可能导致:
   1、每次刷新页面都会创建新的 context;
   2、用户的对话上下文无法跨请求保持;
   3、context 数量持续增加,存在内存增长风险;
   4、/api/context/list、/api/context/switch 等接口的行为不符合预期。
   
   ## 复现步骤
   
   进入 book-flight-ai-agent 目录后,启动 server:
   > go run ./go-server/cmd/server.go
   启动 frontend:
   > go run ./go-client/frontend/main.go
   
   然后访问首页并查看响应头:
   
   > curl -i http://127.0.0.1:8080/
   
   ### 实际结果
   
   响应可以正常返回 HTML,但是响应头中没有看到 Set-Cookie:
   ```
   HTTP/1.1 200 OK
   Content-Type: text/html; charset=utf-8
   Date: ...
   Transfer-Encoding: chunked
   ```
   没有类似下面这样的 header:
   ```
   Set-Cookie: ...
   ``` 
   
   ### 预期结果
   
   如果该 sample 依赖 session 保存 current_context,那么首次访问首页并创建 context 后,响应中应该返回 Set-Cookie,让后续请求可以继续使用同一个 context。
   
   预期响应头中应包含类似:
   ```
   Set-Cookie: ...
   ```
   
   ## 影响
   
   该问题可能导致用户的对话上下文无法跨请求保持。对于一个 AI Agent demo 来说,context/session 行为会直接影响多轮对话体验。
   
   如果每次访问首页都创建新的 context,但没有通过 cookie 复用旧 context,也可能造成不必要的内存增长。
   
   ## 建议排查方向
   
   建议检查 go-client/frontend/main.go 中 Gin sessions middleware 的注册方式,以及 session store 的配置是否正确。
   
   可以重点确认:
   1) 是否正确注册了 sessions.Sessions(...) middleware;
   2) session.Save() 是否返回错误但未被检查;
   3) cookie path/domain/sameSite/secure 配置是否导致本地访问时没有下发;
   4) 首页 handler 中是否应该显式检查并记录 session.Save() 的错误。
   
   可以考虑:
   ```
   if err := session.Save(); err != nil {
       c.JSON(500, gin.H{"error": err.Error()})
       return
   }
   ``` 
   ## 补充说明
   
   如果当前设计并不打算通过 cookie/session 保持 context,也建议简化相关代码或在 README 中说明 context 的生命周期,避免用户误解。如果这个修复方向可以接受,我可以继续提交 PR。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] [book-flight-ai-agent] 前端未返回 Set-Cookie,可能导致 context 无法跨请求保持 [dubbo-go-samples]

Posted by "CAICAIIs (via GitHub)" <gi...@apache.org>.
CAICAIIs commented on issue #1086:
URL: https://github.com/apache/dubbo-go-samples/issues/1086#issuecomment-4322070201

   @huangguanxiong


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] [book-flight-ai-agent] 前端未返回 Set-Cookie,可能导致 context 无法跨请求保持 [dubbo-go-samples]

Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl closed issue #1086: [book-flight-ai-agent] 前端未返回 Set-Cookie,可能导致 context 无法跨请求保持
URL: https://github.com/apache/dubbo-go-samples/issues/1086


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org