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

Remove max_cli_sessions — CLI session pool is now unbounded

Claude99f99fce9099
diff --git a/.env.example b/.env.example
index f4a023f0..6bc114c3 100644
--- a/.env.example
+++ b/.env.example
@@ -55,7 +55,6 @@ ALLOWED_DISCORD_CHANNELS=""
# Agent Config
CLAUDE_WORKSPACE="./agent_workspace"
-MAX_CLI_SESSIONS=10
ALLOWED_DIR=""
FAST_PREFIX_DETECTION=true
ENABLE_NETWORK_PROBE_MOCK=true
diff --git a/api/app.py b/api/app.py
index 5b220c79..c2f0320d 100644
--- a/api/app.py
+++ b/api/app.py
@@ -88,7 +88,6 @@ async def lifespan(app: FastAPI):
workspace_path=workspace,
api_url=api_url,
allowed_dirs=allowed_dirs,
- max_sessions=settings.max_cli_sessions,
plans_directory=plans_directory,
)
diff --git a/cli/manager.py b/cli/manager.py
index 6d43acdf..7770efca 100644
--- a/cli/manager.py
+++ b/cli/manager.py
@@ -27,7 +27,6 @@ class CLISessionManager:
workspace_path: str,
api_url: str,
allowed_dirs: list[str] | None = None,
- max_sessions: int = 10,
plans_directory: str | None = None,
):
"""
@@ -37,21 +36,19 @@ class CLISessionManager:
workspace_path: Working directory for CLI processes
api_url: API URL for the proxy
allowed_dirs: Directories the CLI is allowed to access
- max_sessions: Maximum concurrent sessions
plans_directory: Directory for Claude Code CLI plan files (passed via --settings)
"""
self.workspace = workspace_path
self.api_url = api_url
self.allowed_dirs = allowed_dirs or []
self.plans_directory = plans_directory
- self.max_sessions = max_sessions
self._sessions: dict[str, CLISession] = {}
self._pending_sessions: dict[str, CLISession] = {}
self._temp_to_real: dict[str, str] = {}
self._lock = asyncio.Lock()
- logger.info(f"CLISessionManager initialized (max_sessions={max_sessions})")
+ logger.info("CLISessionManager initialized")
async def get_or_create_session(
self, session_id: str | None = None
@@ -71,15 +68,6 @@ class CLISessionManager:
if lookup_id in self._pending_sessions:
return self._pending_sessions[lookup_id], lookup_id, False
- total_sessions = len(self._sessions) + len(self._pending_sessions)
- if total_sessions >= self.max_sessions:
- await self._cleanup_idle_sessions_unlocked()
- total_sessions = len(self._sessions) + len(self._pending_sessions)
- if total_sessions >= self.max_sessions:
- raise RuntimeError(
- f"Maximum concurrent sessions ({self.max_sessions}) reached."
- )
-
temp_id = session_id if session_id else f"pending_{uuid.uuid4().hex[:8]}"
new_session = CLISession(
@@ -132,15 +120,6 @@ class CLISessionManager:
return False
- async def _cleanup_idle_sessions_unlocked(self):
- """Clean up idle sessions (must hold lock)."""
- idle = [sid for sid, s in self._sessions.items() if not s.is_busy]
-
- for sid in idle[:3]:
- session = self._sessions.pop(sid)
- await session.stop()
- logger.debug(f"Cleaned up idle session: {sid}")
-
async def stop_all(self):
"""Stop all sessions."""
async with self._lock:
@@ -163,6 +142,5 @@ class CLISessionManager:
return {
"active_sessions": len(self._sessions),
"pending_sessions": len(self._pending_sessions),
- "max_sessions": self.max_sessions,
"busy_count": sum(1 for s in self._sessions.values() if s.is_busy),
}
diff --git a/config/settings.py b/config/settings.py
index 0b2a44e7..cde9b9dd 100644
--- a/config/settings.py
+++ b/config/settings.py
@@ -97,7 +97,6 @@ class Settings(BaseSettings):
)
claude_workspace: str = "./agent_workspace"
allowed_dir: str = ""
- max_cli_sessions: int = 10
# ==================== Server ====================
host: str = "0.0.0.0"
diff --git a/messaging/handler.py b/messaging/handler.py
index 3794f305..c5088d15 100644
--- a/messaging/handler.py
+++ b/messaging/handler.py
@@ -668,13 +668,6 @@ class ClaudeMessageHandler:
return self._format_status("🔄", "Continuing conversation...")
# New conversation
- stats = self.cli_manager.get_stats()
- if stats["active_sessions"] >= stats["max_sessions"]:
- return self._format_status(
- "⏳",
- "Waiting for slot...",
- f"({stats['active_sessions']}/{stats['max_sessions']})",
- )
return self._format_status("⏳", "Launching new Claude CLI instance...")
async def stop_all_tasks(self) -> int:
@@ -813,8 +806,6 @@ class ClaudeMessageHandler:
+ "\n"
+ ctx.escape_text(f"• Active CLI: {stats['active_sessions']}")
+ "\n"
- + ctx.escape_text(f"• Max CLI: {stats['max_sessions']}")
- + "\n"
+ ctx.escape_text(f"• Message Trees: {tree_count}"),
fire_and_forget=False,
message_thread_id=incoming.message_thread_id,
diff --git a/tests/api/test_app_lifespan_and_errors.py b/tests/api/test_app_lifespan_and_errors.py
index 64a4af77..c8a52de0 100644
--- a/tests/api/test_app_lifespan_and_errors.py
+++ b/tests/api/test_app_lifespan_and_errors.py
@@ -27,7 +27,6 @@ def test_create_app_provider_error_handler_returns_anthropic_format():
claude_workspace="./agent_workspace",
host="127.0.0.1",
port=8082,
- max_cli_sessions=1,
log_file="server.log",
)
with (
@@ -62,7 +61,6 @@ def test_create_app_general_exception_handler_returns_500():
claude_workspace="./agent_workspace",
host="127.0.0.1",
port=8082,
- max_cli_sessions=1,
log_file="server.log",
)
with (
@@ -95,7 +93,6 @@ def test_app_lifespan_sets_state_and_cleans_up(tmp_path, messaging_enabled):
claude_workspace=str(tmp_path / "data"),
host="127.0.0.1",
port=8082,
- max_cli_sessions=2,
log_file=str(tmp_path / "server.log"),
)
@@ -174,7 +171,6 @@ def test_app_lifespan_cleanup_continues_if_platform_stop_raises(tmp_path):
claude_workspace=str(tmp_path / "data"),
host="127.0.0.1",
port=8082,
- max_cli_sessions=1,
log_file=str(tmp_path / "server.log"),
)
@@ -228,7 +224,6 @@ def test_app_lifespan_messaging_import_error_no_crash(tmp_path, caplog):
claude_workspace=str(tmp_path / "data"),
host="127.0.0.1",
port=8082,
- max_cli_sessions=1,
log_file=str(tmp_path / "server.log"),
)
@@ -265,7 +260,6 @@ def test_app_lifespan_platform_start_exception_cleanup_still_runs(tmp_path):
claude_workspace=str(tmp_path / "data"),
host="127.0.0.1",
port=8082,
- max_cli_sessions=1,
log_file=str(tmp_path / "server.log"),
)
@@ -317,7 +311,6 @@ def test_app_lifespan_flush_pending_save_exception_warning_only(tmp_path):
claude_workspace=str(tmp_path / "data"),
host="127.0.0.1",
port=8082,
- max_cli_sessions=1,
log_file=str(tmp_path / "server.log"),
)
diff --git a/tests/cli/test_cli.py b/tests/cli/test_cli.py
index a5b20d9d..a22f9dd1 100644
--- a/tests/cli/test_cli.py
+++ b/tests/cli/test_cli.py
@@ -554,7 +554,6 @@ class TestCLISessionManager:
manager = CLISessionManager(
workspace_path="/tmp/test",
api_url="http://localhost:8082/v1",
- max_sessions=5,
)
session, sid, is_new = await manager.get_or_create_session()
@@ -589,10 +588,8 @@ class TestCLISessionManager:
manager = CLISessionManager(
workspace_path="/tmp/test",
api_url="http://localhost:8082/v1",
- max_sessions=10,
)
stats = manager.get_stats()
- assert stats["max_sessions"] == 10
assert stats["active_sessions"] == 0
assert stats["pending_sessions"] == 0
diff --git a/tests/cli/test_cli_manager_edge_cases.py b/tests/cli/test_cli_manager_edge_cases.py
index 0d1bfffc..b802e494 100644
--- a/tests/cli/test_cli_manager_edge_cases.py
+++ b/tests/cli/test_cli_manager_edge_cases.py
@@ -79,50 +79,6 @@ async def test_remove_session_active_removes_temp_mapping():
assert real is None
-async def test_get_or_create_session_cleans_up_idle_sessions_when_at_limit():
- from cli.manager import CLISessionManager
-
- manager = CLISessionManager(
- workspace_path="/tmp", api_url="http://x/v1", max_sessions=1
- )
-
- idle_session = MagicMock()
- idle_session.is_busy = False
- idle_session.stop = AsyncMock(return_value=True)
- manager._sessions["s1"] = idle_session
-
- with patch("cli.manager.CLISession") as mock_session_cls:
- new_session = MagicMock()
- new_session.is_busy = False
- new_session.stop = AsyncMock(return_value=True)
- mock_session_cls.return_value = new_session
-
- s2, sid2, is_new2 = await manager.get_or_create_session()
- assert s2 is new_session
- assert sid2.startswith("pending_")
- assert is_new2 is True
-
- idle_session.stop.assert_awaited_once()
-
-
-async def test_get_or_create_session_raises_when_max_sessions_reached_with_busy_sessions():
- from cli.manager import CLISessionManager
-
- manager = CLISessionManager(
- workspace_path="/tmp", api_url="http://x/v1", max_sessions=1
- )
-
- busy_session = MagicMock()
- busy_session.is_busy = True
- busy_session.stop = AsyncMock(return_value=True)
- manager._sessions["s1"] = busy_session
-
- with pytest.raises(RuntimeError):
- await manager.get_or_create_session()
-
-
@pytest.mark.asyncio
async def test_stop_all_handles_stop_exceptions():
from cli.manager import CLISessionManager
diff --git a/tests/config/test_config.py b/tests/config/test_config.py
index 758d4dd5..8796e535 100644
--- a/tests/config/test_config.py
+++ b/tests/config/test_config.py
@@ -25,7 +25,6 @@ class TestSettings:
assert isinstance(settings.provider_rate_window, int)
assert isinstance(settings.nim.temperature, float)
assert isinstance(settings.fast_prefix_detection, bool)
- assert isinstance(settings.max_cli_sessions, int)
def test_get_settings_cached(self):
"""Test get_settings returns cached instance."""
diff --git a/tests/conftest.py b/tests/conftest.py
index ca1a9621..291e894f 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -75,9 +75,7 @@ def mock_cli_manager():
manager.register_real_session_id = AsyncMock(return_value=True)
manager.stop_all = AsyncMock()
manager.remove_session = AsyncMock(return_value=True)
- manager.get_stats = MagicMock(
- return_value={"active_sessions": 0, "max_sessions": 5}
- )
+ manager.get_stats = MagicMock(return_value={"active_sessions": 0})
return manager
diff --git a/tests/messaging/test_handler.py b/tests/messaging/test_handler.py
index 745f1f3c..eb09041f 100644
--- a/tests/messaging/test_handler.py
+++ b/tests/messaging/test_handler.py
@@ -13,27 +13,12 @@ def handler(mock_platform, mock_cli_manager, mock_session_store):
return ClaudeMessageHandler(mock_platform, mock_cli_manager, mock_session_store)
-def test_get_initial_status_new_conversation_with_slot(handler):
- """New conversation when slots available returns launching message."""
- handler.cli_manager.get_stats.return_value = {
- "active_sessions": 0,
- "max_sessions": 5,
- }
+def test_get_initial_status_new_conversation(handler):
+ """New conversation always returns launching message."""
result = handler._get_initial_status(None, None)
assert "Launching" in result
-def test_get_initial_status_new_conversation_at_capacity(handler):
- """New conversation at capacity returns waiting message."""
- handler.cli_manager.get_stats.return_value = {
- "active_sessions": 5,
- "max_sessions": 5,
- }
- result = handler._get_initial_status(None, None)
- assert "Waiting" in result
- assert "5/5" in result
-
-
def test_get_initial_status_reply_tree_busy_queued(handler):
"""Reply to tree when busy returns queued message."""
mock_queue = MagicMock()
@@ -140,14 +125,13 @@ async def test_handle_message_stats_command(
handler, mock_platform, mock_cli_manager, incoming_message_factory
):
incoming = incoming_message_factory(text="/stats")
- mock_cli_manager.get_stats.return_value = {"active_sessions": 2, "max_sessions": 5}
+ mock_cli_manager.get_stats.return_value = {"active_sessions": 2}
await handler.handle_message(incoming)
mock_platform.queue_send_message.assert_called_once()
args, kwargs = mock_platform.queue_send_message.call_args
assert "Active CLI: 2" in args[1]
- assert "Max CLI: 5" in args[1]
assert kwargs["fire_and_forget"] is False
assert kwargs.get("message_thread_id") is None
diff --git a/tests/messaging/test_handler_markdown_and_status_edges.py b/tests/messaging/test_handler_markdown_and_status_edges.py
index 610f4436..ff377656 100644
--- a/tests/messaging/test_handler_markdown_and_status_edges.py
+++ b/tests/messaging/test_handler_markdown_and_status_edges.py
@@ -96,13 +96,8 @@ def test_get_initial_status_branches():
s2 = handler._get_initial_status(tree=object(), parent_node_id="p")
assert "Continuing" in s2
- cli_manager.get_stats.return_value = {"active_sessions": 10, "max_sessions": 10}
s3 = handler._get_initial_status(tree=None, parent_node_id=None)
- assert "Waiting for slot" in s3
-
- cli_manager.get_stats.return_value = {"active_sessions": 1, "max_sessions": 10}
- s4 = handler._get_initial_status(tree=None, parent_node_id=None)
- assert "Launching" in s4
+ assert "Launching" in s3
@pytest.mark.asyncio
@@ -149,7 +144,7 @@ async def test_process_node_session_limit_marks_error_and_updates_ui():
cli_manager = MagicMock()
cli_manager.get_or_create_session = AsyncMock(side_effect=RuntimeError("limit"))
- cli_manager.get_stats.return_value = {"active_sessions": 0, "max_sessions": 10}
+ cli_manager.get_stats.return_value = {"active_sessions": 0}
session_store = MagicMock()
handler = ClaudeMessageHandler(platform, cli_manager, session_store)
@@ -183,7 +178,7 @@ async def test_stop_all_tasks_saves_tree_for_cancelled_nodes():
cli_manager = MagicMock()
cli_manager.stop_all = AsyncMock()
- cli_manager.get_stats.return_value = {"active_sessions": 0, "max_sessions": 10}
+ cli_manager.get_stats.return_value = {"active_sessions": 0}
session_store = MagicMock()
handler = ClaudeMessageHandler(platform, cli_manager, session_store)
@@ -219,7 +214,7 @@ async def test_handle_message_reply_with_tree_but_no_parent_treated_as_new():
platform.queue_edit_message = AsyncMock()
cli_manager = MagicMock()
- cli_manager.get_stats.return_value = {"active_sessions": 0, "max_sessions": 10}
+ cli_manager.get_stats.return_value = {"active_sessions": 0}
session_store = MagicMock()
handler = ClaudeMessageHandler(platform, cli_manager, session_store)
@@ -273,7 +268,7 @@ async def test_update_ui_handles_transcript_render_exception():
return_value=(mock_session, "s1", False)
)
cli_manager.remove_session = AsyncMock()
- cli_manager.get_stats.return_value = {"active_sessions": 0, "max_sessions": 10}
+ cli_manager.get_stats.return_value = {"active_sessions": 0}
handler = ClaudeMessageHandler(platform, cli_manager, session_store)
handler.tree_queue = MagicMock()
@@ -307,7 +302,7 @@ async def test_handle_message_incoming_text_none_safe():
platform.queue_edit_message = AsyncMock()
cli_manager = MagicMock()
- cli_manager.get_stats.return_value = {"active_sessions": 0, "max_sessions": 10}
+ cli_manager.get_stats.return_value = {"active_sessions": 0}
session_store = MagicMock()
handler = ClaudeMessageHandler(platform, cli_manager, session_store)
@@ -391,7 +386,7 @@ async def test_handler_update_ui_edit_failure_does_not_crash():
return_value=(mock_session, "s1", False)
)
cli_manager.remove_session = AsyncMock()
- cli_manager.get_stats.return_value = {"active_sessions": 0, "max_sessions": 10}
+ cli_manager.get_stats.return_value = {"active_sessions": 0}
session_store = MagicMock()
handler = ClaudeMessageHandler(platform, cli_manager, session_store)