@@ -218,16 +218,18 @@ async def _update_core_local(self, db_core_config: CoreConfig):
218218 await self ._persist_state ()
219219
220220 async def _update_core_nats (self , db_core_config : CoreConfig ):
221- # Validate core before publishing
222- # Keep local state in sync immediately, while still broadcasting via NATS.
221+ # Persist local state (and KV snapshot) before broadcasting.
222+ # This lets node workers refresh from KV and avoids reconnect races.
223+ await self ._update_core_local (db_core_config )
224+
225+ # Validate payload before publishing the broadcast message.
223226 self .validate_core (
224227 db_core_config .config , db_core_config .exclude_inbound_tags , db_core_config .fallbacks_inbound_tags
225228 )
226229 try :
227230 await self ._publish_invalidation ({"action" : "update" , "core" : self ._core_payload_from_db (db_core_config )})
228231 except Exception as exc :
229232 self ._logger .warning (f"Failed to publish core update via NATS: { exc } " )
230- await self ._update_core_local (db_core_config )
231233
232234 async def update_core (self , db_core_config : CoreConfig ):
233235 await self ._update_core_impl (db_core_config )
@@ -244,11 +246,13 @@ async def _remove_core_local(self, core_id: int):
244246 await self ._persist_state ()
245247
246248 async def _remove_core_nats (self , core_id : int ):
249+ # Persist local removal (and KV snapshot) before broadcasting.
250+ await self ._remove_core_local (core_id )
251+
247252 try :
248253 await self ._publish_invalidation ({"action" : "remove" , "core_id" : core_id })
249254 except Exception as exc :
250255 self ._logger .warning (f"Failed to publish core remove via NATS: { exc } " )
251- await self ._remove_core_local (core_id )
252256
253257 async def remove_core (self , core_id : int ):
254258 await self ._remove_core_impl (core_id )
0 commit comments