diff --git a/src/codexmcp/server.py b/src/codexmcp/server.py index 73a1e3b..c0a1bfa 100644 --- a/src/codexmcp/server.py +++ b/src/codexmcp/server.py @@ -221,15 +221,18 @@ async def codex( err_message = "codex error: " + line_dict.get("error", {}).get("message", "") if "error" in line_dict.get("type", ""): error_msg = line_dict.get("message", "") + import re is_reconnecting = bool(re.match(r'^Reconnecting\.\.\.\s+\d+/\d+$', error_msg)) + if not is_reconnecting: success = False if len(agent_messages) == 0 else success err_message = "codex error: " + error_msg - except json.JSONDecodeError as error: - # Improved error handling: include problematic line - err_message = line - success = False - break + + except json.JSONDecodeError: + import sys + print(f"Ignored non-JSON line: {line}", file=sys.stderr) + continue + except Exception as error: err_message = f"Unexpected error: {error}. Line: {line!r}" success = False