Fix inconsistent bus stop loading: switch route queries from around() to bbox#5
Merged
Merged
Conversation
… stops Bus stops loaded inconsistently even after the previous chunking fix. Investigation against the live Overpass API found two compounding root causes: 1. Overpass's around(radius, point-list) operator costs scale with points-in-list x candidate-elements-in-area. A single chunk at the previous chunkMaxPoints=160 reliably timed out; even much smaller chunks (25-60 points) took anywhere from 3s to 23s depending on how road-dense the area was -- the same chunk size that was fine in a quiet area could time out in a busy one, which is exactly the "sometimes works, sometimes doesn't" behavior reported. 2. When Overpass's own [timeout:N] elapses, it replies HTTP 200 with an empty elements array and a "remark" field describing the error -- not an error status. The client only checked the HTTP status code, so a timed-out chunk was silently indistinguishable from "no stops near this stretch of road" and never retried or logged. Fixes: - Replace the around() query with a bounding-box query per chunk. A bbox test is an O(1) rectangle check per candidate regardless of route shape or point density, unlike around(). Verified live: a chunk that took 16-23s (or timed out) via around() resolved via bbox in 2-8s for the same area, including a deliberately pathological zigzag route whose bbox came out much larger than the route itself. - Chunk the route by real-world distance (~5km) instead of point count, since query cost no longer depends on point density -- this also simplifies chunk building (no separate query-string downsampling step). - Decode the "remark" field and treat any non-nil value as a failure so a server-side timeout is retried and logged instead of silently accepted as empty data. - Retry each chunk once with a short backoff before giving up, since the public Overpass instance is a shared, load-dependent resource where a single slow response shouldn't cost that stretch of road its data. Verified the exact query shape and decoder assumptions against the live Overpass API across multiple route shapes (realistic 5km stretch, dense-area chunk, pathological zigzag) -- all resolved in under 8s with correct bus stop / speed limit extraction. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013DNqCsHShA4yNqgZ6ZZQy3
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bus stops still loaded inconsistently after the previous chunking fix (#4) — sometimes working, sometimes not, with no obvious pattern. Investigating against the live Overpass API found two compounding root causes.
Changes
Root cause 1 — query cost scales with point density, not route length. Overpass's
around(radius, point-list)operator costs scale with points-in-list × candidate-elements-in-area. A single chunk at the previouschunkMaxPoints=160reliably timed out. But even much smaller chunks (25-60 points) took anywhere from 3s to 23s purely depending on how road-dense the area was — the same chunk size that was fine in a quiet area could time out in a busy one. That's exactly the "sometimes works, sometimes doesn't" behavior: no fixed point-count chunk size is safe everywhere.Root cause 2 — Overpass server timeouts are silent. When Overpass's own
[timeout:N]elapses, it replies HTTP 200 with an emptyelementsarray and aremarkfield describing the error — not an error status. The client only checked the HTTP status code, so a timed-out chunk was silently indistinguishable from "no stops near this stretch of road," and was never retried or logged.Fixes:
around()query with a bounding-box query per chunk. A bbox test is an O(1) rectangle check per candidate regardless of route shape or point density, unlikearound(). Verified live: a chunk that took 16-23s (or timed out) viaaround()resolved via bbox in 2-8s for the same area — including a deliberately pathological zigzag route whose bbox came out much larger than the route itself.remarkfield and treat any non-nil value as a failure, so a server-side timeout is retried and logged instead of silently accepted as empty data.Testing
around()(now 2-8s via bbox), and a deliberately pathological zigzag route (bbox much larger than the route, still resolved in under 8s).remarkbehavior by intentionally forcing an Overpass timeout and inspecting the response.Screenshots
N/A — backend data-fetching change, no UI changes.
Generated by Claude Code