fix(codex): resolve JSON serialization and logging exception propagation in codex_llm (#724)

Port fixes from #461 (claude_code_llm) to codex_llm:
- Replace json.dumps(result) with result.model_dump_json() for Pydantic models to fix TypeError during consolidation
- Wrap record_llm_call tracing block in try/except so logging failures never propagate to retry handler

Co-authored-by: Marco Rutsch <marco@rutimka.de>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Rutimka 2026-03-27 13:37:30 +01:00 committed by GitHub
parent 3c78b717b0
commit 1ac80bda6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -263,6 +263,7 @@ class CodexLLM(LLMInterface):
)
# Record trace span
try:
from hindsight_api.tracing import get_span_recorder
# Estimate tokens for tracing
@ -274,13 +275,15 @@ class CodexLLM(LLMInterface):
model=self.model,
scope=scope,
messages=messages,
response_content=result if isinstance(result, str) else json.dumps(result),
response_content=result if isinstance(result, str) else result.model_dump_json(),
input_tokens=estimated_input,
output_tokens=estimated_output,
duration=duration,
finish_reason=None,
error=None,
)
except Exception:
pass # logging failure must never affect the operation
if return_usage:
# Codex doesn't provide token counts, estimate based on content
@ -526,12 +529,15 @@ class CodexLLM(LLMInterface):
)
# Record OpenTelemetry span
try:
from hindsight_api.tracing import get_span_recorder
span_recorder = get_span_recorder()
# Convert LLMToolCall objects to dicts for span recording
tool_calls_dict = (
[{"id": tc.id, "name": tc.name, "arguments": tc.arguments} for tc in tool_calls] if tool_calls else None
[{"id": tc.id, "name": tc.name, "arguments": tc.arguments} for tc in tool_calls]
if tool_calls
else None
)
span_recorder.record_llm_call(
provider=self.provider,
@ -546,6 +552,8 @@ class CodexLLM(LLMInterface):
error=None,
tool_calls=tool_calls_dict,
)
except Exception:
pass # logging failure must never affect the operation
return LLMToolCallResult(
content=content,