Skip to content

fix: packet monitor ordering now considers milliseconds (#2364)#2369

Merged
Yeraze merged 1 commit intomainfrom
fix/packet-monitor-ordering
Mar 22, 2026
Merged

fix: packet monitor ordering now considers milliseconds (#2364)#2369
Yeraze merged 1 commit intomainfrom
fix/packet-monitor-ordering

Conversation

@Yeraze
Copy link
Copy Markdown
Owner

@Yeraze Yeraze commented Mar 22, 2026

Summary

Fixes the second part of #2364 — packet monitor ordering didn't consider milliseconds, so packets within the same second appeared in wrong order.

Root Cause

The packet_log query used ORDER BY pl.timestamp DESC but timestamp is whole seconds (from Meshtastic protobuf rxTime). Packets arriving within the same second had undefined relative order.

Fix

Added pl.created_at DESC as a secondary sort key. created_at is already stored as Date.now() (millisecond precision) on every packet insert, but wasn't used in the sort. Applied to both PostgreSQL and SQLite/MySQL query paths.

Files Changed

File Change
src/db/repositories/misc.ts Add created_at DESC tiebreaker to both packet_log ORDER BY clauses

Test plan

  • 3052 tests pass, 0 failures

🤖 Generated with Claude Code

Added created_at (millisecond precision) as secondary sort key in
packet_log queries. Packets within the same second now display in
correct arrival order instead of arbitrary DB order.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
LEFT JOIN nodes to_nodes ON pl.to_node = to_nodes."nodeNum"
WHERE ${whereClause}
ORDER BY pl.timestamp DESC LIMIT ${limit} OFFSET ${offset}
ORDER BY pl.timestamp DESC, pl.created_at DESC LIMIT ${limit} OFFSET ${offset}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Excellent fix! Adding pl.created_at DESC as a secondary sort key resolves the ordering issue for packets arriving within the same second. Since created_at is stored with millisecond precision (Date.now()), this ensures packets are sorted by actual arrival order even when they have the same timestamp value.

LEFT JOIN nodes to_nodes ON pl.to_node = to_nodes.nodeNum
WHERE ${whereClause}
ORDER BY pl.timestamp DESC LIMIT ${limit} OFFSET ${offset}
ORDER BY pl.timestamp DESC, pl.created_at DESC LIMIT ${limit} OFFSET ${offset}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Perfect consistency! This identical change ensures the same ordering behavior across all database backends (SQLite/MySQL path). The dual maintenance of PostgreSQL and SQLite/MySQL query paths is handled correctly.

@Yeraze Yeraze merged commit 1694d86 into main Mar 22, 2026
16 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