Upstream source
Evaluate and adapt Kpa-clawbot/CoreScope#2050: merge background-loaded chunks without violating the packet store's oldest-first ordering.
Current fork evidence
Verified against fork master 1bdf088e:
PacketStore.packets must be sorted by first_seen ASC.
evictStaleInternal walks from the head and stops at the first in-window transmission.
- The background merge still publishes with
s.packets = append(localPackets, s.packets...).
- Chunks selected by recent
last_seen may contain much older first_seen, so prepending silently breaks ordering and can under-evict.
Fork-specific adaptation
Preserve the fork's index-before-slice-publication invariant, parked route masks, and resolved-path/node indexes. Replace only the final publication with a bounded linear merge of two sorted runs; do not sort the complete store under s.mu.
Acceptance criteria
s.packets remains ordered after every chunk merge, including interleaved/equal timestamps and repeated last_seen activity.
- No packet is lost, duplicated, or visible without its indexes.
- Time- and memory-based eviction remove all eligible oldest entries.
- Complexity is O(existing + chunk), with at most a bounded incoming-chunk sort.
- A benchmark guards against a full-store comparison sort under the write lock.
Verification
Add direct merge and eviction regressions, run the full server suite under -race, benchmark a production-shaped merge, and run static checks.
No deploy or live-environment mutation is part of this issue.
Upstream source
Evaluate and adapt Kpa-clawbot/CoreScope#2050: merge background-loaded chunks without violating the packet store's oldest-first ordering.
Current fork evidence
Verified against fork master
1bdf088e:PacketStore.packetsmust be sorted byfirst_seen ASC.evictStaleInternalwalks from the head and stops at the first in-window transmission.s.packets = append(localPackets, s.packets...).last_seenmay contain much olderfirst_seen, so prepending silently breaks ordering and can under-evict.Fork-specific adaptation
Preserve the fork's index-before-slice-publication invariant, parked route masks, and resolved-path/node indexes. Replace only the final publication with a bounded linear merge of two sorted runs; do not sort the complete store under
s.mu.Acceptance criteria
s.packetsremains ordered after every chunk merge, including interleaved/equal timestamps and repeatedlast_seenactivity.Verification
Add direct merge and eviction regressions, run the full server suite under
-race, benchmark a production-shaped merge, and run static checks.No deploy or live-environment mutation is part of this issue.