Files
meshcore-analyzer/cmd/server
Kpa-clawbot d667dc0a74 fix(#1278): /api/nodes/{pk}/paths uses canonical persisted resolved_path (drop anchor-bias inconsistency) (#1282)
First failing (RED) commit: c994c5a7 — CI:
https://github.com/Kpa-clawbot/CoreScope/actions

Fixes #1278.

## Root cause
`handleNodePaths` (`cmd/server/routes.go`) anchored the disambiguator
with the queried node as `hopContext` (`hopContext :=
[]string{lowerPK}`). For ambiguous short-prefix hops (e.g. two nodes
sharing the 1-byte prefix `C0`), tier-1/2 hop-context resolution then
biased the resolver to pick the queried node — even though the CANONICAL
persisted `resolved_path` (what `/api/packets/{hash}` shows via
`fetchResolvedPathForTxBest`) had picked the OTHER colliding node at
ingest time. The `containsTarget` gate accepted those packets and
rendered the queried node into the displayed hop, while the packets page
(reading the canonical resolved_path) showed a different node. The two
pages disagreed.

Confirmed on staging: `/api/nodes/c0dedad…/paths` returned `sampleHash
6c4af39ee4b7e202`; `/api/packets/6c4af39ee4b7e202.resolved_path[3]` =
`c0ffeec7…`, not `c0dedad…`.

## Option chosen — A
For each candidate tx, read the canonical persisted `resolved_path` via
`fetchResolvedPathForTxBest`. When present, use it for BOTH:
- the `containsTarget` membership decision (queried pubkey must appear
in the canonical resolved hops), and
- the displayed hop names (zipped parallel to `tx.PathJSON`).

When absent (older data / async backfill not yet complete) the legacy
biased re-resolve is kept as a fallback — there's no canonical answer to
be consistent with, and dropping the bias unconditionally would regress
#1197.

## Why not B / C
- **B** (drop bias only for membership): still re-resolves display with
bias → display vs packets page can still diverge for hop names. Option A
fixes both.
- **C** (drop `hopContext` entirely): regresses #1197 / breaks the
`resolve_context_callsites_test.go` gate.

## Performance
Same O(N) walk over candidates; one extra `fetchResolvedPathForTxBest`
per candidate, LRU-cached, worst case a single SQL row.

## Tests
- RED: `cmd/server/paths_anchor_bias_test.go` — seeds two `c0…` nodes +
a tx whose best-obs resolved_path picks the GPS node; asserts the no-GPS
node's `/paths` excludes the tx and the GPS node's includes it.
Mutation-verified (fails on master).
- All existing tests green (including #1197 callsite gate and #929
prefix-collision exclusion).

---------

Co-authored-by: corescope-bot <bot@corescope>
2026-05-18 23:19:30 -07:00
..