Spaces:
Running
Running
Hamdy Doma commited on
Commit ·
2f5ddeb
1
Parent(s): a8fbf04
Fix session lifecycle to prevent premature termination
Browse files- messaging/handler.py +2 -10
- messaging/platforms/telegram.py +3 -4
messaging/handler.py
CHANGED
|
@@ -639,16 +639,8 @@ class ClaudeMessageHandler:
|
|
| 639 |
)
|
| 640 |
finally:
|
| 641 |
logger.info(f"HANDLER: _process_node completed for node {node_id}")
|
| 642 |
-
#
|
| 643 |
-
#
|
| 644 |
-
# around after this node completes.
|
| 645 |
-
try:
|
| 646 |
-
if captured_session_id:
|
| 647 |
-
await self.cli_manager.remove_session(captured_session_id)
|
| 648 |
-
elif temp_session_id:
|
| 649 |
-
await self.cli_manager.remove_session(temp_session_id)
|
| 650 |
-
except Exception as e:
|
| 651 |
-
logger.debug(f"Failed to remove session for node {node_id}: {e}")
|
| 652 |
|
| 653 |
async def _propagate_error_to_children(
|
| 654 |
self,
|
|
|
|
| 639 |
)
|
| 640 |
finally:
|
| 641 |
logger.info(f"HANDLER: _process_node completed for node {node_id}")
|
| 642 |
+
# DO NOT remove sessions here. They should persist for the duration of the conversation.
|
| 643 |
+
# sessions will be managed/cleaned up by CLISessionManager if needed (e.g. on timeout).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 644 |
|
| 645 |
async def _propagate_error_to_children(
|
| 646 |
self,
|
messaging/platforms/telegram.py
CHANGED
|
@@ -717,10 +717,6 @@ class TelegramPlatform(MessagingPlatform):
|
|
| 717 |
chat_id = str(update.effective_chat.id)
|
| 718 |
text = update.message.text or ""
|
| 719 |
|
| 720 |
-
# DEBUG ECHO
|
| 721 |
-
if user_id == self.admin_id:
|
| 722 |
-
await update.message.reply_text(f"DEBUG: Received '{text}'")
|
| 723 |
-
|
| 724 |
# 1. Handle Admin Buttons (Highest Priority)
|
| 725 |
if user_id == self.admin_id:
|
| 726 |
if text == "🤖 الموديل الحالي": return await self._on_model_command(update, context)
|
|
@@ -987,6 +983,9 @@ class TelegramPlatform(MessagingPlatform):
|
|
| 987 |
finally:
|
| 988 |
with contextlib.suppress(OSError):
|
| 989 |
tmp_path.unlink(missing_ok=True)
|
|
|
|
|
|
|
|
|
|
| 990 |
|
| 991 |
async def _on_telegram_error_wrapper(self, update: Update, context: ContextTypes.DEFAULT_TYPE, func) -> None:
|
| 992 |
"""Wrapper to catch and report errors to chat."""
|
|
|
|
| 717 |
chat_id = str(update.effective_chat.id)
|
| 718 |
text = update.message.text or ""
|
| 719 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 720 |
# 1. Handle Admin Buttons (Highest Priority)
|
| 721 |
if user_id == self.admin_id:
|
| 722 |
if text == "🤖 الموديل الحالي": return await self._on_model_command(update, context)
|
|
|
|
| 983 |
finally:
|
| 984 |
with contextlib.suppress(OSError):
|
| 985 |
tmp_path.unlink(missing_ok=True)
|
| 986 |
+
logger.info(f"HANDLER: _process_node completed for node {node_id}")
|
| 987 |
+
# DO NOT remove sessions here. They should persist for the duration of the conversation.
|
| 988 |
+
# sessions will be managed/cleaned up by CLISessionManager if needed (e.g. on timeout).
|
| 989 |
|
| 990 |
async def _on_telegram_error_wrapper(self, update: Update, context: ContextTypes.DEFAULT_TYPE, func) -> None:
|
| 991 |
"""Wrapper to catch and report errors to chat."""
|