Repository navigation
Fix #22: clear stale request_id so plain chats work after idempotent ones - #30
Open
xiaoyao-666-coder wants to merge 2 commits into
Open
xiaoyao-666-coder wants to merge 2 commits into
xiaoyao-666-coder wants to merge 2 commits into
Conversation
…r idempotent ones
This was referenced Nov 19, 2026
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.
问题
带
request_id发一轮后,不带request_id的后续对话全部 409,会话被锁死,只能新建会话。根因
带
request_id的一轮把request_id/_request_fingerprint写进了持久化会话状态;下一轮 plain 请求从 store 读出旧 state,_state_for_request只在请求带 request_id 时才覆写这两个字段,不带时不做任何清理。随后_run_chat_transaction和流式路径stream_chat.run_sync都从这个 state 里读陈旧标识,调_check_request_fingerprint拿旧指纹比对新消息 → 不匹配 → 409。修复
只在
backend/app/main.py的_state_for_request里加了一个else分支:请求未带 request_id 时pop掉request_id/_request_fingerprint。清理点选在这里的原因:它是普通与流式两条路径唯一的 state 入口,清理发生在任何校验之前;request_fingerprints/request_results的保留逻辑没动,去重本身不受影响。附带效果:之前已被锁死的旧会话,下一次 plain 请求也会先清掉残留再校验,不用新建会话。验证
backend/tests/test_request_id_lock.py(6 个测试):request_id 轮之后 plain chat 正常 200 且 turn 正常推进(普通与流式都测);同 id + 同消息重放仍返回同一 turn 且不推进 turn;回放接口仍能取回结果;同 id + 不同消息仍 409(中间插一轮 plain 也不影响指纹);带 id / 不带 id / 带新 id 多轮交替全程无 409,且旧 id 重放仍有效;过短/非法字符 request_id 仍 422,且被拒的请求不污染会话。MEDGUIDE_MODE=test python -m pytest -q backend/tests527 passed(基线 521 + 6 新)。Closes #22