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(core): guarantee terminal failure recovery
cyhba777d2aa580
diff --git a/core/backend_failure.py b/core/backend_failure.pyindex 6e3c25f59..9f13d63d1 100644--- a/core/backend_failure.py+++ b/core/backend_failure.py@@ -100,16 +100,33 @@ async def emit_backend_failure(metadata=notify_metadata,)+ async def settle_terminal_failure() -> None:+ await controller.emit_agent_message(+ context,+ "result",+ "",+ is_error=True,+ level="silent",+ output=terminal,+ terminal_error=error,+ )+auth_service = getattr(controller, "agent_auth_service", None)maybe_recover = getattr(auth_service, "maybe_emit_auth_recovery_message", None)- if callable(maybe_recover) and await maybe_recover(- context,- backend_name,- visible,- output=terminal,- terminal_error=error,- ):- return True+ if callable(maybe_recover):+ try:+ handled_auth = await maybe_recover(+ context,+ backend_name,+ visible,+ output=terminal,+ terminal_error=error,+ )+ except Exception:+ await settle_terminal_failure()+ raise+ if handled_auth:+ return Truetry:await controller.emit_agent_message(@@ -119,13 +136,5 @@ async def emit_backend_failure(output=notification,)finally:- await controller.emit_agent_message(- context,- "result",- "",- is_error=True,- level="silent",- output=terminal,- terminal_error=error,- )+ await settle_terminal_failure()return Falsediff --git a/tests/test_backend_failure.py b/tests/test_backend_failure.pyindex e20d87685..94e733717 100644--- a/tests/test_backend_failure.py+++ b/tests/test_backend_failure.py@@ -47,6 +47,36 @@ class BackendFailureTests(unittest.IsolatedAsyncioTestCase):self.assertTrue(handled_auth)controller.emit_agent_message.assert_not_awaited()+ async def test_settles_lifecycle_when_auth_recovery_delivery_raises(self) -> None:+ request = _request()+ controller = SimpleNamespace(+ agent_auth_service=SimpleNamespace(+ maybe_emit_auth_recovery_message=AsyncMock(+ side_effect=RuntimeError("button delivery unavailable")+ )+ ),+ emit_agent_message=AsyncMock(),+ )++ with self.assertRaisesRegex(RuntimeError, "button delivery unavailable"):+ await emit_backend_failure(+ controller,+ request.context,+ "codex",+ "401 Unauthorized",+ request=request,+ )++ controller.emit_agent_message.assert_awaited_once_with(+ request.context,+ "result",+ "",+ is_error=True,+ level="silent",+ output=request.output,+ terminal_error="401 Unauthorized",+ )+async def test_separates_notify_from_terminal_settlement(self) -> None:request = _request()controller = SimpleNamespace(diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsxindex 8d2b264a9..59d3ccc7e 100644--- a/ui/src/components/workbench/ChatPage.tsx+++ b/ui/src/components/workbench/ChatPage.tsx@@ -11,7 +11,7 @@ import { useRegisterComposerTarget, type ComposerInsertTarget } from '../../contimport type { SessionRuntimeState, VaultRequest, VibeAgentBrief, WorkbenchMessage, WorkbenchSession } from '../../context/ApiContext';import { apiFetch } from '../../lib/apiFetch';import { normalizeChatMessageFontSize } from '../../lib/chatDisplay';-import { isNotifyMessageType } from '../../lib/chatMessageTypes';+import { isNotifyMessageType, isTerminalAgentMessage } from '../../lib/chatMessageTypes';import { useIosKeyboardInset } from '../../lib/useIosKeyboardInset';import { isProxyMediaUrl } from '../../lib/mediaProxy';import { localPath, type ShowPageLinkInfo } from '../../lib/showPageLinks';@@ -2032,12 +2032,13 @@ const Transcript: React.FC<TranscriptProps> = ({// The reply arrives atomically as a persisted ``result`` row (no streaming// card), so the thinking bubble shows for the whole gap between send and// reply. Hide it the moment the last row is a fresh agent terminal — a- // successful ``result`` OR a failed ``error`` both end the turn.- const lastIsAgentResult =- messages.length > 0 &&- messages[messages.length - 1].author === 'agent' &&- (messages[messages.length - 1].type === 'result' || messages[messages.length - 1].type === 'error');- const showThinking = working && !lastIsAgentResult;+ // successful ``result``, a legacy ``error``, or a structured backend-failure+ // ``notify`` all end the visible response. ``working`` itself still settles+ // only from turn.end or the authoritative turn-state poll, so a late row from+ // an older Turn cannot clear Stop for a newer one.+ const lastIsAgentTerminal =+ messages.length > 0 && isTerminalAgentMessage(messages[messages.length - 1]);+ const showThinking = working && !lastIsAgentTerminal;const empty = messages.length === 0 && !working;// Capture the topmost (partly) visible row as the restore anchor. Viewport-diff --git a/ui/src/lib/chatMessageTypes.test.ts b/ui/src/lib/chatMessageTypes.test.tsindex 3dbd09d78..9a3d0bc04 100644--- a/ui/src/lib/chatMessageTypes.test.ts+++ b/ui/src/lib/chatMessageTypes.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from 'vitest';-import { isNotifyMessageType } from './chatMessageTypes';+import { isNotifyMessageType, isTerminalAgentMessage } from './chatMessageTypes';describe('isNotifyMessageType', () => {it('renders current and legacy failure rows as notifications', () => {@@ -13,3 +13,29 @@ describe('isNotifyMessageType', () => {expect(isNotifyMessageType('assistant')).toBe(false);});});++describe('isTerminalAgentMessage', () => {+ it('recognizes results, legacy errors, and structured backend failures', () => {+ expect(isTerminalAgentMessage({ author: 'agent', type: 'result' })).toBe(true);+ expect(isTerminalAgentMessage({ author: 'agent', type: 'error' })).toBe(true);+ expect(+ isTerminalAgentMessage({+ author: 'agent',+ type: 'notify',+ metadata: { event: 'backend_failure' },+ }),+ ).toBe(true);+ });++ it('keeps ordinary notifications and user rows nonterminal', () => {+ expect(isTerminalAgentMessage({ author: 'agent', type: 'notify' })).toBe(false);+ expect(+ isTerminalAgentMessage({+ author: 'agent',+ type: 'notify',+ metadata: { event: 'activity_completed' },+ }),+ ).toBe(false);+ expect(isTerminalAgentMessage({ author: 'user', type: 'result' })).toBe(false);+ });+});diff --git a/ui/src/lib/chatMessageTypes.ts b/ui/src/lib/chatMessageTypes.tsindex 947e58270..376ab9c9a 100644--- a/ui/src/lib/chatMessageTypes.ts+++ b/ui/src/lib/chatMessageTypes.ts@@ -1,2 +1,14 @@export const isNotifyMessageType = (type: string): boolean =>type === 'notify' || type === 'error';++type TerminalMessageCandidate = {+ author: string;+ type: string;+ metadata?: Record<string, unknown> | null;+};++export const isTerminalAgentMessage = (message: TerminalMessageCandidate): boolean =>+ message.author === 'agent' &&+ (message.type === 'result' ||+ message.type === 'error' ||+ (message.type === 'notify' && message.metadata?.event === 'backend_failure'));