Skip to content

feat(facts): add PairwiseLinkMatrix for directional network topology - #266

Merged
toasterbook88 merged 3 commits into
mainfrom
feat/pairwise-link-matrix
Jul 27, 2026
Merged

feat(facts): add PairwiseLinkMatrix for directional network topology#266
toasterbook88 merged 3 commits into
mainfrom
feat/pairwise-link-matrix

Conversation

@toasterbook88

Copy link
Copy Markdown
Owner

Summary

Fills the 1B gap from the v0.14.7 optimization spec audit: the spec described a `PairwiseLinkMatrix` / `LinkMetric` data structure that did not exist anywhere in the codebase. This adds it for real — a first cut that measures what's actually measurable from a single vantage.

Types (`internal/models/types.go`)

```go
type PairwiseLinkMatrix struct {
Links []LinkMetric
}
type LinkMetric struct {
SourceNode string
TargetNode string
OverlayType string // lan | tailscale | thunderbolt
RTTLatencyP95 time.Duration
ThroughputMBps float64 // 0 = unmeasured in this cut
}
```
`ClusterSnapshot` gains an optional `Topology *PairwiseLinkMatrix` field (zero-value-safe; existing consumers unaffected).

Builder (`internal/facts/pairwise.go`)

`BuildPairwiseLinkMatrix(ctx, localName, nodes)`:

  • Probes directional RTT from the local node to each remote node's `ResolvedDialTarget` (fallback `SSHTarget`) via `ping -c 4 -W 1`.
  • Parses the max RTT from the ping summary line as a P95 stand-in (4 samples).
  • Infers overlay from address shape: `100.` → `tailscale`, `169.254.` → `thunderbolt`, else `lan`.
  • Single-vantage model: only local→remote is probed; cross-remote edges are not measured. Throughput left at 0 (unmeasured) in this first cut — RTT is the primary signal.
  • Best-effort: unreachable nodes or missing `ping` are omitted, not fatal. No-local-node returns an empty matrix.

`TopologySummary(m)` helper for logging.

Verification

Check Result
`TestParseRTTP95` (linux summary / no-summary / malformed) PASS
`TestInferOverlay` (tailscale / thunderbolt / lan / 10.x / hostname) PASS
`TestBuildPairwiseLinkMatrixNoLocalNode` PASS — empty matrix, no panic
`TestBuildPairwiseLinkMatrixSkipsLocalAndEmptyTargets` PASS — self + empty skipped
`TestTopologySummaryEmpty` / `NonEmpty` PASS
`TestBuildPairwiseLinkMatrixLiveOnCranium` (loopback) PASS — captured `cranium→loopback-target lan 27µs`
Full `internal/facts` + `internal/models` suites PASS
`go build ./...` clean

Scope notes

  • This is a first cut: throughput is unmeasured, and only local→remote edges are probed. Cross-remote measurement would require distributed probing (each node probing the others) — out of scope for a single-PR addition, and the spec didn't require it.
  • The builder is not yet wired into the snapshot pipeline — it's available for callers but `ClusterSnapshot.Topology` stays nil by default. Wiring it into `axis status` / daemon refresh is a deliberate follow-up so this PR stays focused on the type + builder.

Related

Follows #264 (MCP tools, 4B) and #265 (local VRAM sampling, 1A). Completes the three real gaps flagged in the spec audit.

Fills the 1B gap from the v0.14.7 optimization spec audit: the spec
described a PairwiseLinkMatrix / LinkMetric data structure that did not
exist anywhere in the codebase. This adds it for real.

Types (internal/models/types.go):
- PairwiseLinkMatrix{ Links []LinkMetric }
- LinkMetric{ SourceNode, TargetNode, OverlayType, RTTLatencyP95, ThroughputMBps }
- ClusterSnapshot gains an optional Topology *PairwiseLinkMatrix field.

Builder (internal/facts/pairwise.go):
- BuildPairwiseLinkMatrix probes directional RTT from the local node to
  each remote node's ResolvedDialTarget (fallback SSHTarget) via ICMP ping,
  parses the max RTT from the ping summary as a P95 stand-in, and infers
  the overlay from the address shape (100.* → tailscale, 169.254.* →
  thunderbolt, else lan).
- Single-vantage model: only local→remote is probed; cross-remote edges
  are not measured. Throughput left at 0 (unmeasured) in this first cut.
- Best-effort: unreachable nodes or missing ping are omitted, not fatal.
- TopologySummary helper for logging.

Verified:
- Unit tests: parseRTTP95 (3 cases), inferOverlay (5 cases), no-local-node
  edge case, skip-local-self + skip-empty-target, TopologySummary empty/
  non-empty. All pass.
- Live smoke test on cranium: cranium→loopback-target lan 27µs captured
  end-to-end via real ping.
- Full facts + models suites pass; go build ./... clean.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@toasterbook88
toasterbook88 merged commit 5a661b9 into main Jul 27, 2026
7 checks passed
@toasterbook88
toasterbook88 deleted the feat/pairwise-link-matrix branch July 27, 2026 19:20
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.

1 participant