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.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(auth): harden setup flow routing
cyhe0eca8dc9d1c
diff --git a/core/agent_auth_service.py b/core/agent_auth_service.pyindex 6393141ab..2b51843bc 100644--- a/core/agent_auth_service.py+++ b/core/agent_auth_service.py@@ -3,6 +3,7 @@from __future__ import annotationsimport asyncio+import errnoimport jsonimport loggingimport os@@ -456,10 +457,24 @@ class AgentAuthService:backend: str,) -> None:try:- while process.returncode is None:- chunk = await asyncio.to_thread(os.read, master_fd, 4096)+ os.set_blocking(master_fd, False)+ while True:+ try:+ chunk = os.read(master_fd, 4096)+ except BlockingIOError:+ if process.returncode is not None:+ break+ await asyncio.sleep(0.05)+ continue+ except OSError as err:+ if err.errno == errno.EIO:+ break+ raiseif not chunk:- break+ if process.returncode is not None:+ break+ await asyncio.sleep(0.05)+ continueawait self._handle_process_text(context, backend, chunk.decode("utf-8", errors="replace"))finally:try:@@ -650,11 +665,22 @@ class AgentAuthService:if backend_hint:return self._flows.get(f"{settings_key}:{backend_hint}")- for backend in ("claude", "codex", "opencode"):- flow = self._flows.get(f"{settings_key}:{backend}")- if flow is not None:- return flow- return None+ candidates = [+ flow+ for flow in self._flows.values()+ if flow.settings_key == settings_key and flow.initiator_user_id == context.user_id+ ]+ awaiting_candidates = [flow for flow in candidates if flow.awaiting_code]+ if awaiting_candidates:+ return awaiting_candidates[-1]++ code_capable_candidates = [+ flow for flow in candidates if flow.backend in {"claude", "opencode"} and flow.pty_master_fd is not None+ ]+ if code_capable_candidates:+ return code_capable_candidates[-1]++ return candidates[-1] if candidates else Noneasync def _terminate_flow(self, flow: AgentAuthFlow) -> None:if flow.waiter_task and not flow.waiter_task.done():diff --git a/tests/test_agent_auth_service.py b/tests/test_agent_auth_service.pyindex fedf2e37d..7a01d37aa 100644--- a/tests/test_agent_auth_service.py+++ b/tests/test_agent_auth_service.py@@ -1,9 +1,10 @@import asyncio+import osimport sysimport unittestfrom pathlib import Pathfrom types import SimpleNamespace-from unittest.mock import AsyncMock+from unittest.mock import AsyncMock, patchROOT = Path(__file__).resolve().parents[1]sys.path.insert(0, str(ROOT))@@ -247,6 +248,63 @@ class AgentAuthServiceTests(unittest.IsolatedAsyncioTestCase):self.assertIn("https://auth.openai.com/codex/device", message)self.assertIn("TRVY-E7DCU", message)+ async def test_submit_code_prefers_same_user_flow_waiting_for_code(self):+ controller = _StubController()+ service = AgentAuthService(controller)+ context = MessageContext(user_id="U1", channel_id="C1")+ done_task = asyncio.create_task(asyncio.sleep(0))+ await done_task+ codex_flow = AgentAuthFlow(+ flow_id="flow-codex",+ backend="codex",+ settings_key="C1",+ initiator_user_id="U1",+ context=context,+ process=SimpleNamespace(returncode=None),+ reader_task=done_task,+ waiter_task=done_task,+ )+ opencode_flow = AgentAuthFlow(+ flow_id="flow-opencode",+ backend="opencode",+ settings_key="C1",+ initiator_user_id="U1",+ context=context,+ process=SimpleNamespace(returncode=None),+ reader_task=done_task,+ waiter_task=done_task,+ pty_master_fd=17,+ awaiting_code=True,+ provider="opencode",+ )+ service._flows[codex_flow.flow_key] = codex_flow+ service._flows[opencode_flow.flow_key] = opencode_flow++ with patch("core.agent_auth_service.os.write") as mock_write:+ await service.submit_code(context, "secret-value")++ mock_write.assert_called_once_with(17, b"secret-value\n")+ self.assertFalse(opencode_flow.awaiting_code)+ self.assertIn("opencode", controller.im_client.sent_messages[0][1].lower())++ async def test_read_pty_output_exits_after_process_finishes_without_output(self):+ controller = _StubController()+ service = AgentAuthService(controller)+ context = MessageContext(user_id="U1", channel_id="C1")+ process = SimpleNamespace(returncode=None)+ master_fd, slave_fd = os.openpty()++ async def finish_process():+ await asyncio.sleep(0.05)+ process.returncode = 0+ os.close(slave_fd)++ finisher = asyncio.create_task(finish_process())+ try:+ await asyncio.wait_for(service._read_pty_output(process, master_fd, context, "claude"), timeout=0.5)+ finally:+ await finisher+class ClassifyAuthErrorTests(unittest.TestCase):def test_codex_401_requires_reset(self):