@@ -25,6 +25,7 @@ class SessionState(TypedDict):
2525 session_messages : List [Dict [str , str ]]
2626 cleaned_messages : Dict [str , str ]
2727 last_summary : str
28+ is_active : bool
2829
2930
3031class Uploader :
@@ -33,7 +34,6 @@ class Uploader:
3334 def __init__ (self ):
3435 self ._client : Optional [WebClient ] = None
3536 self ._channel_id : Optional [str ] = None
36- self ._session_started : bool = False
3737 self ._indent_level : int = 0
3838 self ._executor = ThreadPoolExecutor (max_workers = 5 )
3939 self ._anthropic_client = None
@@ -141,11 +141,11 @@ def _start_session(self, first_note: str) -> bool:
141141 raw_reply_ts = raw_reply_ts ,
142142 session_messages = [{'ts' : header_response ['ts' ], 'text' : first_note }],
143143 cleaned_messages = {},
144- last_summary = first_note
144+ last_summary = first_note ,
145+ is_active = True
145146 )
146147
147148 # Initialize tracking
148- self ._session_started = True
149149 self ._summary_request_version = 0
150150 self ._latest_summary_version = 0
151151 self ._is_waiting_for_summary = False
@@ -353,8 +353,9 @@ def _summarize_session_async(self, version: int, session: SessionState):
353353 has_thread = len (session ['session_messages' ]) > 1
354354 thread_indicator = " :thread:" if has_thread else ""
355355
356- # Update header (keeping :wip: for now, will be removed in end_session)
357- header_text = f":wip: { summary } { thread_indicator } "
356+ # Only add :wip: if this session is still active
357+ wip_indicator = ":wip: " if session ['is_active' ] else ""
358+ header_text = f"{ wip_indicator } { summary } { thread_indicator } "
358359 self ._update_message (session ['channel_id' ], session ['thread_ts' ], header_text )
359360
360361 except Exception as e :
@@ -403,7 +404,7 @@ def upload(self, note_events: List[events.NoteEvent]) -> bool:
403404 continue
404405
405406 # Start a new session for the first note
406- if not self ._session_started :
407+ if not self ._current_session :
407408 success = self ._start_session (text )
408409 else :
409410 # Send as a reply to the thread with proper indentation
@@ -420,21 +421,23 @@ def upload(self, note_events: List[events.NoteEvent]) -> bool:
420421
421422 def end_session (self ) -> None :
422423 """End the current session."""
423- # Remove :wip: from header and trigger final summary
424- if self ._session_started and self ._current_session :
424+ if self ._current_session :
425425 try :
426+ # Mark session as inactive
427+ self ._current_session ['is_active' ] = False
428+
426429 # Cancel any pending summary timer
427430 if self ._summary_timer :
428431 self ._summary_timer .cancel ()
429432
430- # Request final summary
433+ # Request final summary (will see is_active=False and not add :wip:)
431434 if self ._current_session ['session_messages' ]:
432435 self ._summary_request_version += 1
433436 self ._executor .submit (self ._summarize_session_async ,
434437 self ._summary_request_version ,
435438 self ._current_session )
436439
437- # Update header to remove :wip:
440+ # Update header to remove :wip: immediately
438441 has_thread = len (self ._current_session ['session_messages' ]) > 1
439442 thread_indicator = " :thread:" if has_thread else ""
440443 header_text = f"{ self ._current_session ['last_summary' ]} { thread_indicator } "
@@ -447,7 +450,6 @@ def end_session(self) -> None:
447450
448451 # Clear session state
449452 self ._current_session = None
450- self ._session_started = False
451453 self ._indent_level = 0
452454 self ._summary_request_version = 0
453455 self ._latest_summary_version = 0
0 commit comments