v3.9.8 — Fix Desktop model leak, global BrokenPipeError protection
This commit is contained in:
@@ -335,7 +335,7 @@ def _codebuff_get_session(token, model):
|
||||
req = urllib.request.Request(url, data=body, headers={
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {token}",
|
||||
"User-Agent": "codex-launcher/3.9.7",
|
||||
"User-Agent": "codex-launcher/3.9.8",
|
||||
"x-codebuff-model": model,
|
||||
})
|
||||
try:
|
||||
@@ -383,7 +383,7 @@ def _codebuff_start_run(token, agent_id):
|
||||
req = urllib.request.Request(url, data=body, headers={
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {token}",
|
||||
"User-Agent": "codex-launcher/3.9.7",
|
||||
"User-Agent": "codex-launcher/3.9.8",
|
||||
})
|
||||
try:
|
||||
resp = urllib.request.urlopen(req, timeout=15)
|
||||
@@ -416,7 +416,7 @@ def _codebuff_finish_run(token, run_id, status="completed"):
|
||||
req = urllib.request.Request(url, data=body, headers={
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {token}",
|
||||
"User-Agent": "codex-launcher/3.9.7",
|
||||
"User-Agent": "codex-launcher/3.9.8",
|
||||
})
|
||||
try:
|
||||
urllib.request.urlopen(req, timeout=10)
|
||||
@@ -4132,6 +4132,12 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
|
||||
model = body.get("model", MODELS[0]["id"] if MODELS else "unknown")
|
||||
stream = body.get("stream", False)
|
||||
_desktop_forced_models = {"gpt-5.4-mini", "gpt-5.4", "gpt-5.5", "gpt-5-codex", "gpt-5.3-codex"}
|
||||
_launcher_model = os.environ.get("CODEX_LAUNCHER_MODEL", "")
|
||||
if _launcher_model and model in _desktop_forced_models:
|
||||
print(f"[{_sid}] remap desktop model {model} -> {_launcher_model}", file=sys.stderr)
|
||||
model = _launcher_model
|
||||
body["model"] = model
|
||||
request_id = body.get("request_id") or body.get("id") or uid("req")
|
||||
if isinstance(input_data, list):
|
||||
for item in input_data:
|
||||
@@ -5305,7 +5311,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {token}",
|
||||
"User-Agent": "codex-launcher/3.9.7",
|
||||
"User-Agent": "codex-launcher/3.9.8",
|
||||
"x-codebuff-model": model,
|
||||
}
|
||||
if instance_id:
|
||||
@@ -5442,10 +5448,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
}],
|
||||
"usage": {"input_tokens": 0, "output_tokens": 0, "total_tokens": 0},
|
||||
}
|
||||
try:
|
||||
return self.send_json(200, result)
|
||||
except (BrokenPipeError, ConnectionResetError, ConnectionAbortedError):
|
||||
return
|
||||
return self.send_json(200, result)
|
||||
|
||||
def _cb_retry_thinking_disabled(self, body, model, token, agent_id, stream, tracker, input_data, instructions, original_error, acct=None):
|
||||
run_id, run_err = _codebuff_start_run(token, agent_id)
|
||||
@@ -5474,7 +5477,7 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
if body.get("tool_choice"):
|
||||
chat_body["tool_choice"] = body["tool_choice"]
|
||||
target = f"{_CODEBUFF_API_URL}/api/v1/chat/completions"
|
||||
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {token}", "User-Agent": "codex-launcher/3.9.7", "x-codebuff-model": model}
|
||||
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {token}", "User-Agent": "codex-launcher/3.9.8", "x-codebuff-model": model}
|
||||
if instance_id:
|
||||
headers["x-codebuff-instance-id"] = instance_id
|
||||
print(f"[codebuff] retry POST {target} model={model} stream={stream} run={run_id} (thinking disabled via DeepSeek native)", file=sys.stderr)
|
||||
@@ -5830,12 +5833,15 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
store_response(rid, input_data, result.get("output", []))
|
||||
|
||||
def send_json(self, status, data):
|
||||
body = json.dumps(data).encode()
|
||||
self.send_response(status)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
try:
|
||||
body = json.dumps(data).encode()
|
||||
self.send_response(status)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
except (BrokenPipeError, ConnectionResetError, ConnectionAbortedError):
|
||||
pass
|
||||
|
||||
def stream_buffered_events(self, event_iter, flush_interval=0.03, max_bytes=4096, on_event=None):
|
||||
buf = bytearray()
|
||||
|
||||
Reference in New Issue
Block a user