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(opencode): add error handling and timeout to post-answer polling

yh c202496d84b5f
diff --git a/modules/agents/opencode_agent.py b/modules/agents/opencode_agent.py
index 41c8fb00b..e0ed8ba1b 100644
--- a/modules/agents/opencode_agent.py
+++ b/modules/agents/opencode_agent.py
@@ -1314,11 +1314,14 @@ class OpenCodeAgent(BaseAgent):
emitted_assistant_messages: set[str] = set()
poll_interval_seconds = 2.0
final_text: Optional[str] = None
+ max_poll_iterations = 300 # 10 minutes with 2s intervals
+ poll_count = 0
def _relative_path(path: str) -> str:
return self._to_relative_path(path, request.working_path)
- while True:
+ while poll_count < max_poll_iterations:
+ poll_count += 1
try:
messages = await server.list_messages(session_id, directory)
except Exception as poll_err:
@@ -1348,6 +1351,17 @@ class OpenCodeAgent(BaseAgent):
tool_state = part.get("state") or {}
tool_input = tool_state.get("input") or {}
+ # Check for nested questions - warn but continue
+ if (
+ tool_name == "question"
+ and tool_state.get("status") != "completed"
+ ):
+ logger.warning(
+ "Detected nested question after answer submission for %s, "
+ "continuing to process other messages",
+ session_id,
+ )
+
# Format and emit tool call
toolcall = self.im_client.formatter.format_toolcall(
tool_name,
@@ -1384,19 +1398,52 @@ class OpenCodeAgent(BaseAgent):
last_info = last_message.get("info", {})
last_id = last_info.get("id")
+ # Check for errors first
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"
):
- # Session completed
- final_text = self._extract_response_text(last_message)
- break
+ msg_error = last_info.get("error")
+ if msg_error:
+ 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.error(
+ "OpenCode error after question answer for %s: %s - %s",
+ session_id,
+ error_name,
+ error_msg[:200],
+ )
+ await self.controller.emit_agent_message(
+ request.context,
+ "notify",
+ f"OpenCode error after question answer: {error_name} - {error_msg[:500]}",
+ )
+ return
+
+ # No error, check for normal completion
+ if last_info.get("finish") != "tool-calls":
+ # Session completed
+ final_text = self._extract_response_text(last_message)
+ break
await asyncio.sleep(poll_interval_seconds)
+ # Check if timed out
+ if poll_count >= max_poll_iterations:
+ logger.warning(
+ "Post-answer polling timeout after %d iterations for %s",
+ poll_count,
+ session_id,
+ )
+ final_text = None # Will trigger warning message
+
# Emit final result
if final_text:
await self.emit_result_message(