Skip to content

Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)

Python

fixed handler bypassing rate limiter

Alishahryar1602a616fddcb
diff --git a/messaging/handler.py b/messaging/handler.py
index 94b964c4..d85b5e45 100644
--- a/messaging/handler.py
+++ b/messaging/handler.py
@@ -93,12 +93,16 @@ class ClaudeMessageHandler:
# Send initial status message
status_text = self._get_initial_status(tree, parent_node_id)
- status_msg_id = await self.platform.send_message(
+ # Using handle_message might still need the ID immediately, but we can queue it
+ # and wait if needed, or fire and forget if the ID is generated by the platform.
+ # For Telegram, we need the ID to track the status message.
+ status_msg_id = await self.platform.queue_send_message(
incoming.chat_id,
status_text,
reply_to=incoming.message_id
if incoming.message_id != incoming.message_id
else None,
+ fire_and_forget=False,
)
# Create or extend tree
@@ -138,7 +142,7 @@ class ClaudeMessageHandler:
if was_queued:
# Update status to show queue position
queue_size = self.tree_queue.get_queue_size(node_id)
- await self.platform.edit_message(
+ await self.platform.queue_edit_message(
incoming.chat_id,
status_msg_id,
f"📋 **Queued** (position {queue_size}) - waiting...",
@@ -302,15 +306,15 @@ class ClaudeMessageHandler:
)
# Update status messages for all affected children
for child in affected[1:]: # Skip first (current node)
- try:
- await self.platform.edit_message(
+ # Fire and forget these updates so they don't block the worker
+ self.platform.fire_and_forget(
+ self.platform.queue_edit_message(
child.incoming.chat_id,
child.status_message_id,
f"❌ **Cancelled:** Parent task failed",
parse_mode="markdown",
)
- except Exception as e:
- logger.error(f"Failed to update child status: {e}")
+ )
except asyncio.CancelledError:
logger.warning(f"HANDLER: Task cancelled for node {node_id}")
@@ -324,15 +328,15 @@ class ClaudeMessageHandler:
)
# Update status messages for all affected children
for child in affected[1:]:
- try:
- await self.platform.edit_message(
+ # Fire and forget these updates
+ self.platform.fire_and_forget(
+ self.platform.queue_edit_message(
child.incoming.chat_id,
child.status_message_id,
f"❌ **Cancelled:** Parent task was stopped",
parse_mode="markdown",
)
- except Exception as e:
- logger.error(f"Failed to update child status: {e}")
+ )
except Exception as e:
logger.error(
f"HANDLER: Task failed with exception: {type(e).__name__}: {e}"
@@ -348,15 +352,15 @@ class ClaudeMessageHandler:
)
# Update status messages for all affected children
for child in affected[1:]:
- try:
- await self.platform.edit_message(
+ # Fire and forget these updates
+ self.platform.fire_and_forget(
+ self.platform.queue_edit_message(
child.incoming.chat_id,
child.status_message_id,
f"❌ **Cancelled:** Parent task failed",
parse_mode="markdown",
)
- except Exception as e:
- logger.error(f"Failed to update child status: {e}")
+ )
finally:
logger.info(
f"HANDLER: _process_node completed for node {node_id}, errors={len(components['errors'])}"
@@ -463,22 +467,23 @@ class ClaudeMessageHandler:
# 3. Update UI for all cancelled nodes
for node in cancelled_nodes:
- try:
- await self.platform.edit_message(
+ # Fire and forget to avoid blocking the cleanup process
+ # Note: We don't await because we are in a massive loop potentially
+ self.platform.fire_and_forget(
+ self.platform.queue_edit_message(
node.incoming.chat_id,
node.status_message_id,
"⏹ **Stopped.**",
parse_mode="markdown",
)
- except Exception as e:
- logger.error(f"Failed to update status for cancelled node: {e}")
+ )
return len(cancelled_nodes)
async def _handle_stop_command(self, incoming: IncomingMessage) -> None:
"""Handle /stop command from messaging platform."""
count = await self.stop_all_tasks()
- await self.platform.send_message(
+ await self.platform.queue_send_message(
incoming.chat_id,
f"⏹ **Stopped.** Cancelled {count} pending or active requests.",
)
@@ -487,7 +492,7 @@ class ClaudeMessageHandler:
"""Handle /stats command."""
stats = self.cli_manager.get_stats()
tree_count = len(self.tree_queue._trees)
- await self.platform.send_message(
+ await self.platform.queue_send_message(
incoming.chat_id,
f"📊 **Stats**\n• Active CLI: {stats['active_sessions']}\n• Max CLI: {stats['max_sessions']}\n• Message Trees: {tree_count}",
)
diff --git a/messaging/telegram.py b/messaging/telegram.py
index 0a6f98b8..40004e6e 100644
--- a/messaging/telegram.py
+++ b/messaging/telegram.py
@@ -91,8 +91,8 @@ class TelegramPlatform(MessagingPlatform):
# Send startup notification
try:
- me_entity = await self._client.get_input_entity("me")
- await self.send_message(me_entity, "🚀 **Claude Code Proxy is online!**")
+ # Send message to yourself using the special 'me' entity or chat_id
+ await self.send_message("me", "🚀 **Claude Code Proxy is online!**")
except Exception as e:
logger.warning(f"Could not send startup message: {e}")
@@ -206,6 +206,10 @@ class TelegramPlatform(MessagingPlatform):
else:
await self._limiter.enqueue(_edit)
+ def fire_and_forget(self, task: Awaitable[Any]) -> None:
+ """Execute a coroutine without awaiting it."""
+ asyncio.create_task(task)
+
def on_message(
self,
handler: Callable[[IncomingMessage], Awaitable[None]],