Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(session): clean up Claude buffer error sessions

cyh90f6b5195683
diff --git a/core/handlers/session_handler.py b/core/handlers/session_handler.py
index b39b1894e..deb6fcf7a 100644
--- a/core/handlers/session_handler.py
+++ b/core/handlers/session_handler.py
@@ -14,6 +14,7 @@ from modules.claude_sdk_compat import (
ClaudeAgentOptions,
ClaudeSDKClient,
PermissionResultAllow,
+ is_claude_sdk_buffer_error,
)
from modules.agents.native_sessions.base import build_resume_preview
from core.avibe_cloud import avibe_cloud_url_available
@@ -1085,9 +1086,12 @@ class SessionHandler(BaseHandler):
context,
self._get_formatter(context).format_error(self._t("error.sessionReset")),
)
- # TODO: Consider treating Claude SDK oversized JSON buffer failures as
- # broken sessions once the recovery behavior is validated in production.
- elif "Session is broken" in error_msg or "Connection closed" in error_msg or "Connection lost" in error_msg:
+ elif (
+ "Session is broken" in error_msg
+ or "Connection closed" in error_msg
+ or "Connection lost" in error_msg
+ or is_claude_sdk_buffer_error(error)
+ ):
logger.error(f"Session {composite_key} is broken - cleaning up")
await self.cleanup_session(composite_key, current_receiver_task=asyncio.current_task())
diff --git a/tests/test_session_handler_base_id.py b/tests/test_session_handler_base_id.py
index ce4337a1c..910c2dcf3 100644
--- a/tests/test_session_handler_base_id.py
+++ b/tests/test_session_handler_base_id.py
@@ -347,14 +347,14 @@ def test_claude_session_not_found_error_is_reported_without_cleanup() -> None:
assert "/tmp/other" in message
-def test_claude_sdk_buffer_error_is_reported_without_cleanup_for_now() -> None:
+def test_claude_sdk_buffer_error_cleans_up_broken_session() -> None:
controller = _Controller(platform="slack", dm_threads=False)
controller.im_client = _FakeIM()
handler = SessionHandler(controller)
cleanup_calls = []
- async def _cleanup_session(composite_key: str) -> None:
- cleanup_calls.append(composite_key)
+ async def _cleanup_session(composite_key: str, *, current_receiver_task=None) -> None:
+ cleanup_calls.append((composite_key, current_receiver_task))
handler.cleanup_session = _cleanup_session
context = MessageContext(user_id="U123", channel_id="C123", platform="slack")
@@ -367,7 +367,10 @@ def test_claude_sdk_buffer_error_is_reported_without_cleanup_for_now() -> None:
)
)
- assert cleanup_calls == []
+ assert len(cleanup_calls) == 1
+ cleanup_key, cleanup_task = cleanup_calls[0]
+ assert cleanup_key == "slack_C123:/tmp/workdir"
+ assert cleanup_task is not None
assert len(controller.im_client.sent_messages) == 1
_, message = controller.im_client.sent_messages[0]
- assert "JSON message exceeded maximum buffer size" in message
+ assert message == "ERR:Connection to Claude was lost. Please try your message again."