From 2859d05572f5a8c077ce5a2228bcbe0ef5ff3e30 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 24 May 2026 20:13:32 +0000 Subject: [PATCH] v3.9.5: Fix thought_signature 400 + user instruction loss --- translate-proxy.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/translate-proxy.py b/translate-proxy.py index 3ffe7f9..12d0e8d 100755 --- a/translate-proxy.py +++ b/translate-proxy.py @@ -4346,9 +4346,12 @@ class Handler(http.server.BaseHTTPRequestHandler): except Exception: args = {} fc_part = {"functionCall": {"name": fname, "args": args, "id": call_id}} - stored_sig = _gemini_get_sig(f"fc:{call_id}") + stored_sig = _gemini_get_sig(f"fc:{call_id}") or _gemini_get_sig(f"fc:{fname}") if stored_sig: fc_part["thoughtSignature"] = stored_sig + fc_part["thought_signature"] = stored_sig + else: + fc_part["thought_signature"] = "skip_thought_signature_validator" contents.append({"role": "model", "parts": [fc_part]}) elif t == "function_call_output": call_id = item.get("call_id", item.get("id", "")) @@ -4451,9 +4454,11 @@ class Handler(http.server.BaseHTTPRequestHandler): break if latest_user: serialized = json.dumps(contents, ensure_ascii=False) - needle = latest_user.strip()[:120] - if needle and needle not in serialized: - print(f"[antigravity] WARNING: latest user instruction missing from contents! needle={needle[:60]}...", file=sys.stderr) + needle = latest_user.strip().replace("\n", " ")[:120] + escaped_serialized = serialized.replace("\\n", " ") + if needle and needle not in escaped_serialized: + print(f"[antigravity] latest user instruction missing from contents, appending", file=sys.stderr) + contents.append({"role": "user", "parts": [{"text": latest_user}]}) request_body = {"contents": contents} if system_parts: @@ -4597,10 +4602,16 @@ class Handler(http.server.BaseHTTPRequestHandler): if sig: if part.get("functionCall"): fc_id = part["functionCall"].get("id") or part["functionCall"].get("name") + fc_name = part["functionCall"].get("name") if fc_id: _gemini_store_sig(f"fc:{fc_id}", sig) + if fc_name: + _gemini_store_sig(f"fc:{fc_name}", sig) _gemini_store_sig(f"turn:{resp_id}", sig) if part.get("thought"): + sig_from_thought = _extract_gemini_sig(part) + if sig_from_thought: + _gemini_store_sig(f"turn:{resp_id}", sig_from_thought) continue if "text" in part and not part.get("functionCall"): text_delta = part["text"]