fix(hermes): 保证最后一轮 capture 先于 session flush#479
Open
Qiyuanqiii wants to merge 1 commit into
Open
Conversation
Author
|
仍值得继续挖的下一优先级是 Gateway JSON 请求边界:当前畸形 JSON 会落入 500,请求体也没有大小上限,可拆成一个返回 400/413、支持中止并有定向测试的小型协议修复。user_id 真正租户隔离和跨重启持久化幂等也有价值,但改动范围明显更大,我想询问维护者这个方向是否有价值去做,还有就是#470能否审阅一下 |
Collaborator
|
hank you for submitting this PR and participating in Tencent Rhino-bird Open-source Training Program! |
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.
关联 Issue
Related to #235
背景与定位
本 PR 是一个独立的 Hermes 生命周期正确性修复,不新增 Gateway client、MCP bridge 或平台适配器。
它不修改 #470 或 #476,也不与 #316/#372 的共享客户端和 MCP 基线竞争。
问题根因
Hermes 的
sync_turn()会为每轮 capture 创建后台线程,以避免阻塞模型响应;但正常的on_session_end()不会等待这些线程,而是立即调用 Gateway/session/end。因此最后一轮 capture 较慢时,实际顺序可能变成:
Gateway 会先完成旧状态的 flush,最后一轮 capture 随后才写入并通知 scheduler。宿主此时已经认为会话结束,新增工作可能停留在未 flush 状态。
本地使用阻塞假客户端稳定复现出了:
此外,原实现先把 Thread 注册到 _active_syncs,释放锁后才调用 start()。session end 如果恰好插入这个窗口,会把“已登记但尚未 alive”的合法 capture 当作无效线程清除。
修复方案
范围边界
本 PR 仅修改 Hermes provider 和对应标准库测试,不涉及:
验证
python -m unittest discover -s hermes-plugin/memory/memory_tencentdb/tests -p test_session_end_ordering.py -v python -m py_compile hermes-plugin/memory/memory_tencentdb/__init__.py hermes-plugin/memory/memory_tencentdb/tests/test_session_end_ordering.py npm test npm run build git diff --check origin/main...HEAD验证结果:
验证截图