fix: Optimized and support for inference context return - #539
Merged
Conversation
…rove request options management
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
「回传推理上下文」自
5781834b起完全失效:reasoning_content正常入库,但从未被读出来过。根因是
ListMessageAncestors/ListMessageAncestorsUntil两处WITH RECURSIVECTE 手写了列清单并漏掉reasoning_content。该清单原本是为规避「GORM Scan 遇到未知字段会出错」而写的——这个前提经实测是错的,GORM 按列名映射并静默忽略未匹配列(gorm/scan.go:276-281,与驱动无关)。所以本 PR 不只补列,而是把两处外层投影改为SELECT *,从根上消除「手写列清单随新增列漂移」这一 bug class。排查中发现同一 bug class 的另外两处,一并修复:
cloneSharedMessage手写字段清单同样漏掉ReasoningContent(且复制了ReasoningTokens,造成行内自相矛盾);中断生成的落库更新未带该字段,而UpdateAssistantMessageCompletion是无条件覆盖,会把已产出的推理抹成空——interrupted状态的 assistant 消息仍会进入后续轮次上下文。另外扩展了 Chat Completions 的回传厂商白名单,加入
moonshot/zhipu(issue 中提到的 K3 需求)。两家均要求历史 assistant 消息原样携带reasoning_content:Moonshot 缺失时服务端直接返回 400,智谱默认clear_thinking=false即保留思考。字段名与放置位置和现有序列化一致,未改动协议层。Fixes #529
Change type
Affected areas
Verification
pnpm check— 通过(api-contract 契约一致、biome lint 544 文件无问题、前后端 typecheck)pnpm test— 通过go build ./.../go vet ./.../gofmt -l internal/— 全部干净go test ./...— 55 包全绿,0 失败补充验证:
SELECT *的语法与_depth辅助列扫描行为一致未验证:没有挂真实 DeepSeek / Kimi / GLM 渠道端到端抓包确认出站请求携带
reasoning_content。建议合并后在同一对话连发 3 轮实测确认。Screenshots, API examples, or logs
变异测试输出(撤销修复时):
真实 Postgres 18 验证:
Configuration, migration, and compatibility notes
reasoning_content列早已由迁移添加(postgres.go:397),本 PR 仅修正读取pnpm check的 swagger/TS 契约校验通过),无生成物改动chat.reasoning_content_passback),vendor 判定全在后端;开关文案本就是 vendor 无关的「支持的 Chat Completions 推理模型」SELECT *对 DB 多出的列忽略、模型多出的字段取零值,行为不弱于原显式清单internal/infra/persistence/postgres仓储实现(persistence/sqlite/只含连接配置)Documentation
Security and privacy
安全加固说明:
ListMessageAncestors的递归项此前未约束m.conversation_id(兄弟方法ListMessageAncestorsUntil有)。经核查不是当前可利用漏洞——三条写入路径均强制同会话父指针,HTTP 层虽接受调用方传parentMessagePublicID,但经会话+用户双重限定的GetMessageByPublicID校验后才落库。但parent_message_id上没有外键,不变量纯靠应用层保证;且本 PR 的SELECT *会扩大一旦不变量被破坏时的泄漏面(原本连推理内容都读不出来)。已补上约束并加回归测试,测试绕过应用层直接植入跨会话父指针,验证遍历会停在会话边界。Checklist
.pycfiles,.envfiles, and local storage data are not committed.