Skip to content

fix(meshcore): honor packet-monitor Max count setting in the live list (#3690)#3693

Merged
Yeraze merged 1 commit into
mainfrom
fix/meshcore-packet-monitor-maxcount-3690
Jun 24, 2026
Merged

fix(meshcore): honor packet-monitor Max count setting in the live list (#3690)#3693
Yeraze merged 1 commit into
mainfrom
fix/meshcore-packet-monitor-maxcount-3690

Conversation

@Yeraze

@Yeraze Yeraze commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Root cause

The MeshCore Packet Monitor live-list endpoint GET /api/sources/:id/meshcore/packets ignored the user-configured meshcore_packet_log_max_count setting. It applied a hard-coded default limit of 100, clamped only by MESHCORE_PACKET_MAX_LIMIT (1000), against whatever limit the client sent. The frontend always sent limit=200 (PAGE_LIMIT), so the monitor showed at most ~200 packets regardless of the configured Max count.

The export endpoint (GET .../packets/export) already read meshcorePacketLogService.getMaxCount() and used it as the query limit — so the two endpoints behaved inconsistently, and the live monitor never honored the setting users could change in the UI.

Fix

  • List endpoint (server, authoritative): now reads meshcorePacketLogService.getMaxCount() and uses it as the effective query limit when the client does not supply an explicit ?limit, mirroring the export endpoint precisely. An explicit, smaller client-supplied limit still wins so a caller can request fewer rows; both are clamped by the MESHCORE_PACKET_MAX_LIMIT ceiling (1000). The previously-fetched maxCount in the response Promise.all was deduplicated into the new single read.
  • Frontend view: MeshCorePacketMonitorView.tsx no longer hard-codes limit=200 on load, so the server-side setting governs the page size. The unused PAGE_LIMIT constant was removed; the live MAX_BUFFER (2000) cap is unchanged.

The setting-read mirrors export exactly:

const maxCount = await meshcorePacketLogService.getMaxCount();

(getMaxCount() reads the global meshcore_packet_log_max_count setting via databaseService.getSettingAsync, defaulting to DEFAULT_MAX_COUNT when unset/invalid.)

Tests

Added a GET .../packets (list) describe block in meshcoreRoutes.test.ts asserting the list endpoint:

  • queries with limit: 500 when getMaxCount() returns 500 (no explicit client limit),
  • clamps a configured max count of 5000 down to the 1000 ceiling,
  • honors an explicit smaller client-supplied limit=50.

Full Vitest suite: 7373 passed, 0 failed, 0 failed suites (success: true). tsc --noEmit reports no new errors in the touched files.

🤖 Generated with Claude Code

#3690)

The MeshCore Packet Monitor list endpoint
(GET /api/sources/:id/meshcore/packets) ignored the user-configured
meshcore_packet_log_max_count setting. It used a hard-coded default
limit of 100, clamped only by MESHCORE_PACKET_MAX_LIMIT (1000), so the
monitor showed at most ~200 rows (the client's PAGE_LIMIT) regardless of
the configured retention cap. The export endpoint already read
getMaxCount() correctly, producing inconsistent behavior.

Fix: the list endpoint now reads meshcorePacketLogService.getMaxCount()
and uses it as the effective query limit when the client does not supply
an explicit ?limit, mirroring the export endpoint exactly. An explicit
smaller client-supplied limit still wins; both are clamped by the
MESHCORE_PACKET_MAX_LIMIT ceiling. The frontend view no longer hard-codes
limit=200 on load, so the server-side setting governs.

Adds list-endpoint tests asserting: the configured max count (500) is
used as the limit, the cap is clamped to 1000, and an explicit smaller
client limit (50) is honored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VBLhGGNh35oMwTL53va1Y5
@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown

Claude finished @Yeraze's task —— View job


PR Review: fix(meshcore): honor packet-monitor Max count setting in the live list

Tasks:

  • Gather context and understand the PR
  • Review meshcoreRoutes.ts changes
  • Review MeshCorePacketMonitorView.tsx changes
  • Review meshcoreRoutes.test.ts changes
  • Post final review feedback

Summary

Clean, targeted fix that resolves the inconsistency between the list and export endpoints. The approach is sound and the test coverage is appropriate. A few observations below.


Code Quality

meshcoreRoutes.ts (lines 3281–3284)

The logic is correct, but there's a subtle edge case worth noting: if a client passes ?limit=900 when getMaxCount() returns 500, the explicit client limit (900) wins and the user would see more rows than their configured max. The comment says "An explicit, smaller client-supplied limit still wins" — but the implementation doesn't enforce smaller; any positive finite value wins. This means:

const effectiveLimit = Number.isFinite(requestedLimit) && requestedLimit > 0 ? requestedLimit : maxCount;

...could return up to MESHCORE_PACKET_MAX_LIMIT (1000) even when the user set maxCount to 100. Since the frontend now doesn't send an explicit limit, this isn't an issue in practice, but it's a behavior gap between the comment and the code. Suggest either:

  • Updating the comment to reflect the actual behavior, or
  • Using Math.min(requestedLimit, maxCount) as the effective limit when a client limit is supplied.

meshcoreRoutes.tsgetMaxCount() deduplication

The PR description mentions deduplication of the maxCount fetch. Confirmed: the new code reads maxCount once at the top and uses it in both the query and the response envelope (line 3307). No duplicate await needed.

MeshCorePacketMonitorView.tsx

The load callback (lines 87–108) is clean. The URLSearchParams approach is correct. No concerns.

The removal of PAGE_LIMIT is the right call — it was previously causing the server setting to be silently ignored.


Test Coverage

The three new tests in meshcoreRoutes.test.ts (lines 2104–2140) cover:

  1. Server-configured max as default limit ✓
  2. Ceiling clamp (5000 → 1000) ✓
  3. Explicit smaller client limit honored ✓

Missing test case: There's no test covering an explicit client-supplied limit larger than maxCount (e.g., ?limit=900 with getMaxCount() = 500). Based on the current code, this resolves to 900 (clamped to 1000 ceiling), not 500. This behavior may or may not be intentional — a test would clarify the expected contract.


Minor Observations

  • The since query parameter input handling (req.query.since) uses the same seconds/milliseconds heuristic as the Meshtastic route (lines 3287–3288). This is fine and consistent.
  • No security concerns identified — the existing requirePermission middleware is in place.
  • No performance concerns — getMaxCount() reads a single settings row (cached or fast DB lookup).

Verdict

Approve with suggestions. The core fix is correct and the tests cover the primary behavior. The edge case around client limits larger than maxCount is a minor documentation/behavior gap, not a regression.

@Yeraze Yeraze merged commit e41db0c into main Jun 24, 2026
19 checks passed
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