合并 codex/mcp-runtime-reliability: 运行可靠性、局状态与决策交接

Browse Source
与 main 上的审查修复及 2131f89 (story-test) 合并, 冲突处理:
- mcp_session: 保留超时/取消客户端, 补回 raise_on_error
- 执行器: 局状态改用 run_state (run_id 绑定), 取代完成后归档 context;
  Jev 请求统一经 jev_client.request_answer (支持 baseUrl/curl, 返回置信度与概率);
  保留截图解码缓存、地图模板缓存、按坐标点按钮、use_last_error 单实例互斥;
  刷新计数与开战标记只在动作成功后更新
- battle_batch: 取消/预算框架 + 只在看到胜率按钮时点胜率再回车;
  回合标签改为包含匹配 (OCR 常输出 'wave1')
- 文档采用 reliability 版本 (已是仓库相对路径), 注明 jev_client
- 测试: 互斥量桩改为 WinDLL/get_last_error, 战斗批次测试按胜率语义重写,
  Jev 测试改为对 jev_client 打桩, 生命周期测试改为轮询; 145 项通过

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yws
2026-10-03 03:12:48 +00:00
co-authored by Claude Opus 5.5
24 changed files with 2014 additions and 194 deletions
+28 -6
View File
@@ -78,6 +78,18 @@ class Server:
if not isinstance(msg, dict): if not isinstance(msg, dict):
return _error(None, -32600, 'request must be a JSON object') return _error(None, -32600, 'request must be a JSON object')
method, mid = msg.get('method'), msg.get('id') method, mid = msg.get('method'), msg.get('id')
valid_id = (mid is None or isinstance(mid, str) or
isinstance(mid, (int, float)) and not isinstance(mid, bool) and
(not isinstance(mid, float) or math.isfinite(mid)))
if msg.get('jsonrpc') != '2.0' or not isinstance(method, str) or not method or not valid_id:
return _error(mid if valid_id else None, -32600, 'invalid JSON-RPC request')
notification = 'id' not in msg
params = msg.get('params', {})
if not isinstance(params, dict):
return None if notification else _error(mid, -32602, 'params must be an object')
# Notifications never produce responses or trigger request-only tools.
if notification:
return None
if method == 'initialize': if method == 'initialize':
return _ok(mid, {'protocolVersion': '2024-11-05', return _ok(mid, {'protocolVersion': '2024-11-05',
'capabilities': {'tools': {'listChanged': False}}, 'capabilities': {'tools': {'listChanged': False}},
@@ -87,17 +99,17 @@ class Server:
if method == 'tools/list': if method == 'tools/list':
return _ok(mid, {'tools': TOOLS}) return _ok(mid, {'tools': TOOLS})
if method == 'tools/call': if method == 'tools/call':
params = msg.get('params') or {} name, arguments = params.get('name'), params.get('arguments', {})
result = self.call_tool(params.get('name'), params.get('arguments') or {}) if not isinstance(name, str) or not name.strip() or not isinstance(arguments, dict):
return _error(mid, -32602, 'tools/call requires a name and object arguments')
result = self.call_tool(name, arguments)
return _ok(mid, {'content': [{'type': 'text', 'text': json.dumps(result, ensure_ascii=False)}], return _ok(mid, {'content': [{'type': 'text', 'text': json.dumps(result, ensure_ascii=False)}],
'isError': not result.get('ok', False)}) 'isError': not result.get('ok', False)})
if mid is None:
return None # 通知 (notifications/*) 不回
return _error(mid, -32601, 'method not found: %s' % method) return _error(mid, -32601, 'method not found: %s' % method)
def call_tool(self, name, args): def call_tool(self, name, args):
try: try:
if name in TASK_TOOLS: # 不抢游戏锁: wait_for_text 期间也能查任务/停任务 if name in TASK_TOOLS: # 查任务/停任务不等待正在执行的游戏工具
return self._task_tool(name, args) return self._task_tool(name, args)
with self.lock: with self.lock:
return self._call(name, args) return self._call(name, args)
@@ -113,7 +125,14 @@ class Server:
if task not in TASKS: if task not in TASKS:
raise ValueError('unknown task %r' % task) raise ValueError('unknown task %r' % task)
params = {k: int(a[k]) for k in TASKS[task] if a.get(k) is not None} params = {k: int(a[k]) for k in TASKS[task] if a.get(k) is not None}
# Starting must not race a click that has already checked running().
# Reject promptly when busy instead of waiting behind a long OCR poll.
if not self.lock.acquire(blocking=False):
return {'ok': False, 'error': 'MCP 工具正在执行,完成后再启动 AALC 任务'}
try:
return self.tasks.start(task, params) return self.tasks.start(task, params)
finally:
self.lock.release()
if name == 'task_status': if name == 'task_status':
return self.tasks.status(a.get('lines', 30)) return self.tasks.status(a.get('lines', 30))
return self.tasks.stop() return self.tasks.stop()
@@ -216,6 +235,9 @@ def parse_line(line):
if not line: if not line:
return None, None return None, None
try: try:
return json.loads(line), None msg = json.loads(line)
if msg is None:
return None, _error(None, -32600, 'request must be a JSON object')
return msg, None
except ValueError as e: except ValueError as e:
return None, _error(None, -32700, 'parse error: %s' % e) return None, _error(None, -32700, 'parse error: %s' % e)