Skip to content

fix(map): recover missing route shapes - #608

Merged
aaronbrethorst merged 1 commit into
OneBusAway:developfrom
soumajitgh:fix/607-route-shape-fallback
Sep 6, 2026
Merged

aaronbrethorst merged 1 commit into
OneBusAway:developfrom
soumajitgh:fix/607-route-shape-fallback

Conversation

@soumajitgh

@soumajitgh soumajitgh commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • align map routes with the non-departed arrivals shown to riders
  • try up to three upcoming trip shapes before falling back to route-level geometry
  • cache successful shapes and briefly cache failures to avoid request amplification
  • keep arrival polling from redrawing healthy routes and clean up fallback segments and vehicles
  • add regression coverage for retries, fallback deduplication, caching, and redraw behavior

Testing

  • npm test -- --run (1,799 tests passed)
  • Prettier and ESLint checks on changed files
  • npm run build

Closes #607

Summary by CodeRabbit

  • Improvements
    • Map route displays now prioritize currently boardable arrivals and exclude trips that have already departed.
    • Route lines are more resilient when trip-specific geometry is unavailable, using alternate trips or route-level geometry when possible.
    • Multiple route segments can now be displayed for more complete coverage.
    • Map updates reuse previously loaded route geometry, improving redraw behavior.
    • Vehicle markers are cleaned up reliably when routes are removed from the map.

Retry a bounded set of boardable trip shapes and fall back to route-level geometry so one bad trip cannot hide an active route. Cache results to avoid request amplification during arrival polling.\n\nCloses OneBusAway#607
@coderabbitai

coderabbitai Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: e6200e77-17ab-4758-b4fa-19fc51a9a0e1

📥 Commits

Reviewing files that changed from the base of the PR and between 2ef7b96 and e36916c.

📒 Files selected for processing (5)
  • src/components/MapExperience.svelte
  • src/components/map/StopRoutesLayer.svelte
  • src/components/map/__tests__/StopRoutesLayer.test.js
  • src/lib/__tests__/activeRoutes.test.js
  • src/lib/activeRoutes.js

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change filters departed arrivals, exposes ordered trip candidates, and improves route shape rendering. Shape requests now use caching, alternate trip attempts, and route-level fallback segments. Rendering and teardown handle multiple polylines per route.

Changes

Route shape resilience

Layer / File(s) Summary
Boardable arrival candidates
src/lib/activeRoutes.js, src/lib/__tests__/activeRoutes.test.js, src/components/MapExperience.svelte
activeRoutesFromArrivals filters departed arrivals and returns ordered, deduplicated tripCandidates. MapExperience shares the boardable route set for selection and colors.
Cached shape retrieval and fallback
src/components/map/StopRoutesLayer.svelte, src/components/map/__tests__/StopRoutesLayer.test.js
StopRoutesLayer tries up to three trip shapes, caches successes and temporary failures, and falls back to route-level polylines. Tests cover alternate candidates, fallback segments, and cache reuse.
Multi-segment rendering and teardown
src/components/map/StopRoutesLayer.svelte, src/components/map/__tests__/StopRoutesLayer.test.js
Drawing, stop claiming, paint ordering, promotion, vehicle-marker cleanup, redraw behavior, and cache disposal now support multiple polylines per route.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: 🔵 Low · up to e3691

The change improves route recovery and is mergeable, but a route whose trip and fallback geometry all fail may remain missing for the current selection rather than retrying automatically after the failure-cache window.

Sequence Diagram(s)

sequenceDiagram
  participant StopRoutesLayer
  participant TransitAPI
  participant ShapeCache
  participant MapProvider
  StopRoutesLayer->>ShapeCache: request cached trip shape
  ShapeCache->>TransitAPI: fetch trip details and shape points
  TransitAPI-->>ShapeCache: return shape or failure
  StopRoutesLayer->>TransitAPI: fetch route fallback after trip failures
  TransitAPI-->>StopRoutesLayer: return fallback segments
  StopRoutesLayer->>MapProvider: create and reveal route polylines
Loading

Suggested reviewers: aaronbrethorst

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: recovering missing route shapes in the map.
Linked Issues check ✅ Passed The changes directly address issue #607 by retrying upcoming trip shapes, using route-level geometry as a fallback, and adding regression coverage for missing route rendering.
Out of Scope Changes check ✅ Passed The changes remain within scope. Retry logic, caching, arrival filtering, cleanup, redraw behavior, and tests all support reliable map route rendering.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. (2 skipped: 2 …
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 93.41% — soumajitgh:fix/607-route-shape-fallback into OneBusAway:develop. No base build found for OneBusAway:develop.

@aaronbrethorst

Copy link
Copy Markdown
Member

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

@aaronbrethorst aaronbrethorst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a careful piece of work on a genuinely awkward problem. The escalation — try up to three boardable trips in arrival order, then fall back to route-level geometry, rather than dropping the route off the map — is the right shape, and I like that the fallback is honest about being degraded rather than pretending it's the real trip shape.

The parts I checked hardest and found sound:

  • The polylinesByRouteId single-to-array conversion is complete. teardown(), reassertLinePaintOrder(), the promotion effect, and drawRoutes all handle the array form, and both providers already accept revealPolylines({only}) with multiple polylines and per-polyline removePolyline/setPolylineLayer, so nothing diverges between OSM and Google.
  • polledRouteIds is the right fix for the actual leak: vehicle polling starts for every active route including ones whose shape never resolves, so teardown has to snapshot the union rather than just the drawn keys.
  • The stale-token path inside the multi-segment loop correctly removes every segment the superseded route already attached, not just the one in flight.
  • filterDeparted(arrivals, now) matches its real signature, and gating on Number.isFinite(now) keeps the no-options callers on the old unfiltered behavior.

One thing worth a follow-up, not a blocker. routeColors now derives from the departed-filtered boardableRoutes, but StopPane seeds its rows from the unfiltered entry on first render and only applies filterDeparted on subsequent polls. So a route whose only cold-load arrival has already departed renders a row with no assigned color and falls back to route?.color until the first poll corrects it. Cosmetic and self-healing, and the comment above routeColors about two consumers with different staleness semantics is now carrying a third axis it doesn't mention — worth a line when you're next in there.

Merging.

@aaronbrethorst
aaronbrethorst merged commit a97d145 into OneBusAway:develop Sep 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some routes are not drawn in onebusaway-mcp-ui but are visible in WayFinder

3 participants