@@ -310,6 +310,10 @@ def __init__(
310310 # An inconsistent state event means the Notebook was updated in a way that "broke" Delta
311311 # history, and the RTUClient needs to pull in the seed notebook and re-apply deltas from
312312 # a "new" current version id in order to catch up
313+ #
314+ # However if we get several inconsistent state events (say from getting them on file
315+ # resubscribe), we'll call catastrophic_failure to let the application handle tear-down
316+ self .inconsistent_state_event_count = 0
313317 self .register_rtu_event_callback (
314318 rtu_event = InconsistentStateEvent , fn = self .on_inconsistent_state_event
315319 )
@@ -634,6 +638,10 @@ async def on_inconsistent_state_event(self, msg: InconsistentStateEvent):
634638 the least, to stop getting new deltas in. Then we need to figure out what the new current
635639 version id is, and pull down seed notebook, and then resubscribe to file channel.
636640 """
641+ if self .inconsistent_state_event_count >= 3 :
642+ logger .warning ("Calling catastrophic failure after 3 inconsistent state events" )
643+ return await self .catastrophic_failure ()
644+
637645 logger .info ("Received inconsistent state event, resetting NotebookBuilder" )
638646 # There's the chance for some gnarly but rare edge cases here that would probably take a
639647 # serious amount of thinking and logic to handle. Basically, what happens if new Deltas
@@ -647,6 +655,7 @@ async def on_inconsistent_state_event(self, msg: InconsistentStateEvent):
647655 await self .file_unsubscribe ()
648656 await self .load_seed_notebook ()
649657 await self .send_file_subscribe ()
658+ self .inconsistent_state_event_count += 1
650659
651660 async def _on_delta_recv (self , msg : NewDeltaEvent ):
652661 """
0 commit comments