a-b-street/abstreet · error

active_agents at has more ended trips than started

Error message

active_agents at {} has more ended trips than started

What it means

active_agents replays trip start/end events to build a step-function count of agents over time. This fires while replaying an 'ended' event when cnt is already 0 — meaning the analytics recorded more trip endings than starts, which can only happen if event data is corrupt, events were truncated, or the ended flag logic is inverted. The comment notes release builds compile this check out, so it's a debug-time invariant.

Solutions

  1. Check that all TripPhase::Cancelled and start events are recorded before end events in the analytics store
  2. Verify the starts_stops sorting and the ended flag derivation for the affected agent
  3. Re-run the simulation and regenerate analytics if the event log is truncated or corrupt
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at sim/src/analytics.rs:508 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of a-b-street/abstreet@0964f29315 (2026-09-13). Data as JSON: /api/errors/1b81ebaff71938dc. Report an issue: GitHub.

Appendix: source

Thrown at sim/src/analytics.rs:508

for (t, ended) in starts_stops {
    if t != last_t {
        // Step functions. Don't interpolate.
        pts.push((last_t, cnt));
    }
    last_t = t;
    if ended {
        // release mode disables this check, so...
        if cnt == 0 {
            panic!("active_agents at {} has more ended trips than started", t);
        }
        cnt -= 1;
    } else {
        cnt += 1;
    }
}

View on GitHub (pinned to 0964f29315)