fix(packets): order by ingest id, not rxTime — fresh activity visible on packets page (#1345)#1349
Merged
Conversation
added 2 commits
May 24, 2026 04:30
PR #1233 redefined transmissions.first_seen as the radio's receive time (rxTime). When an observer buffers offline and uploads hours later, its packets land with old first_seen values. The /api/packets handler was ORDER BY first_seen DESC, which pushed buffered uploads below older ingested packets that happened to have fresher rxTime — the packets page looked stale even with active MQTT ingest. Switch the default ordering to t.id DESC (ingest order) on /api/packets and adjacent endpoints. The since= filter still uses first_seen (rxTime semantics preserved). In-memory store now sorts query results by ID too so the path that does NOT fall back to SQL gets the same fix. Endpoints touched: - DB.QueryPackets, DB.QueryMultiNodePackets, DB.GetRecentTransmissionsForNode - Store.QueryPackets, Store.QueryMultiNodePackets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1345 — the packets page shows "no recent activity" while MQTT ingest is healthy because the default
/api/packetsquery wasORDER BY first_seen DESC, and PR #1233 redefinedfirst_seenas the observer's radio receive time (rxTime). When an observer buffers offline and uploads hours later, its packets land with hours-oldfirst_seenvalues; older-ingested packets with fresher rxTime then crowd the top of the list and the visually freshest activity disappears.Fix
Switch the default ordering to
t.id DESC(ingest order) on/api/packetsand the closely-related endpoints.idis monotonic with ingest time and immune to buffered uploads.Endpoints changed (all use the same fix for the same reason):
GET /api/packets(default)DB.QueryPackets,Store.QueryPacketscmd/server/db.go,cmd/server/store.goGET /api/packets?nodes=…DB.QueryMultiNodePackets,Store.QueryMultiNodePacketsDB.GetRecentTransmissionsForNodecmd/server/db.gosince=semantic — preservedsince=still filters byfirst_seen(RFC3339 path uses the observations.timestamp subquery), i.e. "packets the network received since X." Buffered uploads of older packets are still excluded from asince=15mview even if they were ingested in the last 15 minutes. Only the display order changes; filtering by receive time is unchanged.Audit — NOT changed
Store.QueryGroupedPacketsalready sorts byLatestSeen(max observation timestamp), which is correct for the grouped view and immune to the buffered-upload regression.GetChannelMessagesand channelsample_jsonsubqueries keepfirst_seen DESC— channel message chronology is meaningful for message UX; if buffered uploads become a problem here too it's a separate UX call (out of scope for bug(packets): page shows old/empty because first_seen=rxTime sorts buffered uploads to top — should order by ingest-time #1345).s.packetsinsertion ordering (Load + ingest) — untouched. The fix sorts at query time so we don't perturboldestLoadedinvariants.Tests — TDD red → green
508f4371addscmd/server/packets_order_test.gowith two cases — order assertion (failed on master with[fresh, buffered]) and since-filter semantic (RFC3339 path uses observation timestamps).0fd685e7switches the SQL + in-memory ordering. Tests pass; fullcmd/serversuite green locally (44s).Out of scope
Preflight
Clean (
bash ~/.openclaw/skills/pr-preflight/scripts/run-all.sh origin/master).