Skip to content

Fix #22: clear stale request_id so plain chats work after idempotent ones - #30

Open
xiaoyao-666-coder wants to merge 2 commits into
zhengdaodeguL:mainfrom
xiaoyao-666-coder:fix/issue-22-request-id-lock
Open

xiaoyao-666-coder wants to merge 2 commits into
zhengdaodeguL:mainfrom
xiaoyao-666-coder:fix/issue-22-request-id-lock

Conversation

@xiaoyao-666-coder

Copy link
Copy Markdown

问题

带 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,且被拒的请求不污染会话。
  • 反向验证:stash 掉改动再跑新测试,5 个失败、1 个通过,证明测试确实抓住了这个 bug。
  • 全量回归:MEDGUIDE_MODE=test python -m pytest -q backend/tests 527 passed(基线 521 + 6 新)。
  • 前端未动。

Closes #22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[高] 带 request_id 发一轮后,不带 request_id 的后续对话全部 409,会话被锁死

1 participant