{"record":{"id":"1b81ebaff71938dc","repo":"a-b-street/abstreet","slug":"active-agents-at-has-more-ended-trips-than-started","errorCode":null,"errorMessage":"active_agents at {} has more ended trips than started","messagePattern":"active_agents at (.+?) has more ended trips than started","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sim/src/analytics.rs","lineNumber":508,"sourceCode":"for (t, ended) in starts_stops {\n    if t != last_t {\n        // Step functions. Don't interpolate.\n        pts.push((last_t, cnt));\n    }\n    last_t = t;\n    if ended {\n        // release mode disables this check, so...\n        if cnt == 0 {\n            panic!(\"active_agents at {} has more ended trips than started\", t);\n        }\n        cnt -= 1;\n    } else {\n        cnt += 1;\n    }\n}","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/sim/src/analytics.rs#L490-L526","documentation":"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.","triggerScenarios":"Thrown at sim/src/analytics.rs:508 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check that all TripPhase::Cancelled and start events are recorded before end events in the analytics store","Verify the starts_stops sorting and the ended flag derivation for the affected agent","Re-run the simulation and regenerate analytics if the event log is truncated or corrupt"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0964f29315820c91b171b585eb51e300164e9197","analyzedAt":"2026-09-13T18:02:03.421Z","contentChangedAt":"2026-09-13T18:02:03.421Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}