Files
kefu/deploy/review-visibility-20260916/fix_visual_handoff_races.py
T
2026-09-21 10:34:06 +08:00

45 lines
2.4 KiB
Python

from pathlib import Path
for root in (Path('C:/wechat_rpa'), Path('C:/kefu/wechat_rpa')):
path = root / 'wechat_bot.py'
raw = path.read_bytes()
source = raw.decode('utf-8').replace('\r\n', '\n')
def one(before, after):
global source
assert source.count(before) == 1, (before[:100], source.count(before))
source = source.replace(before, after)
one(''' if send_state in {"sent_uncommitted", "uncertain"} or (
send_state == "sending" and dispatch_reserved
):
''', ''' if (str(state.get("stage") or "") in {"sending", "receipt_check", "uncertain", "unknown"}
or send_state in {"sent_uncommitted", "uncertain", "unknown"}
or (send_state == "sending" and dispatch_reserved)
):
''')
one(''' state = self._pending_reply_state(fp) or {}
before_id = str((state.get("database_event") or {}).get("message_id") or "")
''', ''' initial_state = self._pending_reply_state(fp)
state = initial_state or {}
before_id = str((state.get("database_event") or {}).get("message_id") or "")
''')
one(''' state = self._pending_reply_state(fp) or {}
after_id = str((state.get("database_event") or {}).get("message_id") or "")
''', ''' current_state = self._pending_reply_state(fp)
if result and initial_state is not None and current_state is not initial_state:
self.report_progress("原任务已取消或转人工,旧模型回复已丢弃")
return None
state = current_state or {}
after_id = str((state.get("database_event") or {}).get("message_id") or "")
''')
one(''' reply_text = _humanize(ai_reply)
if self._reply_task_cancelled(fp):
''', ''' reply_text = _humanize(ai_reply)
if initial_pending_state is not None and self._pending_reply_state(fp) is not initial_pending_state:
self._generation_logged = True
self.report_progress("原任务已取消或转人工,旧模型回复已丢弃")
return None
if self._reply_task_cancelled(fp):
''')
path.write_bytes(source.replace('\n', '\r\n' if b'\r\n' in raw else '\n').encode('utf-8'))
print(root, 'handoff race and cancellation protections applied')