Phase 4-6: Dead code removal, performance, minor fixes

Phase 4:
- Remove legacy SessionRecord, _sessions, _msg_to_session from SessionStore
- Fix hardcoded provider in root endpoint (use settings.provider_type)
- Update session store tests

Phase 5:
- Use list-based string accumulation in ThinkingSegment, TextSegment, ToolCallSegment
- Cache MAX_MESSAGE_LOG_ENTRIES_PER_CHAT at SessionStore init
- Use iterative DFS in MessageTree.get_descendants

Phase 6:
- Add comment for abstract async generator workaround in BaseProvider
- Rename TELEGRAM_EDIT log tags to PLATFORM_EDIT in handler

Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
This commit is contained in:
Cursor Agent 2026-02-17 02:01:01 +00:00
parent 72b7e34999
commit bfc781e0ed
10 changed files with 75 additions and 128 deletions

View file

@ -479,7 +479,7 @@ class ClaudeMessageHandler:
return
if display and display != last_displayed_text:
logger.debug(
"TELEGRAM_EDIT: node_id=%s chat_id=%s msg_id=%s force=%s status=%r chars=%d",
"PLATFORM_EDIT: node_id=%s chat_id=%s msg_id=%s force=%s status=%r chars=%d",
node_id,
chat_id,
status_msg_id,
@ -488,13 +488,13 @@ class ClaudeMessageHandler:
len(display),
)
if os.getenv("DEBUG_TELEGRAM_EDITS") == "1":
logger.debug("TELEGRAM_EDIT_TEXT:\n%s", display)
logger.debug("PLATFORM_EDIT_TEXT:\n%s", display)
else:
head = display[:500]
tail = display[-500:] if len(display) > 500 else ""
logger.debug("TELEGRAM_EDIT_PREVIEW_HEAD:\n%s", head)
logger.debug("PLATFORM_EDIT_PREVIEW_HEAD:\n%s", head)
if tail:
logger.debug("TELEGRAM_EDIT_PREVIEW_TAIL:\n%s", tail)
logger.debug("PLATFORM_EDIT_PREVIEW_TAIL:\n%s", tail)
last_displayed_text = display
try:
await self.platform.queue_edit_message(
@ -504,7 +504,9 @@ class ClaudeMessageHandler:
parse_mode=self._parse_mode(),
)
except Exception as e:
logger.warning(f"Failed to update Telegram for node {node_id}: {e}")
logger.warning(
f"Failed to update platform for node {node_id}: {e}"
)
try:
try: