From b92fc723f06137cd037c24d4ab8e03ad8d6e8970 Mon Sep 17 00:00:00 2001 From: emco Date: Tue, 9 Jun 2026 12:19:11 +0100 Subject: [PATCH] fix: guard ACTIVE_MODEL_INSTANCES lookup and add json default=str --- src/cai/parallel_worker.py | 2 +- src/cai/tools/streaming.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cai/parallel_worker.py b/src/cai/parallel_worker.py index d69511fbf..146c04f0b 100644 --- a/src/cai/parallel_worker.py +++ b/src/cai/parallel_worker.py @@ -132,7 +132,7 @@ def main() -> int: try: with open(args.result_file, "w", encoding="utf-8") as f: - json.dump(payload, f, ensure_ascii=False) + json.dump(payload, f, ensure_ascii=False, default=str) except Exception as write_error: # pylint: disable=broad-except print(f"[CAI worker] failed to write result file: {write_error}", file=sys.stderr) return 2 diff --git a/src/cai/tools/streaming.py b/src/cai/tools/streaming.py index f2e7554fd..b5f55a218 100644 --- a/src/cai/tools/streaming.py +++ b/src/cai/tools/streaming.py @@ -125,10 +125,13 @@ def _get_agent_token_info(): from cai.sdk.agents.models.openai_chatcompletions import ACTIVE_MODEL_INSTANCES if ACTIVE_MODEL_INSTANCES: - # Get the most recent instance (highest instance ID) - latest_key = max(ACTIVE_MODEL_INSTANCES.keys(), key=lambda x: x[1]) - model_ref = ACTIVE_MODEL_INSTANCES[latest_key] - model = model_ref() if model_ref else None + try: + # Get the most recent instance (highest instance ID) + latest_key = max(ACTIVE_MODEL_INSTANCES.keys(), key=lambda x: x[1]) + model_ref = ACTIVE_MODEL_INSTANCES.get(latest_key) + model = model_ref() if model_ref else None + except Exception: + model = None if model: # Get display name with ID