Skip to content

Planner: route long plans two requests at a time, and keep the trip when one point or leg fails #3709

Closed

Description

@timohueser

Status: done

Part of #3652 (step 1). Read the epic first: its Facts on routing and "The screen" (the points about no_snap and no_path).

TL;DR

Goal: A long plan routes with two requests at a time, a point far from a road is left out with a note, a leg with no legal path becomes a remembered gap, and a line with a gap never goes to the bike computer.
Problem: The route requests of a long plan go one after the other (9.2 s for the 64-day cycling test plan), and one point that the service cannot reach, or one leg with no legal path, gives no line at all.
Decision: At most 2 requests in flight; joins checked after the answers; the service names the bad point or leg in its error answer; the leg cache passes the index on; calculateLine drops a no_snap point and makes a no_path leg a cached gap leg; today's sync refuses a line with a gap leg.
Systems: route-planning, routing, web-planner
Contracts: specs/route-api.md Errors (fields point and leg)
Size: M (3 systems, a compatible contract change, about 550 lines)

Facts

  • LegCache.route (builder/web/src/lib/planner/route-legs.ts:81-127) sends the chunks of a gap one after the other, each pinned to the end of the chunk before. On a failed join it clears the whole cache and starts again (:105-109, meant for a new routing package). On no_path under a pin it widens the chunk by one leg on each side, then sends the whole run again (:113-123).

  • post (routing.ts:100-115), which requestRoute (:136-138) calls, throws an error with the service's code only.

  • calculateLine (routing.ts:182-) builds an expanded point list for each run of routed legs: a detour adds 3 points (anchor, place, anchor) and a turnaround (routing.ts:247-251); ends maps the index of the leg that ends at a plan point to that point ids.

  • gapNote (route-gaps.ts:30-40) gives, for one point: "Route starts ‹d› from the selected point", "Route ends ‹d› before the selected point" or "Route passes ‹d› from the selected point", each followed by " — no accessible path"; for several points "Route misses ‹n› selected points by up to ‹d› — no accessible path". The note row has no Show button (PlannerApp.svelte:1224-1226).

  • unknownElevationKm > 0 hides the ascent (PlannerApp.svelte:1222, DayRow.svelte:55); unroutedKm > 0 drops the riding times from search requests (search/plan.ts:39).

  • Error::NoPath is used at planner/router/src/router.rs:304, :309, :315, planner/router/src/alternatives.rs:49, :112 and planner/router-build/tests/routing.rs:287.

  • Measurement (throwaway edit: only the two-at-a-time change of this issue, plus the profile slice edit that changes memory and not routing; 64-day cycling test plan, search off, 3 loads each, terrain run active, load average 5 to 8):

    Route requests From the first route request to the last answer Requests Map quiet
    One after the other, as today 9.2 s (8.4, 9.2, 9.4) 6 21.1 s
    Two at a time, bad joins sent again 5.1 s (4.9, 5.1, 6.2) 9 14.4 s

    3 of the 5 joins between chunks landed on another road position in every load and went out again. The rest of the time to a quiet map is the night search of every night, which Planner: a strip of all days and a week in focus for trips of 15 days or more #3712 limits to the week.

Plan

  1. Service. planner/router/src/lib.rs:40: Error::NoPath becomes NoPath(usize), the leg index in the request: set it in the leg loop of router.rs:303-304 (the loop takes one leg a step), at :309 the last leg, and at :315 the leg index that the loop there knows. The other matches take NoPath(_) (alternatives.rs:49, :112, router-build/tests/routing.rs:287). planner/service/src/lib.rs (error_body): the no_snap answer gets "point": <index from 0>, the no_path answer "leg": <index from 0>. specs/route-api.md Errors: "An error answer is {"code", "message"}; a no_snap answer also has point, the index of the point, from 0; a no_path answer also has leg, the index of the leg from 0, between point leg and leg + 1."
  2. post (routing.ts:115): the thrown error also carries point and leg from the body.
  3. LegCache.route (route-legs.ts):
    • The chunks of a gap go out with at most 2 requests in flight. The first chunk is pinned to the cached leg before it, the last to the cached leg after it; chunks between are not pinned. Each answer is kept in the cache as it arrives. When a request fails, no new chunk starts; the one in flight finishes and is kept; then the error goes up. An abort (the rider edits) stops both; kept answers stay for the next calculation.
    • After the answers, the join check (:87) runs over the gap again: a leg that does not join its neighbour becomes missing and goes out as a one-leg request pinned at both ends. The cache restarts from empty only when a new answer has another package than its neighbour (:105); a join that fails with the same package is such a re-request, never a restart.
    • An error with point or leg goes up with the index changed to an index into points (the chunk's from added). no_path on the first leg of a chunk pinned at its start, or the last leg of a chunk pinned at its end, goes out once more without that pin (one leg wider on that side); if it fails again, the error goes up. The whole-run fallback (whole = true) goes.
    • A gap leg is cached like a routed leg (gap: true, a straight geometry from its start to its end point, no heights, no edges, 0 s, no package). It joins any neighbour, and a neighbour of a gap leg is not pinned to it. So later edits elsewhere send no request for it; a move of one of its two points changes its key and routes it again.
  4. calculateLine (routing.ts):
    • no_snap at expanded index i: the plan point of i (through ends, or the place of a detour) goes into a set of left-out points, and the run is built and routed again without it; turnaround indexes are counted again on the new list. When the point is a start or a finish, or the end of a run beside a drawn or transfer leg (a drawn leg must keep its join), it is not left out: the routed legs at it become gap legs. A detour whose place fails is left out as a whole (anchor, place, anchor). The line lists the left-out points; routeGaps measures the miss from the line to each.
    • no_path at leg k: that leg is a gap leg in the cache (above), and the run routes again around it.
    • RoutingLine gets gapLegs: string[]: the ids of the plan points at which a gap leg ends (as legEndId). daySegments gives these segments leg: 'gap'; the map draws them with trip-gap (PlannerMap.svelte:270).
    • A gap leg's straight length counts in the distance (append measures its geometry); it adds no time and no climb, and it does not count in unroutedKm, unknownSurfaceKm or unknownElevationKm. So the distance holds the gap as a straight line, the time and the climb hold only the routed parts, the climb stays visible, and search keeps its times. That is honest: the note says a part is missing and how it is counted.
  5. Notes (route-gaps.ts, the note row at PlannerApp.svelte:1224-1226): a left-out point gives today's gapNote text ("Route passes 1.2 km from the selected point — no accessible path"). A gap leg gives "No legal path between 2 points" (several: "2 legs have no legal path"). The row gets Show / Next / Hide as the closure rows (showNext), stepping through the points and gap legs. On planner: less text, clear controls, a night picker that follows the stay kinds, no route alternatives (#3286) #3338 the row goes into the list of things to check.
  6. Sync (device-sync/sync.ts, after calculateLine, :126): a line with gapLegs.length > 0 does not go; the plan stays in waiting; problem gets "“‹name›” waits: 1 leg has no legal path. Change it in the planner." (plural "‹n› legs have"). A left-out point does not block: the line is complete without it.
  7. Comment at gpx-import.ts:50: the import shapes lines one at a time; a page routes with two requests at a time, which the service takes because a request waits up to 1 s for a worker before busy (planner/service/src/http.rs:24).

Tests

builder/web/src/lib/planner/routing.test.ts:

  • Replace "sends the chunks one after the other, each pinned to the end of the chunk before" (:252) with: two chunks are in flight at once; a bad join goes out again as one leg pinned at both ends; a join with another package restarts once.
  • Replace "sends a gap without a path again with one more leg on each side, not the whole run" (:288) and "fails a run without cached legs after the widened request, not after the whole run again" (:314) with: a no_path leg in the middle becomes a gap at once; a second calculation after an edit elsewhere sends no request for it.
  • Replace "sends a chunk without a path under the pin of the chunk before again from one leg earlier" (:303-312, it pins chunk 2 to chunk 1, which no longer happens) with: a first chunk, pinned to a cached leg before it, that fails with no_path on its first leg goes out once more one leg wider without that pin; if that fails too, the leg is a gap.
  • Change "keeps each chunk as it arrives; a failure or an abort stops the chunks after it" (:334): with two in flight, the answer in flight is kept and no new chunk starts.
  • New: a no_snap shaping point is left out and listed; a no_snap detour place leaves out the detour; a no_snap point beside a drawn leg gives gap legs.
    builder/web/src/lib/device-sync/sync.test.ts: a plan whose line has a gap leg waits, with the sentence.
    planner/service/src/lib.rs tests: the no_snap body has point, the no_path body has leg.

Proof

The speed run of this change alone:

  • Setup on the build PC, in /media/timo/OSM1/tmp/explore-3506/long-trips-design/tools/: run.sh (local route service with 2 workers, the catalogue proxy with search off, the vite page of the worktree in W) and speed.mjs (3 loads of the stored 64-day cycling plan bike-64.json at 1920 × 1080; it writes routeMs, from the first route request to the last answer, and the request count). In your worktree only, never committed, add by hand three of the four edits that exp.py describes (not the night edit, which belongs to Planner: a strip of all days and a week in focus for trips of 15 days or more #3712): maxRidingDays = 64, the obc:idle mark in PlannerMap.svelte, and the profile slice edit of exp-profile.py (memory only). Run obc suites prepare in the worktree first. Do not run exp.py in a worktree with your change: it resets builder/web/src first.
  • Command: /media/timo/OSM1/tmp/explore-3506/tools/heavy.sh $T env W=<your worktree> $T/run.sh "flock /tmp/trailview-gpu.lock timeout 280 tools/obc exec node $T/speed.mjs step1 bike-64 64 3" with T the tools folder. Say in the pull request whether the terrain run was active and the load average.
  • Pass: median routeMs 6.0 s or less (today 9.2 s; the experiment gave 5.1 s). Re-requested joins = requests − 6; write the three times and that count into the pull request.

Checks

  • obc test -p planner-router, obc test -p planner-router-build, obc test -p planner-service, and obc exec cargo clippy -p <crate> --all-targets -- -D warnings for each.
  • In builder/web: npx vitest run src/lib/planner/routing.test.ts src/lib/planner/route-gaps.test.ts src/lib/device-sync/sync.test.ts, then npm run check.

Limits

  • The Route page (pages/Route.svelte:89) and the signed-route page (Signed.svelte:135) show a gap leg as a plain line with no note; their GPX and FIT export write it as a straight segment.
  • A plan with a gap counts the gap's straight length in its distance, and no time and no climb for it.

Done when

  • The checks pass, and the proof is in the pull request.
  • The owner's check runs on the pull request's head, served on the build PC as in the Proof setup (the vite page of the worktree with the local route service; the orchestrator gives him the address). He opens the 32-day cycling test plan: pass when its line shows (the speed is the measured proof above, not his check). He opens a copy with one shaping point moved 2 km away from any road and one leg between two points with no legal path (for example a point on the other side of a lake with no road around it, or a point on a motorway for the hiking profile): pass when the route goes past the first point with the note "Route passes 2.0 km from the selected point — no accessible path" (about that distance) and Show moves the map there, and the leg is a dashed straight line with the note "No legal path between 2 points"; fail when the line is missing or the whole plan says it cannot route.

Public docs: no change.

Activity

  1. timohueser commented on Nov 19, 2026

    @timohueser
    OwnerAuthor

    The owner's check passed on the sheet of the built planner (the 32-day plan with its whole line, the point 2 km off the roads with its note and Show, the leg with no legal path as a dashed line): "Yes, merge it".


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions