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")
|
||||
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,19 +1097,22 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
last_resp_id = None
|
||||
last_output = None
|
||||
last_status = None
|
||||
for event in stream_fn(upstream):
|
||||
self.wfile.write(event.encode("utf-8"))
|
||||
self.wfile.flush()
|
||||
for line in event.strip().split("\n"):
|
||||
if line.startswith("data: "):
|
||||
try:
|
||||
d = json.loads(line[6:])
|
||||
if d.get("type") == "response.completed":
|
||||
last_resp_id = d.get("response", {}).get("id")
|
||||
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)
|
||||
try:
|
||||
for event in stream_fn(upstream):
|
||||
self.wfile.write(event.encode("utf-8"))
|
||||
self.wfile.flush()
|
||||
for line in event.strip().split("\n"):
|
||||
if line.startswith("data: "):
|
||||
try:
|
||||
d = json.loads(line[6:])
|
||||
if d.get("type") == "response.completed":
|
||||
last_resp_id = d.get("response", {}).get("id")
|
||||
last_output = d.get("response", {}).get("output", [])
|
||||
last_status = d.get("response", {}).get("status")
|
||||
except: pass
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user