My Map Thought Kansas Drives on the Left
What I saw on the drive
On the morning of October 10 I drove with my own navigation app on CarPlay. I build it myself: a phone app, a server, and a self-hosted Valhalla routing engine on OpenStreetMap data for Kansas and Oregon.
Afterward I sent in photos with three notes. The second said "the roundabout icons are shown as if we are driving on the left side of the road rather than the right."
Later that morning I got more specific. At a perfectly perpendicular four-way roundabout, where I needed the third exit, the icon drew a bold line going clockwise and off at the first exit.
I thought that was one bug. There were two, in two different layers, and they happened to point the same way.
The arc ran the wrong way
The phone draws the roundabout icon as SVG. The car draws it with Core Graphics. Both have to know which way traffic goes around the ring, and in the US that's counterclockwise on screen.
The two APIs spell that direction in opposite terms, and they're both right. SVG's sweep flag is defined in screen space, where y points down. CGContext.addArc defines clockwise in Core Graphics' own space, where y points up. On UIKit's y-down canvas, right-hand traffic needs clockwise: true.
The car had been passing false since September 5. Every roundabout on the car went around for left-hand traffic. My phone was right the whole time.
I had the fix in by 10:08 that morning. A probe on a Mac Catalyst build sampled the drawn ring: 252 of 252 samples were wrong before, 0 after. A test now pins the corrected line.
The number was wrong too
Fixing the arc didn't touch the numeral. That came from Valhalla, and at my roundabout it said "take the 2nd exit" for every arm pair. Right turn, straight through, left turn: all 12 pairs said 2nd.
So I had Claude ask Valhalla what it thought those roads were. Its trace_attributes answer reported drive_on_right: false on all 3,239 ring edges it walked at the roundabouts it sampled in Kansas and Oregon, and a country of "None". The admin database had one row. It was Kansas, as a state, with no parent country. Oregon wasn't in it at all.
The tiles are built from per-state OpenStreetMap extracts, and the Docker image builds its admin database from the same files. A state extract can't carry the whole US border. With no country, my map read every road as left-hand traffic. Valhalla counts exits on the drive side, so it was counting around the inside of the ring.
To size it, Claude surveyed 100 roundabouts and every arm pair through them: 1,039 routes. Valhalla said "2nd exit" on 1,022 of them, 3rd on 12, and 1st on 5.
Then a proof on a throwaway graph, without touching the live tiles. Same roads, plus one synthetic "United States" boundary. Every edge flipped to drive_on_right: true, and Valhalla said 1st, 2nd and 3rd at my roundabout, in the count and in the spoken instruction.
Two fixes, a day apart
The quick fix shipped at 12:38 the same day. It's server-side, so I didn't need a phone install. The server counted the exits itself off the route's own edge walk: one, plus every road you could drive away from the ring between where you enter and where you leave.
On the survey it agreed with the corrected graph on 1,019 of 1,031 comparable routes. The 12 misses are all one circle in Bend, where it reads one high. It only kicks in where the ring says drive_on_right: false, so it'll step aside once the map's fixed. On prod at 12:45 it read left 3rd, straight 2nd, right 1st.
The real fix was rebuilding my map with a country. My answer was "Yes: rebuild with a country, local first, then prod in a quiet window." The local graph was rebuilt that afternoon. Every edge read drive_on_right: true, the server suite passed 1,037 of 1,037 on it, and the edge ids held.
I had a second choice to make inside that one. With a country, Valhalla would also start using its US speed rows. That variant cut raw route times by 13 to 35% and broke 3 district-tour tests. I said "Keep today's speeds now (variant A)" and left the speed table for later, as its own change.
Prod went on October 11, from 17:41 to 17:46. Routing was down about 3.6 minutes. Afterward Valhalla said "3rd exit" at my roundabout by itself. My drive history is stored against the graph's road pieces, so it had to be remapped: 1,270 of 1,272 moved over, and 2 were orphaned. The old files are still kept on the volume for rollback.
Why no test caught it
The wrong count was in the repo's notes more than a month earlier. On September 4, an investigation of exit angles at three roundabouts in Bend recorded all three as "take the 2nd exit". One was a hard left. One was about a 70 degree right. One was a U-turn through the circle.
Three very different moves with the same exit number should've been a flag. The note read it as a finding: "Exit COUNT and exit ANGLE are independent quantities." That sentence is true. Those three just weren't examples of it. The real exits were 3rd, 1st and 4th.
Then the wrong answers became fixtures. A snapshot test was titled "the three Bend '2nd exit' fixtures". A CarPlay test fed in "Take the 2nd exit" with an angle of -94°, which is a hard left. Every fixture came from the same graph, so every test agreed with the graph.
A test built from the data can't see a default that's wrong on every row of it. What it needed was one fact from the street: in right-hand traffic, a left at a perpendicular four-way roundabout is the 3rd exit. The new server test asserts that, in the count, the card text and the voice.
What's still open
The car's arc fix is proven by a probe and a simulator pass, but I haven't photographed it on my head unit yet. The roadmap still owes one, plus a drive where the number comes straight from Valhalla with no server rewrite.
A November 18 replay run couldn't check exit numbers against ground truth. It flagged one suspect, a "5th exit" at -94° in downtown Bend.
The drive side also feeds Valhalla's turn costs, so the old graph probably priced turns as if traffic drove on the left. Only small time differences were measured, 0.05 to 0.75 seconds on short test routes. That mechanism is an assumption, not a finding.
Until my next drive, it's proven on the server and in the simulator, and not yet at a real roundabout.
-- Justin Higgins. Software Engineer, Midwest. Drove a roundabout his own app was counting from the wrong side.
Companion pieces: Twelve Days of Green Tests - a core test that passed for twelve days by checking code against itself. The Unearned Constraint - the biggest choice in the same CarPlay app, which nobody had made.
Reactions, disagreements, war stories: jchigg2000.dev@gmail.com