v2.2.1: fix NameError _ts crash + catch stream disconnect errors

- Fix NameError: _ts undefined in crof debug logging (caused ALL requests to crash)
- Catch ConnectionResetError/BrokenPipeError during streaming (graceful client disconnect)
- Tested: kimi-k2.6 + mimo-v2.5-pro streaming through proxy, both status=completed
This commit is contained in:
Roman
2026-05-20 13:54:47 +04:00
Unverified
parent 0a3cd3fd7a
commit 881f4f35d2
2 changed files with 18 additions and 16 deletions

Binary file not shown.

View File

@@ -918,12 +918,11 @@ class Handler(http.server.BaseHTTPRequestHandler):
_crof_debug_path = os.path.join(_LOG_DIR, "crof-upstream.jsonl")
with open(_crof_debug_path, "a") as _cdf:
_cdf.write(json.dumps({
"ts": _ts, "model": model, "max_tokens": chat_body.get("max_tokens"),
"reasoning_enabled": REASONING_ENABLED, "reasoning_effort": chat_body.get("reasoning_effort"),
"model": model, "max_tokens": chat_body.get("max_tokens"),
"reasoning_effort": chat_body.get("reasoning_effort"),
"enable_thinking": chat_body.get("enable_thinking", "NOT_SENT"),
"n_messages": len(chat_body.get("messages", [])),
"has_tools": bool(chat_body.get("tools")),
"messages_summary": [{"role": m.get("role"), "tc": len(m.get("tool_calls", [])), "content_len": len(str(m.get("content", "")))[:6], "tool_call_id": m.get("tool_call_id")} for m in chat_body.get("messages", [])],
}) + "\n")
req = urllib.request.Request(
target,
@@ -1098,6 +1097,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
last_resp_id = None
last_output = None
last_status = None
try:
for event in stream_fn(upstream):
self.wfile.write(event.encode("utf-8"))
self.wfile.flush()
@@ -1110,7 +1110,9 @@ class Handler(http.server.BaseHTTPRequestHandler):
last_output = d.get("response", {}).get("output", [])
last_status = d.get("response", {}).get("status")
except: pass
_log_resp(last_resp_id, last_status, last_output)
except (ConnectionResetError, BrokenPipeError, ConnectionAbortedError):
print("[translate-proxy] client disconnected during stream", file=sys.stderr)
_log_resp(last_resp_id, last_status or "client_disconnect", last_output)
if last_resp_id and input_data is not None:
store_response(last_resp_id, input_data, last_output)
else: