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): fallback text extraction when last message has no text parts

cyh90f395f4a49d
diff --git a/modules/agents/opencode/message_processor.py b/modules/agents/opencode/message_processor.py
index 1c0c5fcdd..49df4babc 100644
--- a/modules/agents/opencode/message_processor.py
+++ b/modules/agents/opencode/message_processor.py
@@ -25,8 +25,11 @@ class OpenCodeMessageProcessorMixin:
if not text_parts and parts:
part_types = [p.get("type") for p in parts]
- logger.debug(
- f"OpenCode response has no text parts; part types: {part_types}"
+ msg_id = response.get("info", {}).get("id", "unknown")
+ logger.warning(
+ "OpenCode message %s has no text parts; part types: %s",
+ msg_id,
+ part_types,
)
return "\n\n".join(text_parts).strip()
diff --git a/modules/agents/opencode/poll_loop.py b/modules/agents/opencode/poll_loop.py
index 0fac5b770..c7ba7c51e 100644
--- a/modules/agents/opencode/poll_loop.py
+++ b/modules/agents/opencode/poll_loop.py
@@ -20,6 +20,37 @@ class OpenCodePollLoop:
self._agent = agent
self._question_handler = question_handler
+ def _fallback_extract_text(
+ self,
+ messages: list[Dict[str, Any]],
+ baseline_message_ids: set[str],
+ last_message_id: Optional[str] = None,
+ ) -> Optional[str]:
+ """Walk backward through messages to find response text.
+
+ When the last completed message has no text parts (e.g. it only
+ contains tool calls or step markers), search earlier messages for
+ the actual assistant response text.
+ """
+ for message in reversed(messages):
+ info = message.get("info", {})
+ msg_id = info.get("id")
+ if not msg_id or msg_id in baseline_message_ids:
+ continue
+ if info.get("role") != "assistant":
+ continue
+ if msg_id == last_message_id:
+ continue # already tried this one
+ text = self._agent._extract_response_text(message)
+ if text:
+ logger.info(
+ "Fallback: found response text in message %s instead of last message %s",
+ msg_id,
+ last_message_id,
+ )
+ return text
+ return None
+
async def run_prompt_poll(
self,
request: AgentRequest,
@@ -231,6 +262,18 @@ class OpenCodePollLoop:
if not msg_error:
error_retry_count = 0
final_text = self._agent._extract_response_text(last_message)
+ if not final_text:
+ logger.warning(
+ "Last message %s has no text parts (finish=%s); "
+ "searching earlier messages for response text",
+ last_id,
+ last_info.get("finish"),
+ )
+ final_text = self._fallback_extract_text(
+ messages,
+ baseline_message_ids,
+ last_message_id=last_id,
+ )
break
await asyncio.sleep(poll_interval_seconds)
@@ -396,6 +439,18 @@ class OpenCodePollLoop:
if not msg_error:
error_retry_count = 0
final_text = self._agent._extract_response_text(last_message)
+ if not final_text:
+ logger.warning(
+ "Restored poll: last message %s has no text parts (finish=%s); "
+ "searching earlier messages for response text",
+ last_info.get("id"),
+ last_info.get("finish"),
+ )
+ final_text = self._fallback_extract_text(
+ messages,
+ baseline_message_ids,
+ last_message_id=last_info.get("id"),
+ )
break
await asyncio.sleep(poll_interval_seconds)