Skip to content

EMCOMM (emergency communications)

Developer reference for Incident Command, the emergency outbox, MECP send reliability, ACK/beacon, ops alerts, EMCOMM exports, SAR map tools, or track retention. MECP wire format, siren alerts, audit log, and RF rebroadcast live in mecp.md. Repo-wide rules live in AGENTS.md. The operator-facing guide (what users see and do) is ../emcomm.md; keep it in sync when user-visible behavior changes.

Safety invariants (S1–S19)

Keep this list in sync with the header comment in emcommSafety.contract.test.ts. Every invariant has a source contract and/or behavioral test today; do not weaken one without updating both the test and this table.

ID Invariant Status / coverage
S1 MECP compose send path uses the emergency outbox (not bare handleSendChunk only) Enforced — contract + emergencySend.test.ts
S2 Emergency rows ignore the 24h age / 5-attempt stop; the soft row cap blocks (never deletes) active distress rows Enforced — contract + useChatOutbox.test.ts
S3 Offline / send-fail MAYDAY still enqueues and drains on reconnect Enforced — emergencySend.test.ts (enqueue paths) + useChatOutbox.test.ts (emergency drain)
S4 Watcher hydration seeds without alert/audit Enforced — useMecpAlertWatcher.test.tsx (hydrate seed + incident upsert without alert/audit)
S5 Sev 0/1 bypass mute; drills never alert Enforced — mecpAlert.test.ts
S6 Cross-protocol rebroadcast does not duplicate incidents Enforced — contract (fingerprint omits protocol) + incidentStore.test.ts
S7 B02/B03 do not open new incidents; B02 is not the general ACK compose Enforced — contract + incidentStore.test.ts, mecpAck.test.ts, useMecpAlertWatcher.test.tsx
S8 Incident tab lazy export is mounted in App Enforced — contract
S9 Tab badge counts every open Incident-panel row (any severity, drills included; incidentTabBadgeCount) Enforced — contract + incidentStore.test.ts (all open rows) + AppRail.test.tsx, navBadges.test.ts
S10 Manual disconnect does not fire link-down / does not cancel emergency outbox retries Enforced — useOperationalAlerts.test.ts, operationalAlerts.test.ts
S11 Link-down suppressed while RF reconnect is in progress Enforced — useOperationalAlerts.test.ts, operationalAlerts.test.ts
S12 Incident-open nodes exempt from position_history prune Enforced — position-history-prune.test.ts + useAppStartupDbPrune.test.ts
S13 USGS/topo tiles only via allowlisted hosts; no user URL template for that basemap Enforced — contract + basemapRegistry.test.ts. User-confirmed custom XYZ/MBTiles are a separate validated path (custom-sources*.ts / customMapSources.ts), not a USGS template override.
S14 mecpComposeEnabled default remains false Enforced — contract + source-policy rule emcomm-mecp-compose-default-off
S15 Incident ACKs queue as normal priority; recordAck only on live 'sent' (drain tags ackIncident: viewKey) Enforced — contract + App handleIncidentAck + applyIncidentAckAfterOutboxSend
S16 App mounts emergency+ACK outbox drain once for all protocols Enforced — contract + useEmergencyOutboxDrain.test.ts
S17 mecpStandingAlertEnabled defaults to false; App gates the banner and attention hook on it Enforced — contract + useUnseenEmergencyAlerts.test.ts, appSettingsStorage.test.ts
S18 A blocked MECP sender never alerts, opens an incident, or is rebroadcast, but is still audited Enforced — contract + useMecpAlertWatcher.test.tsx
S19 The alert throttle only silences tones; throttled reports are still recorded (created seen) Enforced — contract + useMecpAlertWatcher.test.tsx, incidentStore.test.ts

WS1 — Incident tab, store, watcher hydrate upsert

  • Types: incidentTypes.ts — EmergencyIncident (status: 'open' | 'acked' | 'resolved', protocolsSeen, ackPeerIds/ackCount, beaconActive/beaconAcked, lat/lon + coordsSource: 'message' | 'lastKnown' | null, isDrill).
  • Store: incidentStore.ts (Zustand, canonical SQLite emergency_incidents / emergency_incident_tombstones, legacy localStorage recovery cache mesh-client:incidents, cap MAX_INCIDENTS = 200). Startup awaits hydrateIncidentStore before mounting watcher and retention effects; mutators write through ordered IPC, and one-time legacy import is transactional and idempotent. See renderer storage.
  • Fingerprint strips GPS from freetext so a GPS update does not fork a row. Bridged copies from a different sender id merge within CROSS_PROTOCOL_MERGE_WINDOW_MS (10 min) only when the relay arrives on a new protocol, stripped text is non-empty, and the full payload (including coords) matches; original senderId is kept and relays go in relaySenderIds. GPS-only MAYDAYs from two victims never merge. Relays never overwrite victim coords / lastKnown.
  • Resolve / prune tombstones both the sender fingerprint and incidentPayloadMatchKey (when stripped freetext is non-empty) so seed cannot reopen via a relay or escalated copy. GPS-only MAYDAYs skip payload tombs so different victims do not collide.
  • Cap eviction: resolved → drills → higher severity number → oldest; never evict open non-drill sev 0/1 (temporary over-cap allowed).
  • resolvedTombstones survive incident prune/clearAll of live rows so hydration cannot reopen resolved MAYDAYs. Live path may reopen after INCIDENT_REOPEN_GRACE_MS.
  • Seed (fromSeed): applies the same own/history/S&F/tapback skips as the live watcher path, skips messages older than INCIDENT_SEED_MAX_AGE_MS (24h), and honors tombstones.
  • Watcher: useMecpAlertWatcher.ts upserts on live messages and on a one-shot hydration seed (S4). Seed applies the same own/history/S&F/tapback skips as live, except an own B01/B03 is still recorded (no alert/audit) so the originator can cancel the beacon — see WS3. Passes fromSeed, and uses resolveLastKnown from UI nodes when present so incidents without GPS in freetext can still map-pin.
  • UI: components/incident/ — IncidentPanel.tsx (lazy via lazyTabPanels.ts, mounted in App.tsx, S8), EmergencyIncidentRow.tsx, AckIncidentButton.tsx, ResolveIncidentButton.tsx. Tab slot Incident in tabSlotIds.ts / appTabMappings.ts (INCIDENT_PANEL_INDEX) sits just before App (always visible on all three protocols; rarely used day-to-day — badge surfaces every open row, including drills); icon in tabIcons.tsx. Panel intro + empty hint copy live under incidentPanel.* in en/translation.json. User-facing “what’s here” also in ../emcomm.md, README EMCOMM / Incident Command, and troubleshooting What is the Incident tab?.
  • Standing alert (unseen MAYDAY/URGENT): EmergencyIncident.seenAt is local only (never on the wire). Live-created rows start without it; seed (fromSeed) and own (localOrigin) rows get seenAt on creation, and the legacy v3 storage migration stamps pre-existing rows so an upgrade never raises a banner. A live reopen or escalation into sev 0/1 clears it again. markSeen / markAllSeen, resolveIncident, and confirmBeacon set it; App calls markSeen in handleIncidentAck and markAllSeen only when activePanelIndex changes to the Incident tab (an already-open tab does not prove anyone is watching). selectUnseenCriticalIncidents (open, non-drill, sev ≤ 1, no seenAt) drives UnseenEmergencyBanner.tsx (mounted once in App.tsx under ConnectionBanner) and useUnseenEmergencyAlerts.ts: each newly unseen id calls app:requestAttention (main BrowserWindow.flashFrame(true) on the sender window when unfocused, cleared on next focus; no platform branch), and when mecpRepeatAlertMinutes (null = off, 1–60) is set the siren / EAS tone replays every interval until nothing is unseen. The first tone stays owned by triggerMecpAlert. All of this is opt-in via App → MECP → Incident Command station (mecpStandingAlertEnabled, default false, S17): when off, App does not render the banner and the hook skips attention and repeats; seen-state bookkeeping still runs. The repeat-minutes field lives under that toggle. getOperationalAlertSettings treats a stored non-null mecpRepeatAlertMinutes with no stored toggle as enabled, so stations that already opted into repeats keep station mode. Rows upserted with quiet: true (alert-throttled senders, see mecp.md) are created seen and escalation does not clear it.
  • Event timeline: EmergencyIncident.events (IncidentEvent[], oldest first, capped at MAX_EVENTS_PER_INCIDENT = 500; over the cap the original received entry is kept and the oldest later events drop). Only distinct ACK peers grow a timeline without bound; records now live in the dedicated SQLite incident table; event caps still apply, and any future unbounded history requires an explicit retention policy. Appended in store mutators only: received (create), relayHeard (merge from a relay or a new protocol), ackHeard / ackSent (recordAck; peer id 'local' is ours), beaconConfirmed, beaconCancelled (B03 ingest), resolved, reopened. Records only what the mesh carried or the operator did. There are no responder status codes in MECP, so do not invent status events.
  • Map: open incidents with coordinates render via IncidentMarkersLayer in components/map/emcommMapLayers.tsx on both the LoRa Map tab and the Reticulum Map tab (Layers → Emergency incidents, mapLayerStore.showIncidents, default on; drills dashed). Reticulum hears MECP over LXMF chat the same way as LoRa; markers are protocol-agnostic from incidentStore.

WS2 — Emergency-priority outbox

  • Type / storage: OutboxEntry.priority: 'normal' | 'emergency' (electron-api.types.ts); OutboxEntryInput.priority is optional and defaults to 'normal'. SQLite chat_outbox.priority TEXT NOT NULL DEFAULT 'normal' (canonical DDL + DESIRED_COLUMNS additive upgrade in db-schema-sync.ts). chat:outbox:add coerces anything other than 'emergency' to 'normal'; rowToOutboxEntry maps the same way.
  • Drain policy (useChatOutbox.ts + App-level useEmergencyOutboxDrain.ts):
  • Emergency rows skip the 24h OUTBOX_MAX_AGE_MS drain cutoff (still require queued/failed + due nextRetryAt).
  • Emergency rows are removed only after awaitNetworkAck resolves (see mecp.md — Send path); radio accept alone is not delivery. Failure or no acknowledgement schedules nextRetryAt with EMERGENCY_RETRY_DELAYS_MS (30s → 1m → 2m, then 5m forever) — no MAX_ATTEMPTS stop. Encryption-blocked errors still go to blocked without retry. OUTBOX_DRAIN_ROW_TIMEOUT_MS is NETWORK_ACK_MAX_TIMEOUT_MS + 15s so the watchdog never cuts a legitimate wait short.
  • Cancel (Stop retrying on the chat outbox row, cancel on Incident ACK rows) calls abortOutboxRowSend before deleting the row, so an in-flight ACK wait ends and the drain skips failure persistence.
  • Normal rows stop after MAX_ATTEMPTS = 1 + REGULAR_MESSAGE_MAX_AUTO_RESENDS (4).
  • Soft cap: EMERGENCY_OUTBOX_SOFT_CAP = 20 counts non-blocked emergency rows only. Cap blocks the least-urgent non-MAYDAY row (never blocks MECP/0 payloads); if only MAYDAYs remain, over-cap is allowed. Rows are never deleted.
  • Order: drainChatOutboxOnce sends emergency rows before normal, then oldest first.
  • Always-on drain: useEmergencyOutboxDrain mounts once in App.tsx for all three protocols (registers drain listeners + wakes at earliest App-managed nextRetryAt). Sends emergency rows and Incident ACK rows tagged ackIncident:<id>:…. ACK rows skip the 24h / 5-attempt caps like emergency. Pending ACK rows surface on the Incident row (cancel). ChatPanel still owns UI + other normal rows. Shared withChatOutboxDrainLock + per-row OUTBOX_DRAIN_ROW_TIMEOUT_MS watchdog prevent double-send / hung locks (timeout does not abort the in-flight TX — a late success may still air, which is acceptable for MECP).
  • Incident ACKs enqueue as normal priority with incidentAckViewKey; recordAck / confirmBeacon run on live 'sent' or when the tagged ACK row drains successfully (applyIncidentAckAfterOutboxSend decides from the sent payload: B02 → confirmBeacon, else recordAck).
  • Send helper: emergencySend.ts — sendEmergencyText always enqueues (the row stays visible and cancellable while it waits for acknowledgement); queueOutbox must trigger a drain (useChatOutbox.queue does; beaconCancel.ts calls requestChatOutboxDrain). sendTextWithOutboxFallback(..., 'normal') (Incident ACK) keeps live-send-first: Reticulum live sends wait for LXMF receipt (or remote PN propagated) before reporting 'sent'; mid-cascade stored_locally is not counted early (may not survive sidecar restart). Timeout/failure queues. DM-only with no destination throws (does not silently succeed).

WS3 — ACK (R01) vs beacon (B01 / B02 / B03)

  • Codes (mecpAck.ts): R01 general ACK (MECP/<sev>/R01 <echoed codes> [freetext] ~CALLSIGN), B01 beacon, B02 beacon ACK (reduce beacon rate), B03 beacon cancel (sender OK). composeGeneralAck never emits B02 (S7); composeBeaconAck / composeBeaconCancel emit only their marker. All composers stay within MAX_MESSAGE_BYTES (freetext truncated first, then trailing echoed codes dropped; callsign suffix preserved).
  • Correlation: findOpenIncidentForAck scores unresolved incidents by exact echoed-code set, overlap, active beacon (for B02), matching severity, then recency. Incidents raised by the ACK sender are never candidates; the store's recordAck also ignores the incident sender acking themselves.
  • Incident ACK button (incidentAck.ts): incidentNeedsBeaconAck (active, unconfirmed beacon) → B02 Confirm, else R01 ACK. resolveIncidentAckRoute prefers the active protocol if the incident was heard there; otherwise targets the victim's original protocol (protocolsSeen[0]). On a DM-only non-origin protocol, DMs the latest numeric relaySenderIds entry, or falls back to the origin protocol. App.tsx handleIncidentAck sends via sendTextWithOutboxFallback(..., 'normal') with incidentAckViewKey, then confirmBeacon / recordAck only when outcome is 'sent'.
  • Beacon cancel (B03) (beaconCancel.ts): B03 means "I am OK". Ingest clears only unresolved beacons whose senderId matches the B03 sender, and does not resolve the row. A third-party B03 would not stop the victim's beacon and would claim the helper is OK, so Incident Command does not offer Send cancel for other people's beacons. Resolve on those rows (and on any non-beacon) stays local. When the local operator resolves a beacon they originated (localOrigin, or senderId in the local node-id set), the button is Cancel beacon and resolveIncidentWithBeaconCancel sends exactly one composeBeaconCancel via sendEmergencyText (emergency outbox) on the origin protocol and channel — repeating beaconCancelToNode when the beacon was unicast. The row resolves only after that cancel is sent or queued; a second click while the send is in flight does not queue another B03. DM-only protocols with no stored destination do not queue (the row stays open). The watcher records the operator's own B01/B03 into the incident store without alert or audit so the originator has a row to cancel; other own traffic is still ignored.
  • ACK honesty: broadcast ACKs are heard-by-network, best effort — an ACK count means R01/B02 copies were overheard, not that the distressed operator read anything. UI copy must not imply read receipts.

WS4 — Operational alerts

  • Pure predicates (operationalAlerts.ts): shouldFireSilenceAlert, shouldFireSilenceEscalation (SILENCE_ESCALATION_MULTIPLIER = 2; never-heard nodes are not "silent"), shouldFireBatteryLow (ignores 0 "unknown" and >100 charging; requires hasBatteryTelemetry), shouldFireLinkDown (requires was-connected, not manual disconnect, not reconnecting — S10/S11).
  • Hook (useOperationalAlerts.ts), mounted once in App.tsx with nodesForUi, active capabilities, Meshtastic + MeshCore link states, and useOperationalAlertSettings():
  • Watched nodes only (watchedNodesStore). Battery low fires once per cycle; re-arms after recovering BATTERY_ALERT_RESET_HYSTERESIS (5 pts) above the threshold.
  • Silence escalation at 2× nodeSilenceAlertMinutes; the first-level offline alert stays in useNodeStatusNotifier (which receives the same setting as silenceThresholdMinutes).
  • Link-down: connecting/reconnecting keep the "was up" latch so reconnect exhaustion still alerts; manual disconnect (connectionLoss !== true) never alerts; LINK_DOWN_GRACE_MS (5s) debounce absorbs power-suspend blips. Reticulum is not a link entry (sidecar, not RF driver).
  • Settings UI: App → Notifications → ops alerts subsection in AppPanel.tsx. The standing-alert toggle and repeat interval are in App → MECP.
  • Settings (appSettingsStorage.ts getOperationalAlertSettings, defaults in defaultAppSettings.ts): nodeSilenceAlertMinutes (null = off / capability default), nodeBatteryLowThreshold (10), notifyOnLinkDown (true), mecpStandingAlertEnabled (false), mecpRepeatAlertMinutes (null = off; see WS1 standing alert). Changes broadcast via the mesh-client:appSettings window event. Sounds: batteryLow, connectionLost (notificationSounds.ts).

WS6 — Exports

  • UI: NodeListPanel Export JSON (topology envelope over nodesToExportRows) / Export CSV; DiagnosticsPanel Export JSON (visible rows for the active protocol); MECP audit log via App → MECP; IncidentPanel Export log (JSON / CSV, disabled when the store is empty).
  • Serializers (exportFormats.ts, pure): nodesToCsv (RFC 4180, CSV-injection guarded, canonical TOPOLOGY_NODE_FIELDS first then extra keys), nodesToTopologyJson (format: 'mesh-client-topology', version), diagnosticsRowsToJson (format: 'mesh-client-diagnostics'), toJsonSafe (Maps/Sets/bigint/Dates/cycles).
  • Incident log (after-action record): incidentsToExportRows maps every stored incident (including resolved) oldest first to INCIDENT_EXPORT_FIELDS (snake_case, ISO timestamps, null for missing); incidentsToJson (format: 'mesh-client-incidents') and incidentsToCsv (space-joined list fields). The trailing events field is an array of { at, kind, peer_id, protocol } in JSON and one "<iso> <kind> [peer] [protocol]"-per-entry, semicolon-joined cell in CSV. Source is the incidentStore only — the MECP audit log stays a separate export.
  • Ops link-down: Meshtastic + MeshCore RF drivers only. Reticulum uses the sidecar (not an RF ConnectionDriver link), so link-down alerts intentionally omit it.

WS7 — SAR map tools (MGRS grid, measure, bearing)

  • lib/map/mgrsGrid.ts: pickMgrsPrecisionForBbox (finest precision under MGRS_GRID_MAX_SQUARES = 400), mgrsSquaresInBbox, mgrsSquareSizeMeters, estimateMgrsSquareCount.
  • lib/map/measureMath.ts: polylineSegmentsKm, polylineLengthKm (haversine; invalid segments count 0).
  • Bearing: bearingBetween / formatBearing in nodeStatus.ts — surfaced as the Node Detail header bearing/distance row via nodeBearingRange.ts (only when ourPositionReference.trust === 'trusted'; distance honors the miles/km setting).
  • Map wiring: MgrsGridLayer (Layers → MGRS grid, mapLayerStore.showMgrsGrid, default off; labels only when ≤60 squares) and MeasureControl in components/map/emcommMapLayers.tsx.

WS8 — USGS topo, incident track exemption, prune

  • USGS topo basemap: usgs-topo in the offline-maps allowlist (basemapRegistry.ts) — fixed basemap.nationalmap.gov ArcGIS host (z/y/x order), USGS_TOPO_MAX_NATIVE_ZOOM = 16 (Leaflet overzooms), served through mesh-tiles://usgs-topo/… and the shared tile cache. No user-supplied URL templates (S13). Renderer basemap entry in mapBasemapUtils.ts; selectable in the Map Layers control and leafletMapControls.tsx. See offline-maps.md.
  • Track exemption: incidentTrackExemption.ts nodesExemptFromPositionPrune returns sender ids of open/acked incidents (resolved releases the hold). useAppStartupDbPrune.ts (incidentPruneOptions()) reads the incident store at each startup/session prune and passes them as exemptNodeIds to startupDbPrune.ts. Incident sender ids are String(msg.from) (useMecpAlertWatcher.ts), and MessageRecord.from is already a uint32 for every protocol (MeshCore pubkeys and Reticulum hashes are folded at ingest), so they always normalize in main. Known limitation: a MeshCore channel MECP whose sender resolves only to a display-name stub id (0xA… range) or 0 does not exempt that contact's real pubkeyToNodeId track. Reticulum has no position_history writer, so nothing to exempt there.
  • Prune IPC: db:prunePositionHistory / db:prunePositionHistoryPerNode accept optional exemptNodeIds; main validates with sanitizeExemptNodeIdsArg and normalizePositionPruneExemptNodeIds (numbers, decimal, !hex, 0x hex; capped at MAX_POSITION_PRUNE_EXEMPT_IDS) and excludes them via json_each in database.ts (S12).

File map

Area Path
Incident store / types src/renderer/stores/incidentStore.ts, src/renderer/lib/mecp/incidentTypes.ts
Incident UI src/renderer/components/incident/
Unseen alert attention src/renderer/hooks/useUnseenEmergencyAlerts.ts, src/main/index.ts (app:requestAttention)
MECP block / throttle src/renderer/stores/mecpBlockStore.ts, src/renderer/lib/mecp/mecpBlock.ts, src/renderer/lib/mecp/mecpAlertThrottle.ts
Watcher (hydrate + live) src/renderer/hooks/useMecpAlertWatcher.ts
ACK / beacon src/renderer/lib/mecp/mecpAck.ts, src/renderer/lib/mecp/incidentAck.ts, src/renderer/lib/mecp/beaconCancel.ts
Outbox hook / policy src/renderer/hooks/useChatOutbox.ts
Emergency send helper src/renderer/lib/emergencySend.ts
Outbox IPC / schema src/main/index.ts (chat:outbox:*), src/main/db-schema-sync.ts (chat_outbox)
Ops alerts src/renderer/lib/operationalAlerts.ts, src/renderer/hooks/useOperationalAlerts.ts
Exports src/renderer/lib/exportFormats.ts
SAR map src/renderer/lib/map/mgrsGrid.ts, src/renderer/lib/map/measureMath.ts, src/renderer/components/map/emcommMapLayers.tsx
Topo / track retention src/shared/offlineMaps/basemapRegistry.ts, src/renderer/lib/incidentTrackExemption.ts, src/main/database.ts
Safety contract src/renderer/lib/mecp/emcommSafety.contract.test.ts