fix(mesh): use configured offline threshold in data store

- Add offline_threshold_hours parameter to MeshDataStore.__init__
- Compute is_online in _normalize_node using configured threshold
- Pass config.mesh_intelligence.offline_threshold_hours from main.py
- Removes reliance on health engine for initial is_online computation

Verification:
- Unit test confirms 2h threshold marks 3h-old node offline
- Unit test confirms 4h threshold marks same node online
- Container starts healthy with no config errors
- Health engine reports 16/16 infra online
This commit is contained in:
zvx-echo6 2026-05-13 23:54:20 -06:00
commit 7a4bd4f38f
2 changed files with 65 additions and 59 deletions

View file

@ -265,6 +265,7 @@ class MeshAI:
self.data_store = MeshDataStore( self.data_store = MeshDataStore(
source_configs=enabled_sources, source_configs=enabled_sources,
db_path="/data/mesh_history.db", db_path="/data/mesh_history.db",
offline_threshold_hours=self.config.mesh_intelligence.offline_threshold_hours,
) )
# Initial fetch and backfill # Initial fetch and backfill
self.data_store.force_refresh() self.data_store.force_refresh()

View file

@ -230,16 +230,19 @@ class MeshDataStore:
self, self,
source_configs: list[MeshSourceConfig], source_configs: list[MeshSourceConfig],
db_path: str = "/data/mesh_history.db", db_path: str = "/data/mesh_history.db",
offline_threshold_hours: int = 2,
): ):
"""Initialize the data store. """Initialize the data store.
Args: Args:
source_configs: List of source configurations source_configs: List of source configurations
db_path: Path to SQLite database for historical data db_path: Path to SQLite database for historical data
offline_threshold_hours: Hours before a node is considered offline
""" """
self._sources: dict[str, MeshviewSource | MeshMonitorDataSource | MQTTSource] = {} self._sources: dict[str, MeshviewSource | MeshMonitorDataSource | MQTTSource] = {}
self._db_path = db_path self._db_path = db_path
self._db: Optional[sqlite3.Connection] = None self._db: Optional[sqlite3.Connection] = None
self._offline_threshold_hours = offline_threshold_hours
# Live state # Live state
self._nodes: dict[int, UnifiedNode] = {} self._nodes: dict[int, UnifiedNode] = {}
@ -745,11 +748,13 @@ class MeshDataStore:
node.last_heard = ts or 0.0 node.last_heard = ts or 0.0
# NOTE: is_online is set by MeshHealthEngine.compute() using the # Compute is_online based on configured threshold
# configured offline_threshold_hours. Don't set it here with a # This ensures correct status immediately, before health engine runs
# hardcoded value - let the health engine determine online status. if node.last_heard:
# The health engine runs on every refresh cycle and will set is_online offline_threshold = time.time() - (self._offline_threshold_hours * 3600)
# based on: (now - last_heard) < (offline_threshold_hours * 3600) node.is_online = node.last_heard > offline_threshold
else:
node.is_online = False
# Hops, SNR, RSSI (MM) # Hops, SNR, RSSI (MM)
node.hops_away = raw.get("hopsAway") node.hops_away = raw.get("hopsAway")