Skip to content

bug: session.errors not auto-incremented when ERROR events are added #124

@acailic

Description

@acailic

Summary

TraceRepository.add_event() persists events but never updates SessionModel.errors when the event type is EventType.ERROR. As a result, get_session() always returns errors=0 even after error events have been added.

Reproduction

repo = TraceRepository(db_session, tenant_id="local")
session = Session(id="s1", ...)
await repo.create_session(session)

await repo.add_event(TraceEvent(session_id="s1", event_type=EventType.ERROR, ...))
await repo.add_event(TraceEvent(session_id="s1", event_type=EventType.ERROR, ...))

fetched = await repo.get_session("s1")
assert fetched.errors == 2  # FAILS — always 0

Expected behaviour

session.errors reflects the count of EventType.ERROR events in the session. Adding an error event should atomically increment the counter.

Current behaviour

session.errors stays at 0 unless explicitly set via update_session(session_id, errors=N).

Affected files

  • storage/repositories/event_repo.pyadd_event / add_events_batch
  • storage/repository.py — facade add_event / add_events_batch

Tracked by

Reproduction test: tests/test_issue_seed_data_quality.py::test_failure_count_populated_for_sessions_with_errors (currently xfail).

Metadata

Metadata

Assignees

No one assigned

    Labels

    auto-workAI auto-worker queuebugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions