fix(copilot): fix stream_err UnboundLocalError, move local import to top-level

Python 3 deletes `except ... as e` bindings after the except block
exits (PEP 3110). Save the exception to a persistent variable so
the for...else exhaustion block can reference it.

Also move `from backend.copilot.config import ChatConfig` from a
local import to top-level in transcript.py.
This commit is contained in:
Zamil Majdy
2026-03-14 21:06:06 +07:00
parent 384b261e7f
commit 9d1881d909
2 changed files with 3 additions and 3 deletions

View File

@@ -1409,7 +1409,8 @@ async def stream_chat_completion_sdk(
_MAX_STREAM_ATTEMPTS,
)
raise
except Exception as stream_err:
except Exception as e:
stream_err = e
logger.warning(
"%s Stream error (attempt %d/%d): %s",
log_prefix,

View File

@@ -21,6 +21,7 @@ from dataclasses import dataclass
from pathlib import Path
from uuid import uuid4
from backend.copilot.config import ChatConfig
from backend.util import json
from backend.util.clients import get_openai_client
from backend.util.prompt import CompressResult, compress_context
@@ -734,8 +735,6 @@ async def compact_transcript(
Returns the compacted JSONL string, or ``None`` on failure.
"""
from backend.copilot.config import ChatConfig
cfg = ChatConfig()
messages = _transcript_to_messages(content)
if len(messages) < 2: