fix: log sidecar switch failures + fix scoping bug in proxy handler

Two changes to debug the fallback-to-LXC issue:

1. Added debug logging on switch failure: prints the profile name,
   sidecar response status, and error message. Also calls
   circuit_record_failure() so subsequent requests don't wait the
   full 120-second timeout before falling back.

2. Fixed scoping bug: sidecar_status was only defined inside the
   else branch of the circuit breaker check. Initialized to None
   at function scope alongside target_url and error to prevent
   NameError when circuit is open.
This commit is contained in:
root 2026-06-16 21:25:42 +00:00
parent f2e62f60e6
commit 5c1753dfef

View File

@ -401,6 +401,7 @@ async def proxy(
# ── Determine target URL ────────────────────────────────────────────── # ── Determine target URL ──────────────────────────────────────────────
target_url: Optional[str] = None target_url: Optional[str] = None
error: Optional[str] = None error: Optional[str] = None
sidecar_status = None
# Circuit breaker check # Circuit breaker check
if not await circuit_breaker_check(): if not await circuit_breaker_check():
@ -487,6 +488,13 @@ async def proxy(
target_url = f"{MAIN_PC_BASE}/{path}" target_url = f"{MAIN_PC_BASE}/{path}"
else: else:
error = "switch_failed" error = "switch_failed"
circuit_record_failure()
print(
f"SWITCH FAILED: profile={requested_model}, "
f"sidecar_status={switch_result.get('status')}, "
f"message={switch_result.get('message', '(no message)')}",
flush=True,
)
except Exception as e: except Exception as e:
circuit_record_failure() circuit_record_failure()
error = f"switch_error: {str(e)}" error = f"switch_error: {str(e)}"