Skip to content

Fix inconsistent bus stop loading: switch route queries from around() to bbox#5

Merged
dizzafizza merged 1 commit into
mainfrom
claude/fork-code-review-33fkom
Jul 15, 2026
Merged

Fix inconsistent bus stop loading: switch route queries from around() to bbox#5
dizzafizza merged 1 commit into
mainfrom
claude/fork-code-review-33fkom

Conversation

@dizzafizza

Copy link
Copy Markdown
Owner

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 previous chunkMaxPoints=160 reliably 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 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 was 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 needed).
  • 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.

Testing

  • Verified the exact query shape and decoder assumptions against the live Overpass API across multiple route shapes: a realistic ~5km stretch (2.6s, correct bus stops/speeds decoded), a dense-area chunk that previously took 16-23s via around() (now 2-8s via bbox), and a deliberately pathological zigzag route (bbox much larger than the route, still resolved in under 8s).
  • Confirmed the exact server-side timeout/remark behavior by intentionally forcing an Overpass timeout and inspecting the response.
  • Confirmed the change compiles and archives successfully via the Build Debug IPA CI workflow on this branch.
  • Tested on device
  • Tested with fresh pairing file

Screenshots

N/A — backend data-fetching change, no UI changes.


Generated by Claude Code

… 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
@dizzafizza
dizzafizza merged commit 15ca7d4 into main Jul 15, 2026
2 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.

2 participants