From 5c1753dfef9c6de24c544e9886de164858b5c3ec Mon Sep 17 00:00:00 2001 From: root Date: Tue, 16 Jun 2026 21:25:42 +0000 Subject: [PATCH] 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. --- main.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.py b/main.py index 53d2b3f..3c412e3 100644 --- a/main.py +++ b/main.py @@ -401,6 +401,7 @@ async def proxy( # ── Determine target URL ────────────────────────────────────────────── target_url: Optional[str] = None error: Optional[str] = None + sidecar_status = None # Circuit breaker check if not await circuit_breaker_check(): @@ -487,6 +488,13 @@ async def proxy( target_url = f"{MAIN_PC_BASE}/{path}" else: 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: circuit_record_failure() error = f"switch_error: {str(e)}"