Merged
Conversation
根因:FastAPI < 0.118.0 的 StreamingResponse 依赖清理在流完成前执行, 导致 get_db() 的 commit() 在消息写入之前就已调用,user/assistant 消息丢失。 压缩/提炼后台任务复用已关闭的请求级 DB session,导致 'prepared' state 错误。 修复: - 升级 FastAPI >= 0.118.0 修复 StreamingResponse 生命周期 - reply() / reply_stream() 中显式 commit 确保消息持久化(防御性编程) - _compress() / _flush_background() 使用独立 AsyncSessionLocal + bg_memory - 修复 BufferMemory 构造函数错误参数 - 修复集成测试 UNIQUE 约束冲突 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
get_db()的commit()早于消息写入。升级 FastAPI >= 0.118.0 并在reply()/reply_stream()中添加防御性显式 commit。_compress()和_flush_background()改为使用独立的AsyncSessionLocal+bg_memory,避免'prepared' state错误。BufferMemory构造函数错误参数及集成测试 UNIQUE 约束冲突。Test plan
🤖 Generated with Claude Code