Harry33t opened a new pull request, #1100:
URL: https://github.com/apache/dubbo-go-samples/pull/1100

   ## 问题
   
     `go-client/frontend/main.go` 把 `/` 路由注册成一个**匿名函数**,它只渲染模板、根本没碰 session:
   
     ```go
     r.GET("/", func(c *gin.Context) {
         c.HTML(http.StatusOK, "index.html", gin.H{
             "TimeoutSecond": cfgEnv.TimeOut,
             "OllamaModel":   cfgEnv.Model,
         })
     })
     ```
   
     而 `handlers/chat.go` 里**真正做 session 处理**的 `ChatHandler.Index` 
方法从未被注册到任何路由,是死代码。
   
     后果:
   
     - `GET /` 响应**没有 Set-Cookie 头**
     - 每次请求 session 里都拿不到 `current_context`,handler 在 `Chat` / `ListContexts` 
等地方继续 `CreateContext()`,`ContextManager.Contexts`       
     无上限增长
     - 浏览器刷新一次就丢一次会话历史
   
     ## 修复
   
     - `main.go`:把 `/` 路由改成 `r.GET("/", h.Index)`,删掉重复的匿名函数和不再使用的 `net/http` 
import
     - `handlers/chat.go::Index`:把 `TimeoutSecond` / `OllamaModel` 
模板变量补回来(保持页面行为不变),同时给 `session.Save()`
     加上错误日志(之前是静默忽略)
   
     ## 验证
   
     本地启动 server + frontend 后实测:
   
     ```bash
     $ curl -s -i http://127.0.0.1:8080/ | grep Set-Cookie
     Set-Cookie: llm_session=MTc3Nzg5OTc1Nnx...; Path=/; Max-Age=2592000
   
     # 用同一份 cookie 连续请求 3 次
     $ curl -s -b cookies.txt http://127.0.0.1:8080/api/context/list
     {"contexts":["0"],"current":"0"}
     ```
   
     修复前同样的 3 次请求会创建 3 个 context;修复后始终只有 1 个,会话语义正确。
   
     Closes #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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to