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.

feat(opencode): add error retry mechanism for LLM stream errors

cyhhao21e6d3b1021c
diff --git a/config/v2_compat.py b/config/v2_compat.py
index ba1f37e06..89cbb5f06 100644
--- a/config/v2_compat.py
+++ b/config/v2_compat.py
@@ -27,6 +27,7 @@ class OpenCodeCompatConfig:
binary: str
port: int
request_timeout_seconds: int
+ error_retry_limit: int = 1 # Max retries on LLM stream errors (0 = no retry)
@dataclass
@@ -59,6 +60,7 @@ def to_app_config(v2: V2Config) -> AppCompatConfig:
binary=v2.agents.opencode.cli_path,
port=4096,
request_timeout_seconds=60,
+ error_retry_limit=v2.agents.opencode.error_retry_limit,
)
slack = SlackConfig(**v2.slack.__dict__)
return AppCompatConfig(
diff --git a/config/v2_config.py b/config/v2_config.py
index 00640eec5..4401aef0e 100644
--- a/config/v2_config.py
+++ b/config/v2_config.py
@@ -50,6 +50,7 @@ class OpenCodeConfig:
default_agent: Optional[str] = None
default_model: Optional[str] = None
default_reasoning_effort: Optional[str] = None
+ error_retry_limit: int = 1 # Max retries on LLM stream errors (0 = no retry)
@dataclass
diff --git a/modules/agents/opencode_agent.py b/modules/agents/opencode_agent.py
index d9acee28a..e09beccfc 100644
--- a/modules/agents/opencode_agent.py
+++ b/modules/agents/opencode_agent.py
@@ -1502,6 +1502,11 @@ class OpenCodeAgent(BaseAgent):
poll_interval_seconds = 2.0
final_text: Optional[str] = None
+ # Error retry tracking
+ error_retry_count = 0
+ error_retry_limit = getattr(self.opencode_config, "error_retry_limit", 1)
+ last_error_message_id: Optional[str] = None
+
def _relative_path(path: str) -> str:
return self._to_relative_path(path, request.working_path)
@@ -1516,13 +1521,14 @@ class OpenCodeAgent(BaseAgent):
if poll_iter % 5 == 0:
last_info = messages[-1].get("info", {}) if messages else {}
logger.info(
- "OpenCode poll heartbeat %s iter=%s last=%s role=%s completed=%s finish=%s",
+ "OpenCode poll heartbeat %s iter=%s last=%s role=%s completed=%s finish=%s error=%s",
session_id,
poll_iter,
last_info.get("id"),
last_info.get("role"),
bool(last_info.get("time", {}).get("completed")),
last_info.get("finish"),
+ bool(last_info.get("error")),
)
except Exception as poll_err:
logger.warning(f"Failed to poll OpenCode messages: {poll_err}")
@@ -1971,15 +1977,77 @@ class OpenCodeAgent(BaseAgent):
last_message = messages[-1]
last_info = last_message.get("info", {})
last_id = last_info.get("id")
+
+ # Check for error in completed message
if (
last_id
and last_id not in baseline_message_ids
and last_info.get("role") == "assistant"
and last_info.get("time", {}).get("completed")
- and last_info.get("finish") != "tool-calls"
):
- final_text = self._extract_response_text(last_message)
- break
+ msg_error = last_info.get("error")
+ if msg_error and last_id != last_error_message_id:
+ # New error detected
+ last_error_message_id = last_id
+ error_name = msg_error.get("name", "UnknownError")
+ error_data = msg_error.get("data", {})
+ error_msg = error_data.get("message", "") if isinstance(error_data, dict) else str(error_data)
+
+ logger.warning(
+ "OpenCode message error detected for %s: %s - %s (retry %d/%d)",
+ session_id,
+ error_name,
+ error_msg[:200],
+ error_retry_count,
+ error_retry_limit,
+ )
+
+ if error_retry_count < error_retry_limit:
+ error_retry_count += 1
+ logger.info(
+ "Auto-retrying OpenCode session %s with 'continue' (attempt %d/%d)",
+ session_id,
+ error_retry_count,
+ error_retry_limit,
+ )
+
+ # Send "continue" to retry
+ try:
+ await server.prompt_async(
+ session_id=session_id,
+ directory=request.working_path,
+ text="continue",
+ agent=agent_to_use,
+ model=model_dict,
+ reasoning_effort=reasoning_effort,
+ )
+ # Continue polling for new messages
+ await asyncio.sleep(poll_interval_seconds)
+ continue
+ except Exception as retry_err:
+ logger.error(
+ "Failed to send retry 'continue' for %s: %s",
+ session_id,
+ retry_err,
+ )
+ # Fall through to report error
+
+ # Retry limit reached or retry failed, report error to user
+ await self.controller.emit_agent_message(
+ request.context,
+ "notify",
+ f"OpenCode error: {error_name} - {error_msg[:500]}",
+ )
+ final_text = None
+ break
+
+ # No error, check for normal completion
+ if last_info.get("finish") != "tool-calls":
+ # Reset retry count on successful non-error message
+ if not msg_error:
+ error_retry_count = 0
+ final_text = self._extract_response_text(last_message)
+ break
await asyncio.sleep(poll_interval_seconds)
diff --git a/ui/src/components/Dashboard.tsx b/ui/src/components/Dashboard.tsx
index ad1941ed4..8bdfa7c03 100644
--- a/ui/src/components/Dashboard.tsx
+++ b/ui/src/components/Dashboard.tsx
@@ -142,9 +142,11 @@ export const Dashboard: React.FC = () => {
return (
<div className="max-w-5xl mx-auto space-y-8">
- <header>
- <h2 className="text-3xl font-display font-bold mb-2 text-text">{t('dashboard.title')}</h2>
- <p className="text-muted">{t('dashboard.subtitle')}</p>
+ <header className="flex items-center justify-between">
+ <div>
+ <h2 className="text-3xl font-display font-bold mb-2 text-text">{t('dashboard.title')}</h2>
+ <p className="text-muted">{t('dashboard.subtitle')}</p>
+ </div>
</header>
{/* Overview Card */}
@@ -317,6 +319,40 @@ export const Dashboard: React.FC = () => {
<option value="message">{t('dashboard.ackMessage')}</option>
</select>
</div>
+ <div className="flex justify-between items-center">
+ <span className="text-muted flex items-center gap-1">
+ {t('dashboard.errorRetryLimit')}
+ <span className="relative group">
+ <Info size={12} className="text-muted/50 cursor-help" />
+ <span className="absolute bottom-full left-1/2 -translate-x-1/2 mb-1 px-2 py-1 bg-text text-bg text-xs rounded whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-10 w-48">
+ {t('dashboard.errorRetryLimitHint')}
+ </span>
+ </span>
+ </span>
+ <input
+ type="number"
+ min={0}
+ max={10}
+ value={config.agents?.opencode?.error_retry_limit ?? 1}
+ onChange={(e) => {
+ const limit = Math.max(0, Math.min(10, Number(e.target.value) || 0));
+ setSettingsMessage(null);
+ const newConfig = {
+ ...config,
+ agents: {
+ ...(config.agents || {}),
+ opencode: {
+ ...(config.agents?.opencode || {}),
+ error_retry_limit: limit,
+ },
+ },
+ };
+ setConfig(newConfig);
+ autoSaveMessageConfig(newConfig);
+ }}
+ className="w-16 bg-neutral-100 border border-border rounded px-2 py-1 text-xs font-mono text-center"
+ />
+ </div>
<div className="flex justify-between items-center">
<span className="text-muted">{t('dashboard.allowedChannels')}</span>
<Link to="/channels" className="text-xs text-accent hover:underline font-medium">{t('common.manageChannels')}</Link>
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index ff1e44f34..d6cec6861 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -65,16 +65,47 @@
"slackConfig": {
"title": "Slack Configuration",
"saasDescription": "Authorize the official Slack app and wait for workspace binding.",
- "selfHostDescription": "Provide bot and app tokens for Socket Mode.",
+ "selfHostDescription": "Create a Slack app and configure tokens for Socket Mode.",
"oauthPrompt": "Open OAuth in your browser to authorize Vibe Remote with your Slack workspace.",
"openSlackOAuth": "Open Slack OAuth",
"afterAuth": "After authorization, return here to continue.",
"botToken": "Bot User OAuth Token",
"botTokenHint": "Starts with",
"appToken": "App-Level Token",
+ "appTokenHint": "Starts with",
"validateTokens": "Validate Tokens",
- "tokenValidated": "Success: Token Validated",
- "authFailed": "Auth failed"
+ "tokenValidated": "Tokens validated",
+ "authFailed": "Validation failed",
+ "tip": "Tip",
+ "important": "Important",
+ "viewManifest": "View manifest JSON",
+ "step1Title": "Create Slack App",
+ "step1Description": "Click the button below to create a new Slack app with pre-configured permissions.",
+ "step1Tip": "The manifest will be auto-filled. Just select your workspace and click Create.",
+ "createSlackApp": "Create Slack App",
+ "copyManifest": "Copy Manifest",
+ "copied": "Copied!",
+ "step2Title": "Get Bot Token",
+ "step2Description": "Install the app to your workspace and copy the Bot Token.",
+ "step2Item1": "In your new app, go to 'OAuth & Permissions'",
+ "step2Item2": "Click 'Install to Workspace'",
+ "step2Item3": "Authorize the app",
+ "step2Item4": "Copy the 'Bot User OAuth Token'",
+ "step3Title": "Get App Token",
+ "step3Description": "Generate an App-Level Token for Socket Mode connection.",
+ "step3Item1": "Go to 'Basic Information'",
+ "step3Item2": "Scroll to 'App-Level Tokens'",
+ "step3Item3": "Click 'Generate Token and Scopes'",
+ "step3Item4": "Name it (e.g., 'socket-mode')",
+ "step3Item5": "Add 'connections:write' scope and click Generate",
+ "step3Warning": "Keep this token secure. It provides full Socket Mode access.",
+ "step4Title": "Validate & Finish",
+ "step4Description": "Validate your tokens to ensure everything is configured correctly.",
+ "inviteBotTitle": "Invite the bot to channels:",
+ "step4Item1": "Open a Slack channel",
+ "step4Item2": "Type /invite @Vibe Remote",
+ "step4Item3": "The bot will now receive messages from this channel",
+ "step4Tip": "You can also right-click a channel and select 'Add apps'."
},
"agentDetection": {
"title": "Agent Configuration",
@@ -134,8 +165,10 @@
"requireMentionHint": "Bot only responds when @mentioned",
"ackMode": "Ack Mode",
"ackModeHint": "How bot acknowledges received messages",
- "ackReaction": "Reaction",
+ "ackReaction": "👀 Reaction",
"ackMessage": "Message",
+ "errorRetryLimit": "Error Retry Limit",
+ "errorRetryLimitHint": "Auto-retry with 'continue' when LLM stream errors occur (0 = no retry)",
"allowedChannels": "Allowed Channels",
"consoleServer": "Console Server",
"host": "Host",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index f6d3e7c22..0bd90f113 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -65,16 +65,47 @@
"slackConfig": {
"title": "Slack 配置",
"saasDescription": "授权官方 Slack 应用并等待工作区绑定",
- "selfHostDescription": "提供用于 Socket Mode 的 Bot 和 App 令牌",
+ "selfHostDescription": "创建 Slack 应用并配置 Socket Mode 所需的令牌",
"oauthPrompt": "在浏览器中打开 OAuth 以授权 Vibe Remote 访问您的 Slack 工作区",
"openSlackOAuth": "打开 Slack OAuth",
"afterAuth": "授权后返回此处继续",
"botToken": "Bot 用户 OAuth 令牌",
"botTokenHint": "以此开头",
"appToken": "应用级别令牌",
+ "appTokenHint": "以此开头",
"validateTokens": "验证令牌",
- "tokenValidated": "成功:令牌已验证",
- "authFailed": "认证失败"
+ "tokenValidated": "令牌验证成功",
+ "authFailed": "验证失败",
+ "tip": "提示",
+ "important": "重要",
+ "viewManifest": "查看配置清单 JSON",
+ "step1Title": "创建 Slack 应用",
+ "step1Description": "点击下方按钮,使用预配置的权限创建新的 Slack 应用。",
+ "step1Tip": "配置清单会自动填充,只需选择工作区并点击创建。",
+ "createSlackApp": "创建 Slack 应用",
+ "copyManifest": "复制配置清单",
+ "copied": "已复制!",
+ "step2Title": "获取 Bot 令牌",
+ "step2Description": "将应用安装到工作区并复制 Bot 令牌。",
+ "step2Item1": "在新应用中,进入「OAuth & Permissions」",
+ "step2Item2": "点击「Install to Workspace」",
+ "step2Item3": "授权应用",
+ "step2Item4": "复制「Bot User OAuth Token」",
+ "step3Title": "获取 App 令牌",
+ "step3Description": "生成用于 Socket Mode 连接的应用级别令牌。",
+ "step3Item1": "进入「Basic Information」",
+ "step3Item2": "滚动到「App-Level Tokens」",
+ "step3Item3": "点击「Generate Token and Scopes」",
+ "step3Item4": "输入名称(如 'socket-mode')",
+ "step3Item5": "添加「connections:write」权限范围,然后点击生成",
+ "step3Warning": "请妥善保管此令牌,它提供完整的 Socket Mode 访问权限。",
+ "step4Title": "验证并完成",
+ "step4Description": "验证令牌以确保配置正确。",
+ "inviteBotTitle": "邀请机器人加入频道:",
+ "step4Item1": "打开一个 Slack 频道",
+ "step4Item2": "输入 /invite @Vibe Remote",
+ "step4Item3": "机器人现在可以接收此频道的消息了",
+ "step4Tip": "也可以右键点击频道,选择「添加应用」。"
},
"agentDetection": {
"title": "Agent 配置",
@@ -134,8 +165,10 @@
"requireMentionHint": "机器人仅在被 @提及时响应",
"ackMode": "确认模式",
"ackModeHint": "机器人如何确认收到的消息",
- "ackReaction": "表情回应",
+ "ackReaction": "👀 表情回应",
"ackMessage": "消息回复",
+ "errorRetryLimit": "错误重试次数",
+ "errorRetryLimitHint": "当 LLM 流式响应出错时,自动发送 'continue' 重试(0 = 不重试)",
"allowedChannels": "允许的频道",
"consoleServer": "控制台服务器",
"host": "主机",