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 /stop not updating ui for all messages

Alishahryar134035dfc05d5
diff --git a/api/app.py b/api/app.py
index 1166162c..0a48af8a 100644
--- a/api/app.py
+++ b/api/app.py
@@ -100,6 +100,7 @@ async def lifespan(app: FastAPI):
# Store in app state for access in routes
app.state.messaging_platform = messaging_platform
+ app.state.message_handler = message_handler
app.state.cli_manager = cli_manager
yield
diff --git a/api/routes.py b/api/routes.py
index b8f28a20..72bdf8b7 100644
--- a/api/routes.py
+++ b/api/routes.py
@@ -244,9 +244,16 @@ async def health():
@router.post("/stop")
-async def stop_cli():
- """Stop all CLI sessions."""
- from cli import CLISessionManager
-
- # This will be properly injected when messaging layer is complete
- return {"status": "not_implemented"}
+async def stop_cli(request: Request):
+ """Stop all CLI sessions and pending tasks."""
+ handler = getattr(request.app.state, "message_handler", None)
+ if not handler:
+ # Fallback if messaging not initialized
+ cli_manager = getattr(request.app.state, "cli_manager", None)
+ if cli_manager:
+ await cli_manager.stop_all()
+ return {"status": "stopped", "source": "cli_manager"}
+ return HTTPException(status_code=503, detail="Messaging system not initialized")
+
+ count = await handler.stop_all_tasks()
+ return {"status": "stopped", "cancelled_count": count}
diff --git a/messaging/handler.py b/messaging/handler.py
index 65ab9bdf..5754dcd2 100644
--- a/messaging/handler.py
+++ b/messaging/handler.py
@@ -343,13 +343,37 @@ class ClaudeMessageHandler:
return f"⏳ **Waiting for slot...** ({stats['active_sessions']}/{stats['max_sessions']})"
return "⏳ **Launching new Claude CLI instance...**"
- async def _handle_stop_command(self, incoming: IncomingMessage) -> None:
- """Handle /stop command."""
- cancelled = await self.message_queue.cancel_all()
+ async def stop_all_tasks(self) -> int:
+ """
+ Stop all pending and in-progress tasks.
+ Updates status messages for all affected tasks.
+
+ Returns:
+ Number of cancelled messages.
+ """
+ cancelled_messages = await self.message_queue.cancel_all()
await self.cli_manager.stop_all()
+
+ # Update UI for all cancelled messages
+ for msg in cancelled_messages:
+ try:
+ await self.platform.edit_message(
+ msg.incoming.chat_id,
+ msg.status_message_id,
+ "⏹ **Stopped.**",
+ parse_mode="markdown",
+ )
+ except Exception as e:
+ logger.error(f"Failed to update status for cancelled message: {e}")
+
+ return len(cancelled_messages)
+
+ 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(
incoming.chat_id,
- f"⏹ **Stopped.** Cancelled {len(cancelled)} pending messages.",
+ f"⏹ **Stopped.** Cancelled {count} pending or active requests.",
)
async def _handle_stats_command(self, incoming: IncomingMessage) -> None: