Refactor: replace session.commit() with session.flush() in LLMTraceRepository.save()
to ensure changes are persisted within the UnitOfWork without prematurely committing
the database transaction.
- Updated LLMTraceRepository.save() to call session.flush() instead of session.commit()
in src/cleveragents/infrastructure/database/llm_trace_repository.py.
- Added two new BDD scenarios to features/llm_trace.feature:
- 'Repository save() calls flush not commit' to verify save() uses flush not commit.
- 'LLM trace rolled back when UnitOfWork transaction rolls back' to verify rollback.
- Added corresponding step definitions to features/steps/llm_trace_steps.py.
ISSUES CLOSED: #10034
Add LLMTrace Pydantic v2 domain model with all required fields (trace_id,
plan_id, decision_id, actor, provider, model, prompt_tokens, completion_tokens,
cost_usd, latency_ms, tool_calls, context_hash, streaming, retry_count, error).
Define 14 OperationalMetricKey values (PLAN_DURATION_MS, PLAN_TOTAL_COST_USD,
PLAN_DECISION_COUNT, ACTOR_INVOCATION_COUNT, ACTOR_LATENCY_MS,
TOOL_INVOCATION_COUNT, TOOL_ERROR_RATE, CONTEXT_BUILD_TIME_MS,
CONTEXT_TOKEN_COUNT, LLM_CALL_COUNT, LLM_TOTAL_TOKENS, LLM_TOTAL_COST_USD,
LLM_AVG_LATENCY_MS, SUBPLAN_COUNT) with MetricEntry model and MetricCollector.
Add llm_traces database table (LLMTraceModel) with LLMTraceRepository for
persistence. TraceService provides recording, querying, metric computation,
plan lifecycle hooks, and optional LangSmith forwarding when
LANGCHAIN_TRACING_V2=true.
Wired into DI container as trace_service. Includes 28 Behave BDD scenarios,
6 Robot Framework smoke tests, 3 ASV benchmark suites, and reference
documentation.
Fix pre-existing cli_core server_mode test flake by mocking
resolve_server_mode in test steps to avoid stale config file interference.
Closes#500