Skip to content

feat(routes): add per-route max_path_length cap - #321

Merged
jinglemansweep merged 1 commit into
mainfrom
feat/routes-max-path-length
Jul 20, 2026
Merged

feat(routes): add per-route max_path_length cap#321
jinglemansweep merged 1 commit into
mainfrom
feat/routes-max-path-length

Conversation

@jinglemansweep

Copy link
Copy Markdown
Contributor

Summary

Adds a new nullable per-route knob max_path_length that caps the total number of hops in a candidate packet's path. Packets whose path exceeds the cap are dropped from matching consideration entirely (before the subsequence matcher runs), so over-long paths never count toward packet_count_threshold.

Complements the existing max_hop_span, which only constrains the gap between the first and last matched configured node. The new knob constrains the total packet path size and drops over-long packets up front.

Semantics

  • Field name: max_path_length
  • Type: Optional[int] (null = unlimited)
  • Default: null (backwards-compatible — existing routes unchanged)
  • Check: len(hops) > max_path_length → reject, before running the subsequence match

Changes

Data layer

  • Route model: new max_path_length column (nullable Integer, default null)
  • Migration d307ee761a34 (additive, no backfill, zero-downtime)

Matcher (collector/routes.py)

  • Early-return check added to _subsequence_indices; threaded through is_subsequence, _matched_subpath, _matched_subpath_with_indices, _match_hops
  • All 5 call sites updated: evaluate_route, evaluate_route_day, evaluate_route_history, recent_matches, preview_route

API + CLI

  • Schemas: RouteCreate, RouteUpdate, RouteRead, RouteDetail, RoutePreviewRequest
  • API serializer / create / update / preview passthrough
  • CLI seed YAML import (update + create paths)

Frontend

  • Two new dedicated icons: iconHopSpan (<-o->) for max_hop_span, iconPathLength (|⟷|) for max_path_length — distinct from each other and from the generic iconPath
  • Both badges now always render with fallback when null (mirrors observer-count pattern)
  • Hover tooltips added to every stats row item with i18n labels (en + nl)

Tests

  • Matcher unit tests: test_path_length_cap_within, test_path_length_cap_exceeds, test_path_length_cap_zero_ignored
  • API round-trip: test_update_all_scalar_fields extended to PUT max_path_length: 6 and assert round-trip
  • CLI seed import test extended with max_path_length: 12

Verification

pytest --no-cov tests/test_collector/test_routes.py tests/test_api/test_routes.py tests/test_collector/test_cli.py
# 163 passed
pre-commit run --all-files  # all green

Out of scope

  • No cache invalidation changes (invalidate_routes already covers all route mutations)
  • No configuration.md change (per-route DB field, not env var)
  • No data backfill (column is nullable, defaults null = unlimited)
  • Migration is additive and backwards-compatible with running collectors

Adds a new nullable per-route knob that caps the total number of hops
in a candidate packet's path. Packets whose path exceeds the cap are
dropped from matching consideration entirely (before the subsequence
matcher runs), so over-long paths never count toward
packet_count_threshold. Complements the existing max_hop_span, which
only constrains the gap between the first and last matched configured
node.

- Route model + migration (additive, nullable, default null = unlimited)
- Threaded through matcher chain (_subsequence_indices early-return)
- All 5 evaluate/preview/recent_matches call sites updated
- API serializer/create/update/preview passthrough
- CLI seed YAML import (update + create paths)
- Frontend: distinct icons for span (<-o->) vs path-length (|<->|),
  always-rendered badges with infinity fallback, hover tooltips on
  every stats row item, i18n keys (en + nl)
- Tests: matcher unit tests (within/exceeds cap), API round-trip,
  CLI seed import
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.00000% with 3 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/meshcore_hub/collector/routes.py 72.72% 0 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@jinglemansweep
jinglemansweep merged commit 53c1b36 into main Jul 20, 2026
4 checks passed
@jinglemansweep
jinglemansweep deleted the feat/routes-max-path-length branch July 20, 2026 11:51
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