Repository navigation
Avoid reparsing completed Chat Turns during App and Lark admission #8316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0eaedc3
e6b81fd
33659ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1090,23 +1090,21 @@ def accept_managed_turn( | |
| agent_id="loopx-chat", | ||
| operation="accept_managed_chat_turn", | ||
| ): | ||
| turns = [ | ||
| payload | ||
| for path in ( | ||
| self._session_dir(session_token) / "turns" | ||
| ).glob("*.json") | ||
| if ( | ||
| payload := _read_json(path) | ||
| ).get("schema_version") == CHAT_TURN_SCHEMA_VERSION | ||
| ] | ||
| existing = next( | ||
| ( | ||
| turn | ||
| for turn in turns | ||
| if turn.get("client_turn_id") == client_id | ||
| ), | ||
| None, | ||
| ) | ||
| turns_dir = self._session_dir(session_token) / "turns" | ||
| turns = [] | ||
| existing = None | ||
| for path, turn in self._turn_discovery_rows(session_token, turns_dir, _read_json): | ||
| if turn.get("schema_version") != CHAT_TURN_SCHEMA_VERSION: | ||
| continue | ||
| # The planner needs live prepared Turns and the full | ||
| # current request when its client ID matches. | ||
| if existing is None and turn.get("client_turn_id") == client_id: | ||
| turn = _read_json(path) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Preserve a matched managed replay before planning admission 通过真实 App HTTP 重试一个已完成的请求,在准入内第二次读取其已匹配记录时注入一次 EIO。基线的排队请求复用原 Turn,托管请求返回 HTTP 400 并能在下一次健康重试复用原 Turn。新 head 的两个入口均返回 HTTP 202 和新 Turn,同 ID 记录 1→2、新增一条用户消息、上游 turn/start 1→2。 旧托管入口先把匹配完整记录交给 planner,第二次读失败发生在返回原记录时。新托管入口把这次读取移到 planner 之前,空对象被 continue,matching_turn 留空,已空闲 Session 遂准入新 Turn。排队路径同样把匹配后的空读当作缺失。 让冷路径直接保留本次匹配时已经读取的完整记录。热缓存命中后需要读取完整记录,若暂时读不到,应沿现有可重试错误路径退出准入。用相同故障覆盖排队和托管路径,断言单一 Turn、原 transcript 和派发次数。 |
||
| if turn.get("schema_version") != CHAT_TURN_SCHEMA_VERSION: | ||
| continue | ||
| if turn.get("client_turn_id") == client_id: | ||
| existing = turn | ||
| turns.append(turn) | ||
| session = self.load_session(session_token) | ||
| active_turn = None | ||
| if session is not None and session.get("active_turn_id"): | ||
|
|
@@ -1443,16 +1441,6 @@ def claim_next_queued_turn( | |
| return turn | ||
| return None | ||
|
|
||
| def turn_for_client(self, session_id: str, client_turn_id: str) -> dict[str, Any] | None: | ||
| turns_dir = self._session_dir(session_id) / "turns" | ||
| for path in turns_dir.glob("*.json") if turns_dir.is_dir() else []: | ||
| if path.name.endswith(".events.json"): | ||
| continue | ||
| payload = _read_json(path) | ||
| if payload.get("client_turn_id") == client_turn_id: | ||
| return payload | ||
| return None | ||
|
|
||
| def load_turn(self, session_id: str, turn_id: str) -> dict[str, Any] | None: | ||
| payload = _read_json(self._turn_path(session_id, turn_id)) | ||
| return payload if payload.get("schema_version") == CHAT_TURN_SCHEMA_VERSION else None | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Preserve a matched request when the full read fails
同一 client_turn_id 重试时,File Chat 的发现读取已经匹配原记录。只让随后重新打开该文件的一次 read_text 返回 EIO,已排队和已完成两种状态都从原来复用一个 Turn 变为创建第二个 Turn,并多写一条用户消息。 旧版直接使用第一次成功读到的整条记录。新版在匹配后总是再次读取,_read_json 将这一轮 EIO 转成空对象,turn_for_client 返回 None,create_queued_turn 于是走分配新 Turn 和写 transcript 的分支。 直接使用本次已完整读取的匹配记录。缓存只交付终态元数据时,正匹配后的完整读取失败应返回可重试的不可用结果,阻止重复准入。补齐冷、热、queued 和 completed 的故障用例,并核对健康重试及新请求的长历史读取数。