← Back to Pull requests

fix: keep the newer report when an older one finishes after it #837

Closed
unknown closed this pull request without merging on Dec 01, 2026 10:00 UTC
View on GitHub
unknown unknown commented on Dec 01, 2026 09:54 UTC
Author

Tracker.UpdateAuthorized stores whichever report finishes last, whatever its timestamp says. One vehicle can have two reports in flight at once: the per-vehicle limiter allows a burst of 2, and a client can retry a request whose response was lost. If the older one finishes second, /gtfs-rt/vehicle-positions and trip-updates publish the older position and timestamp until the next report arrives.

The rest of the code already keeps the newest report:

  • GetRecentLocations, the startup seed, keeps the latest report by the fix's own timestamp (ORDER BY lp.timestamp DESC). So after a restart the feed shows the newest report, but while running it shows whichever finished last.

  • The alert watcher drops an off-route report older than the newest its vehicle sent (a5566cb).

  • The rider engine refuses a point that isn't after the previous one.
  • A retried copy of an older report already hits ON CONFLICT DO NOTHING when saved, but it still moved the tracker back.

    Changes:

  • UpdateAuthorized drops a report whose timestamp is older than the vehicle's current one. A report with an equal timestamp is still applied.

  • It still returns true in that case. false stays reserved for "a Remove won", so the handler doesn't log the misleading "vehicle removed while its report was processed". The doc comment now says so.
  • Test: TestTracker_UpdateAuthorized_KeepsTheNewerReport applies a newer report, then one 5s older. On main the vehicle's timestamp and position go back to the older report (expected: 1796118865 actual: 1796118860).

    A phone clock corrected backwards would hold the vehicle in place for that many seconds. validate() already limits skew to ±5 minutes, and trip end calls Remove, so the next trip starts fresh.

    Checks run locally: gofmt -l, go vet ., go test -run TestTracker .. All passed.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    Bug Fixes
    When reports for the same vehicle arrive out of order, the latest report is now retained instead of being replaced by an older one. This keeps the vehicle’s displayed timestamp and location consistent with its most recent reported information.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 289 lines (+216 / -73) across 3 files Reviewer: aaronbrethorst Review duration: 5m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.40) × (1 − Review Confidence (0.56)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 289 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 81% · Reviewer familiarity: 35%
    55%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.339
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #837"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 55.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.8% (MEDIUM) · Higher = larger blast radius
    39.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 55.9% · Lower = rushed or shallow review
    55.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.6% · Safe to merge
    17.6%