fix(loop-generator): familiarity uses actor id (#75), dedupe candidates (#76) #77

Merged
maximus merged 2 commits from fix/75-76-loop-gen into deploy 2026-11-06 13:18:18 +00:00
Member

Fixes #75, fixes #76. Two loop-generator bugs found by the #73 browser acceptance run.

#75: Familiarity never finds the user's own trails

Root cause: activityTracksNear (web/src/lib/stores/activity_tracks_store.ts) filtered the Meilisearch trails index with author = "<user.id>". The index stores author as the ActivityPub actor id (documentFromTrailRecord in db/util/meilisearch.go writes author.Id of the expanded activitypub_actors record), so the search always returned 0 hits and the familiarity/novelty bias was never applied.

Fix: filter by $currentUser.actor, the same way the other own-trail searches do (routes/lists/edit/[id]/+page.svelte, trail_dropdown.svelte, trail/edit/[id]/+page.ts). If the user has no actor id, return [] without querying. The "completed", "planned" and "both" sources share this author clause (they only add completed = true/false, which is a filterable index field), so all three are fixed.

Tests: the store tests now set an actor id distinct from the user id, assert author = "<actor>" for completed, planned and both, assert the user id is not in the filter, and add a no-actor case that does not call fetch.

#76: Identical candidates listed twice

Root cause: generateLoops (web/src/lib/routing/generator.ts) keeps one survivor per rotation and never compared survivors. With a must-visit point or a constrained network, several rotations snap to the same ways and come back as the same route.

Fix: after the gates and the score sort, dedupeCandidates drops any candidate that isSameLoop matches against a candidate already kept, so the best-scored copy survives and the order stays the same. Two loops are the same when:

  • distance agrees within max(25 m, 0.5 %) and D+ within max(5 m, 2 %) (a cheap pre-check), and
  • at least 95 % of each geometry, resampled every 10 m, lies within 25 m of the other.

Resampling means long straight segments with few vertices still count by length. The overlap check ignores direction, so the same loop walked the other way round also counts as a duplicate, since it has the same distance and D+ and looks identical on the map. Routes without geometry are never treated as duplicates.

Tests: isSameLoop covers identical, resampled, reversed and near-identical routes (match), a mirrored loop with identical numbers and a distance/D+ outside the tolerance (no match), and empty geometry. dedupeCandidates keeps the first copy and the order. Two generateLoops cases use a port where every rotation snaps to one loop (expect 1 candidate) or to two different loops (expect 2).

Verification

  • vitest run (full web unit suite): 1275 passed, 13 skipped
  • The new and changed tests fail on the old code (5 failures) and pass with the fix
  • npm run check: 0 errors (the 2 warnings are already in trail/edit/[id]/+page.svelte)

Not merged and no image built. Test it on the preview environment first.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP

Fixes #75, fixes #76. Two loop-generator bugs found by the #73 browser acceptance run. ## #75: Familiarity never finds the user's own trails **Root cause:** `activityTracksNear` (`web/src/lib/stores/activity_tracks_store.ts`) filtered the Meilisearch `trails` index with `author = "<user.id>"`. The index stores `author` as the ActivityPub actor id (`documentFromTrailRecord` in `db/util/meilisearch.go` writes `author.Id` of the expanded `activitypub_actors` record), so the search always returned 0 hits and the familiarity/novelty bias was never applied. **Fix:** filter by `$currentUser.actor`, the same way the other own-trail searches do (`routes/lists/edit/[id]/+page.svelte`, `trail_dropdown.svelte`, `trail/edit/[id]/+page.ts`). If the user has no actor id, return `[]` without querying. The "completed", "planned" and "both" sources share this author clause (they only add `completed = true/false`, which is a filterable index field), so all three are fixed. **Tests:** the store tests now set an actor id distinct from the user id, assert `author = "<actor>"` for completed, planned and both, assert the user id is not in the filter, and add a no-actor case that does not call fetch. ## #76: Identical candidates listed twice **Root cause:** `generateLoops` (`web/src/lib/routing/generator.ts`) keeps one survivor per rotation and never compared survivors. With a must-visit point or a constrained network, several rotations snap to the same ways and come back as the same route. **Fix:** after the gates and the score sort, `dedupeCandidates` drops any candidate that `isSameLoop` matches against a candidate already kept, so the best-scored copy survives and the order stays the same. Two loops are the same when: - distance agrees within max(25 m, 0.5 %) and D+ within max(5 m, 2 %) (a cheap pre-check), and - at least 95 % of each geometry, resampled every 10 m, lies within 25 m of the other. Resampling means long straight segments with few vertices still count by length. The overlap check ignores direction, so the same loop walked the other way round also counts as a duplicate, since it has the same distance and D+ and looks identical on the map. Routes without geometry are never treated as duplicates. **Tests:** `isSameLoop` covers identical, resampled, reversed and near-identical routes (match), a mirrored loop with identical numbers and a distance/D+ outside the tolerance (no match), and empty geometry. `dedupeCandidates` keeps the first copy and the order. Two `generateLoops` cases use a port where every rotation snaps to one loop (expect 1 candidate) or to two different loops (expect 2). ## Verification - `vitest run` (full web unit suite): 1275 passed, 13 skipped - The new and changed tests fail on the old code (5 failures) and pass with the fix - `npm run check`: 0 errors (the 2 warnings are already in `trail/edit/[id]/+page.svelte`) Not merged and no image built. Test it on the preview environment first. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP
The trails index stores `author` as the ActivityPub actor id, but
activityTracksNear filtered by the user record id, so "find my nearby
trails" never matched and familiarity/novelty bias was never applied.
Filter by currentUser.actor like the other own-trail searches, and
return [] without querying when the user has no actor id. The completed
and planned sources share the same filter, so both are fixed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP
fix(loop-generator): drop duplicate loop candidates (#76)
All checks were successful
CI / web (push) Successful in 1m22s
CI / go (push) Successful in 15m46s
e5a57df822
With a must-visit point or a constrained network, several rotations
snap to the same ways and the generator listed the same loop more than
once. After ranking, drop candidates whose distance and D+ match an
earlier one within a small tolerance and whose resampled geometries
overlap at least 95 % in both directions, keeping the best-scored copy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XMf4EGfBC9xbQ6rjD6HxgP
maximus merged commit e5a57df822 into deploy 2026-11-06 13:18:18 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
public/wanderer!77
No description provided.