fix(book-flight-ai-agent): 前端 / 路由接入 ChatHandler.Index 修复 Set-Cookie 不下发问题 (#1086)#1100
Merged
Alanxtl merged 1 commit intoMay 10, 2026
Merged
Conversation
Member
|
merge to main to fix ci fail |
…ndex The "/" route was registered with an inline anonymous function that just rendered the template without touching the session, while ChatHandler.Index — the method that actually reads/creates the session context and calls session.Save() — was never wired up. As a result: - The first GET / never returned a Set-Cookie header. - Every subsequent request still found no `current_context` in the session and created a brand-new context, growing ContextManager.Contexts unbounded and discarding conversation history on every page reload. Fix: - Use h.Index for the GET / route in main.go and drop the now-unused net/http import. - Move the template variables (TimeoutSecond, OllamaModel) into ChatHandler.Index so the page still renders with the same data. - Check the error from session.Save() and log it; previously it was silently dropped. Verified manually: $ curl -s -i http://127.0.0.1:8080/ | grep Set-Cookie Set-Cookie: llm_session=...; Path=/; Max-Age=2592000 # 3 sequential requests reusing the same cookie $ curl -s -b cookies.txt http://127.0.0.1:8080/api/context/list {"contexts":["0"],"current":"0"} Closes apache#1086
7a51dcc to
ac9a696
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.
问题
go-client/frontend/main.go把/路由注册成一个匿名函数,它只渲染模板、根本没碰 session:而
handlers/chat.go里真正做 session 处理的ChatHandler.Index方法从未被注册到任何路由,是死代码。后果:
GET /响应没有 Set-Cookie 头current_context,handler 在Chat/ListContexts等地方继续CreateContext(),ContextManager.Contexts无上限增长
修复
main.go:把/路由改成r.GET("/", h.Index),删掉重复的匿名函数和不再使用的net/httpimporthandlers/chat.go::Index:把TimeoutSecond/OllamaModel模板变量补回来(保持页面行为不变),同时给session.Save()加上错误日志(之前是静默忽略)
验证
本地启动 server + frontend 后实测:
修复前同样的 3 次请求会创建 3 个 context;修复后始终只有 1 个,会话语义正确。
Closes #1086