Skip to content

fix(takserver): drop CoT the mesh delivers more than once#5667

Merged
thebentern merged 3 commits into
mainfrom
fix/tak-dedup-duplicate-cot
May 30, 2026
Merged

fix(takserver): drop CoT the mesh delivers more than once#5667
thebentern merged 3 commits into
mainfrom
fix/tak-dedup-duplicate-cot

Conversation

@thebentern

Copy link
Copy Markdown
Contributor

Problem

When the same two nodes are reachable by more than one path (e.g. both on Wi-Fi and the mesh, or a LoRa message relayed over several hops), ATAK surfaces duplicate chat / TAK-Talk messages. CoT's identity model is dedup-by-`uid`, but two copies only collapse at the client if they match.

This PR addresses the duplicates the bridge itself can emit: the mesh can hand `handleV2Packet` the same logical CoT event more than once (multi-path relay, or a sender retransmit).

Fix

  • New `CotDeliveryDedup` — a small TTL (2 min) cache keyed by the exact, already-normalized CoT XML, bounded to 512 entries, with an injectable clock.
  • `handleV2Packet` consults it before injecting to the TAK client: an identical event within the window is dropped; genuine updates (new PLI position, moved marker, …) differ in content and pass through.
  • Confined to the single `meshPacketFlow` collector coroutine, so no locking.

Scope (what this does not do)

It dedupes only what the bridge injects — it can't see copies the TAK client receives over another transport (e.g. Wi-Fi network SA). For those, the client dedupes by `uid`, which is why #5661 hands ATAK the `*:-1:stcp` contact and the SDK preserves the uid/timestamps across the round-trip so the copies collapse client-side. (`ensureMinimumStaleForMesh` already excludes ephemeral `m-t-t`/`b-t-f` via `STATIC_COT_PREFIXES`, so chat/TAK-Talk timestamps are preserved — no change needed there.)

Tests

5 unit tests (`CotDeliveryDedupTest`) with an injected clock: exact-repeat drop, distinct events pass, same-uid-changed-content passes, re-admit after the TTL elapses, and `maxEntries` eviction.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the bugfix PR tag label May 30, 2026
@thebentern thebentern enabled auto-merge May 30, 2026 13:31
thebentern and others added 3 commits May 30, 2026 08:58
The mesh can hand the bridge the same logical CoT event multiple times (a packet relayed over several LoRa paths, or a sender that retransmits), which made ATAK surface doubled chat / TAK-Talk messages. Add a small TTL cache (CotDeliveryDedup) keyed by the exact, already-normalized CoT XML and gate handleV2Packet on it: an identical event within the window is dropped, while genuine updates (new PLI position, moved marker, …) differ in content and pass through. Confined to the single meshPacketFlow collector coroutine, so no locking. Complements the *:-1:stcp endpoint fix (#5661) — that lets the TAK client dedupe cross-transport copies by uid; this stops the bridge from emitting its own duplicates.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- spotlessApply reformats KDoc line wrapping in CotDeliveryDedup.kt
- Rename test to remove comma character (illegal on Kotlin/Native targets)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tive identifiers)

Backtick-quoted function names may contain a comma on JVM but not on Kotlin/Native, so :core:takserver:compileTestKotlinIosSimulatorArm64 failed ("Name contains illegal characters: ','") while jvmTest passed. Rename the one offending test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@thebentern thebentern force-pushed the fix/tak-dedup-duplicate-cot branch from b4ba9dc to 92af91a Compare May 30, 2026 13:58
@thebentern thebentern added this pull request to the merge queue May 30, 2026
Merged via the queue into main with commit ad61441 May 30, 2026
18 checks passed
@thebentern thebentern deleted the fix/tak-dedup-duplicate-cot branch May 30, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix PR tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants