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:
Binary file not shown.
@@ -918,12 +918,11 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||||||
_crof_debug_path = os.path.join(_LOG_DIR, "crof-upstream.jsonl")
|
_crof_debug_path = os.path.join(_LOG_DIR, "crof-upstream.jsonl")
|
||||||
with open(_crof_debug_path, "a") as _cdf:
|
with open(_crof_debug_path, "a") as _cdf:
|
||||||
_cdf.write(json.dumps({
|
_cdf.write(json.dumps({
|
||||||
"ts": _ts, "model": model, "max_tokens": chat_body.get("max_tokens"),
|
"model": model, "max_tokens": chat_body.get("max_tokens"),
|
||||||
"reasoning_enabled": REASONING_ENABLED, "reasoning_effort": chat_body.get("reasoning_effort"),
|
"reasoning_effort": chat_body.get("reasoning_effort"),
|
||||||
"enable_thinking": chat_body.get("enable_thinking", "NOT_SENT"),
|
"enable_thinking": chat_body.get("enable_thinking", "NOT_SENT"),
|
||||||
"n_messages": len(chat_body.get("messages", [])),
|
"n_messages": len(chat_body.get("messages", [])),
|
||||||
"has_tools": bool(chat_body.get("tools")),
|
"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")
|
}) + "\n")
|
||||||
req = urllib.request.Request(
|
req = urllib.request.Request(
|
||||||
target,
|
target,
|
||||||
@@ -1098,6 +1097,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||||||
last_resp_id = None
|
last_resp_id = None
|
||||||
last_output = None
|
last_output = None
|
||||||
last_status = None
|
last_status = None
|
||||||
|
try:
|
||||||
for event in stream_fn(upstream):
|
for event in stream_fn(upstream):
|
||||||
self.wfile.write(event.encode("utf-8"))
|
self.wfile.write(event.encode("utf-8"))
|
||||||
self.wfile.flush()
|
self.wfile.flush()
|
||||||
@@ -1110,7 +1110,9 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
|||||||
last_output = d.get("response", {}).get("output", [])
|
last_output = d.get("response", {}).get("output", [])
|
||||||
last_status = d.get("response", {}).get("status")
|
last_status = d.get("response", {}).get("status")
|
||||||
except: pass
|
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:
|
if last_resp_id and input_data is not None:
|
||||||
store_response(last_resp_id, input_data, last_output)
|
store_response(last_resp_id, input_data, last_output)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user