Skip to content

Commit ecb833f

Browse files
authored
fix: resolve JSON serialization and logging exception propagation in claude_code_llm (#458, #459) (#461)
- 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 - Fix test_llm_provider.py to use _get_raw_config() for bank-configurable enable_observations field
1 parent 5270aa5 commit ecb833f

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

hindsight-api/hindsight_api/engine/providers/claude_code_llm.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -238,21 +238,24 @@ async def call(
238238
)
239239

240240
# Record trace span
241-
from hindsight_api.tracing import get_span_recorder
242-
243-
span_recorder = get_span_recorder()
244-
span_recorder.record_llm_call(
245-
provider=self.provider,
246-
model=self.model,
247-
scope=scope,
248-
messages=messages,
249-
response_content=result if isinstance(result, str) else json.dumps(result),
250-
input_tokens=estimated_input,
251-
output_tokens=estimated_output,
252-
duration=duration,
253-
finish_reason=None,
254-
error=None,
255-
)
241+
try:
242+
from hindsight_api.tracing import get_span_recorder
243+
244+
span_recorder = get_span_recorder()
245+
span_recorder.record_llm_call(
246+
provider=self.provider,
247+
model=self.model,
248+
scope=scope,
249+
messages=messages,
250+
response_content=result if isinstance(result, str) else result.model_dump_json(),
251+
input_tokens=estimated_input,
252+
output_tokens=estimated_output,
253+
duration=duration,
254+
finish_reason=None,
255+
error=None,
256+
)
257+
except Exception:
258+
pass # logging failure must never affect the operation
256259

257260
# Log slow calls
258261
if duration > 10.0:

hindsight-api/tests/test_llm_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ async def test_llm_provider_consolidation(memory_no_llm_verify, request_context,
332332
test_bank_id = f"llm_test_consolidation_{provider}_{model}_{datetime.now().timestamp()}"
333333

334334
# Enable observations for this bank
335-
from hindsight_api.config import get_config
336-
config = get_config()
335+
from hindsight_api.config import _get_raw_config
336+
config = _get_raw_config()
337337
original_value = config.enable_observations
338338
config.enable_observations = True
339339

0 commit comments

Comments
 (0)