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:
parent
3c78b717b0
commit
1ac80bda6f
1 changed files with 44 additions and 36 deletions
|
|
@ -263,6 +263,7 @@ class CodexLLM(LLMInterface):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Record trace span
|
# Record trace span
|
||||||
|
try:
|
||||||
from hindsight_api.tracing import get_span_recorder
|
from hindsight_api.tracing import get_span_recorder
|
||||||
|
|
||||||
# Estimate tokens for tracing
|
# Estimate tokens for tracing
|
||||||
|
|
@ -274,13 +275,15 @@ class CodexLLM(LLMInterface):
|
||||||
model=self.model,
|
model=self.model,
|
||||||
scope=scope,
|
scope=scope,
|
||||||
messages=messages,
|
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,
|
input_tokens=estimated_input,
|
||||||
output_tokens=estimated_output,
|
output_tokens=estimated_output,
|
||||||
duration=duration,
|
duration=duration,
|
||||||
finish_reason=None,
|
finish_reason=None,
|
||||||
error=None,
|
error=None,
|
||||||
)
|
)
|
||||||
|
except Exception:
|
||||||
|
pass # logging failure must never affect the operation
|
||||||
|
|
||||||
if return_usage:
|
if return_usage:
|
||||||
# Codex doesn't provide token counts, estimate based on content
|
# Codex doesn't provide token counts, estimate based on content
|
||||||
|
|
@ -526,12 +529,15 @@ class CodexLLM(LLMInterface):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Record OpenTelemetry span
|
# Record OpenTelemetry span
|
||||||
|
try:
|
||||||
from hindsight_api.tracing import get_span_recorder
|
from hindsight_api.tracing import get_span_recorder
|
||||||
|
|
||||||
span_recorder = get_span_recorder()
|
span_recorder = get_span_recorder()
|
||||||
# Convert LLMToolCall objects to dicts for span recording
|
# Convert LLMToolCall objects to dicts for span recording
|
||||||
tool_calls_dict = (
|
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(
|
span_recorder.record_llm_call(
|
||||||
provider=self.provider,
|
provider=self.provider,
|
||||||
|
|
@ -546,6 +552,8 @@ class CodexLLM(LLMInterface):
|
||||||
error=None,
|
error=None,
|
||||||
tool_calls=tool_calls_dict,
|
tool_calls=tool_calls_dict,
|
||||||
)
|
)
|
||||||
|
except Exception:
|
||||||
|
pass # logging failure must never affect the operation
|
||||||
|
|
||||||
return LLMToolCallResult(
|
return LLMToolCallResult(
|
||||||
content=content,
|
content=content,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue