Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(chat): render failed turns as error cards

Steven Enamakelf61d8a2e22fe
diff --git a/app/src/components/assistant-ui/elements/error-state.tsx b/app/src/components/assistant-ui/elements/error-state.tsx
index 6387c92769..3a9883de88 100644
--- a/app/src/components/assistant-ui/elements/error-state.tsx
+++ b/app/src/components/assistant-ui/elements/error-state.tsx
@@ -65,7 +65,7 @@ export function ErrorState({
<CircleAlertIcon className="mt-0.5 size-4 shrink-0 text-red-500/80" />
<div>
<p className="font-medium text-red-600 dark:text-red-400">{title}</p>
- <p className="mt-0.5 text-[13px] leading-snug text-red-600/60 dark:text-red-400/60">
+ <p className="mt-0.5 whitespace-pre-wrap text-[13px] leading-snug text-red-600/60 dark:text-red-400/60">
{detail}
</p>
</div>
diff --git a/app/src/components/assistant-ui/thread.tsx b/app/src/components/assistant-ui/thread.tsx
index 70eebedf3e..63dce0d85d 100644
--- a/app/src/components/assistant-ui/thread.tsx
+++ b/app/src/components/assistant-ui/thread.tsx
@@ -1309,10 +1309,9 @@ const ComposerAction: FC<{
};
/**
- * The runtime's own error boundary for a message (`message.status.type ===
- * 'error'` — a throw from `onNew`/`onEdit`/`onReload`, not a `chat_error`
- * socket event, which instead lands as its own assistant reply — see
- * `ChatRuntimeProvider`'s `onError` handler).
+ * The runtime's error presentation for a failed message. The external-store
+ * projection marks persisted `chat_error` rows as incomplete/error, so they
+ * use this same card as errors raised directly by assistant-ui.
*
* `useMessageError`/`useActionBarReload` come straight from
* `@assistant-ui/core/react` rather than through a primitive: there is no
diff --git a/app/src/features/conversations/aui/ChatErrorNotice.test.tsx b/app/src/features/conversations/aui/ChatErrorNotice.test.tsx
index b0b30e08e9..744b376d86 100644
--- a/app/src/features/conversations/aui/ChatErrorNotice.test.tsx
+++ b/app/src/features/conversations/aui/ChatErrorNotice.test.tsx
@@ -7,6 +7,7 @@ import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { Thread } from '../../../components/assistant-ui/thread';
+import { toThreadMessageLike } from '../../../providers/assistantUiMessages';
import { CHAT_ERROR_METADATA_KEY } from '../../../store/threadSlice';
/**
@@ -84,4 +85,23 @@ describe('ChatErrorNotice', () => {
expect(screen.queryByTestId('assistant-ui-guardrail-notice')).not.toBeInTheDocument();
});
+
+ it('renders a persisted chat failure as an error card without legacy link markup', () => {
+ const message = toThreadMessageLike({
+ id: 'failed-turn',
+ sender: 'agent',
+ type: 'text',
+ content:
+ 'Something went wrong. Please try again.\n<openhuman-link path="community/discord-report">Report on Discord</openhuman-link>',
+ createdAt: '2026-01-01T00:00:00.000Z',
+ extraMetadata: { [CHAT_ERROR_METADATA_KEY]: { errorType: 'inference' } },
+ });
+
+ render(<Harness messages={[message]} />);
+
+ const card = screen.getByRole('alert');
+ expect(card).toHaveAttribute('data-slot', 'error-state');
+ expect(card).toHaveTextContent('Something went wrong. Please try again.');
+ expect(card).not.toHaveTextContent('openhuman-link');
+ });
});
diff --git a/app/src/providers/ChatRuntimeProvider.tsx b/app/src/providers/ChatRuntimeProvider.tsx
index 1fa18c1579..287073660a 100644
--- a/app/src/providers/ChatRuntimeProvider.tsx
+++ b/app/src/providers/ChatRuntimeProvider.tsx
@@ -106,8 +106,6 @@ import { AssistantUiRuntimeProvider } from './AssistantUiRuntimeProvider';
import { isProactiveConversationSurface, proactiveThreadPins } from './proactiveThreadPins';
const logChatRuntime = debug('openhuman:chat-runtime');
-const USER_FACING_AGENT_ERROR_MESSAGE =
- 'Something went wrong. Please try again.\nThis error has been reported. You can also report it on Discord.\n<openhuman-link path="community/discord-report">Report on Discord</openhuman-link>';
const SEGMENT_DELIVERY_TTL_MS = 5 * 60 * 1000;
const MAX_SEGMENT_DELIVERIES = 100;
@@ -1798,9 +1796,13 @@ const ChatRuntimeProvider = ({ children }: { children: React.ReactNode }) => {
segmentDeliveryKey(event.thread_id, event.request_id)
);
if (event.error_type !== 'cancelled') {
- const errorContent = event.message || USER_FACING_AGENT_ERROR_MESSAGE;
+ const errorContent = event.message || '';
void dispatch(
- addInferenceResponse({ content: errorContent, threadId: event.thread_id })
+ addInferenceResponse({
+ content: errorContent,
+ threadId: event.thread_id,
+ extraMetadata: chatErrorExtraMetadata(event),
+ })
);
requestUsageRefresh();
}
@@ -1835,8 +1837,9 @@ const ChatRuntimeProvider = ({ children }: { children: React.ReactNode }) => {
// upstream provider error appended as a `> quote` block (secret-scrubbed and
// length-capped server-side via with_provider_detail()/sanitize_api_error()), so
// surfacing it tells the user *why* the turn failed instead of a blanket apology.
- // The hardcoded constant is only a last-resort fallback for an empty/missing message.
- const errorContent = event.message || USER_FACING_AGENT_ERROR_MESSAGE;
+ // An empty message still becomes an error-status row; assistant-ui
+ // supplies its own fallback in the error card.
+ const errorContent = event.message || '';
// A core-owned failure carries a deterministic id, so dedupe on that
// rather than on the text. Two runs can fail with byte-identical
// content — the same upstream provider message, or the generic
diff --git a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
index 3d022feec7..a81b8c8bdc 100644
--- a/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
+++ b/app/src/providers/__tests__/ChatRuntimeProvider.test.tsx
@@ -433,6 +433,33 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
expect(after.streamingAssistantByThread['t-par']?.content).toBe('P');
});
+ it('marks a failed parallel turn for the assistant-ui error card', async () => {
+ const listeners = renderProvider();
+ act(() => {
+ store.dispatch(registerParallelRequest({ threadId: 't-par', requestId: 'branch-error' }));
+ listeners.onError?.({
+ thread_id: 't-par',
+ request_id: 'branch-error',
+ message: 'The provider refused this turn.',
+ error_type: 'provider_error',
+ round: 0,
+ });
+ });
+
+ await waitFor(() =>
+ expect(threadApi.appendMessage).toHaveBeenCalledWith(
+ 't-par',
+ expect.objectContaining({
+ content: 'The provider refused this turn.',
+ extraMetadata: expect.objectContaining({
+ chatError: expect.objectContaining({ errorType: 'provider_error' }),
+ }),
+ })
+ )
+ );
+ expect(store.getState().chatRuntime.parallelRequestThreads['branch-error']).toBeUndefined();
+ });
+
it('bumps the heartbeat counter only for the primary turn, never a parallel branch (#4282)', () => {
const listeners = renderProvider();
@@ -2251,13 +2278,10 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
// user-friendly `message` from classify_inference_error() in web_errors.rs,
// which is forwarded directly so the user sees the real reason (for
// 'inference' that message is a friendly summary plus the sanitized upstream
- // provider error as a `> quote` block). The USER_FACING_FALLBACK constant is
- // only used when the server sends an empty/missing message. 'cancelled'
- // produces no bubble at all.
+ // provider error as a `> quote` block). An empty server message is stored
+ // as an empty error row for assistant-ui's ErrorState fallback. 'cancelled'
+ // produces no error row.
describe('inference error classifier — full type set', () => {
- const USER_FACING_FALLBACK =
- 'Something went wrong. Please try again.\nThis error has been reported. You can also report it on Discord.\n<openhuman-link path="community/discord-report">Report on Discord</openhuman-link>';
-
it.each([
['rate_limited', 'You have been rate limited. Please try again later.'],
['auth_error', 'Authentication failed. Please reconnect your account.'],
@@ -2321,7 +2345,7 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
);
});
- it('falls back to the constant when an inference error has no message', async () => {
+ it('stores an empty error row for assistant-ui when an inference error has no message', async () => {
const listeners = renderProvider();
const threadId = 't-inference-empty';
@@ -2338,7 +2362,13 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
await waitFor(() =>
expect(threadApi.appendMessage).toHaveBeenCalledWith(
threadId,
- expect.objectContaining({ content: USER_FACING_FALLBACK, sender: 'agent' })
+ expect.objectContaining({
+ content: '',
+ sender: 'agent',
+ extraMetadata: expect.objectContaining({
+ chatError: expect.objectContaining({ errorType: 'inference' }),
+ }),
+ })
)
);
});
@@ -2365,7 +2395,7 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
);
});
- it('falls back to USER_FACING constant when inference error has empty message', async () => {
+ it('stores an empty error row for other error types without a message', async () => {
const listeners = renderProvider();
const threadId = 't-empty-msg';
@@ -2382,7 +2412,13 @@ describe('ChatRuntimeProvider — dedupe, proactive resolution, mid-turn invaria
await waitFor(() =>
expect(threadApi.appendMessage).toHaveBeenCalledWith(
threadId,
- expect.objectContaining({ content: USER_FACING_FALLBACK, sender: 'agent' })
+ expect.objectContaining({
+ content: '',
+ sender: 'agent',
+ extraMetadata: expect.objectContaining({
+ chatError: expect.objectContaining({ errorType: 'network' }),
+ }),
+ })
)
);
});
diff --git a/app/src/providers/__tests__/assistantUiMessages.test.ts b/app/src/providers/__tests__/assistantUiMessages.test.ts
index 24891040f8..fbfc475d7a 100644
--- a/app/src/providers/__tests__/assistantUiMessages.test.ts
+++ b/app/src/providers/__tests__/assistantUiMessages.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it, vi } from 'vitest';
import type { ToolTimelineEntry } from '../../store/chatRuntimeSlice';
+import { CHAT_ERROR_METADATA_KEY } from '../../store/threadSlice';
import type { ThreadMessage } from '../../types/thread';
import {
buildRuntimeMessages,
@@ -63,6 +64,26 @@ describe('toThreadMessageLike', () => {
});
});
+ it('shows a failed turn through assistant-ui error status without raw link markup', () => {
+ const content =
+ 'Something went wrong. Please try again.\n<openhuman-link path="community/discord-report">Report on Discord</openhuman-link>\n\n> Provider detail';
+ const converted = toThreadMessageLike(
+ msg({
+ id: 'failed-turn',
+ sender: 'agent',
+ content,
+ extraMetadata: { [CHAT_ERROR_METADATA_KEY]: { errorType: 'inference' } },
+ })
+ );
+
+ expect(converted.content).toEqual([]);
+ expect(converted.status).toEqual({
+ type: 'incomplete',
+ reason: 'error',
+ error: 'Something went wrong. Please try again.\n\n> Provider detail',
+ });
+ });
+
it('returns the identical object for the same source message', () => {
const m = msg({ id: 'cached' });
expect(toThreadMessageLike(m)).toBe(toThreadMessageLike(m));
diff --git a/app/src/providers/assistantUiMessages.ts b/app/src/providers/assistantUiMessages.ts
index 4d576d496c..4565b2f560 100644
--- a/app/src/providers/assistantUiMessages.ts
+++ b/app/src/providers/assistantUiMessages.ts
@@ -8,6 +8,7 @@ import {
type ToolCallMessagePart,
} from '@assistant-ui/react';
+import { parseBubbleSegments } from '../features/conversations/utils/format';
import { parseMessageImages } from '../lib/attachments';
import { unwrapToolCallEnvelope } from '../lib/chat/toolCallEnvelope';
import type { ChatCitation } from '../services/chatService';
@@ -854,28 +855,47 @@ export function toThreadMessageLike(
toolCallCount: effectiveTimeline.length,
}
: undefined;
- // A `chat_error{error_type:"guardrail"}` turn (wire-contract.md). Its plain
- // text is suppressed here — `ChatErrorNotice` (`features/conversations/aui/`)
- // renders the vendored `GuardrailNotice` card from this same
- // `extraMetadata` (surfaced unchanged on `metadata.custom.extraMetadata`
- // below) instead, so the turn is not shown twice.
- const isGuardrailError =
- msg.sender === 'agent' &&
- (msg.extraMetadata?.[CHAT_ERROR_METADATA_KEY] as { errorType?: string } | undefined)
- ?.errorType === 'guardrail';
+ // Socket errors are persisted as assistant rows, but assistant-ui's error
+ // status should render them through MessageError's ErrorState card rather
+ // than Markdown. The guardrail has its own structured notice card.
+ const chatError =
+ msg.sender === 'agent'
+ ? (msg.extraMetadata?.[CHAT_ERROR_METADATA_KEY] as { errorType?: string } | undefined)
+ : undefined;
+ const isGuardrailError = chatError?.errorType === 'guardrail';
+ const isChatError = chatError !== undefined && !isGuardrailError;
+ // Older persisted errors may contain the retired custom navigation tag.
+ // Keep the diagnostic text and provider detail, without exposing raw markup
+ // inside the plain-text error card.
+ const errorDetail = isChatError
+ ? parseBubbleSegments(text)
+ .filter(segment => segment.kind === 'text')
+ .map(segment => segment.text)
+ .join('')
+ .replace(/\n{3,}/g, '\n\n')
+ .trim()
+ : '';
const converted: ThreadMessageLike = {
id: msg.id,
role: msg.sender === 'agent' ? 'assistant' : 'user',
- content: isGuardrailError
+ content: chatError
? []
: msg.sender === 'agent'
? assistantParts(text, effectiveTimeline, transcript, 'settled', messageCitations(msg))
: userParts(msg),
createdAt: new Date(msg.createdAt),
- ...(msg.sender === 'agent' && msg.extraMetadata?.stopped === true
- ? { status: { type: 'incomplete' as const, reason: 'cancelled' as const } }
- : {}),
+ ...(isChatError
+ ? {
+ status: {
+ type: 'incomplete' as const,
+ reason: 'error' as const,
+ ...(errorDetail ? { error: errorDetail } : {}),
+ },
+ }
+ : msg.sender === 'agent' && msg.extraMetadata?.stopped === true
+ ? { status: { type: 'incomplete' as const, reason: 'cancelled' as const } }
+ : {}),
metadata: {
// Defect A (#6459-adjacent, but its own bug): the runtime writes
// `submittedFeedback` onto its OWN repository copy when a thumb is
@@ -1102,7 +1122,11 @@ export function buildRuntimeMessages(
if (frozen) {
const settledRows = requestId ? projection.turnTimelines?.[requestId] : undefined;
out.push(
- toThreadMessageLike(msg, withSettledStatuses(frozen.timeline, settledRows), frozen.transcript)
+ toThreadMessageLike(
+ msg,
+ withSettledStatuses(frozen.timeline, settledRows),
+ frozen.transcript
+ )
);
continue;
}
diff --git a/crates/openhuman-core/src/cron/scheduler/failure_classification.rs b/crates/openhuman-core/src/cron/scheduler/failure_classification.rs
index ef13daf6c8..6d7bb5d9b0 100644
--- a/crates/openhuman-core/src/cron/scheduler/failure_classification.rs
+++ b/crates/openhuman-core/src/cron/scheduler/failure_classification.rs
@@ -4,7 +4,7 @@
use crate::agent::error::AgentError;
use crate::cron::JobType;
-pub(super) const AGENT_JOB_USER_FAILURE_MESSAGE: &str = "Something went wrong. Please try again.\nThis error has been reported. You can also report it on Discord.\n<openhuman-link path=\"community/discord-report\">Report on Discord</openhuman-link>";
+pub(super) const AGENT_JOB_USER_FAILURE_MESSAGE: &str = "Something went wrong. Please try again.";
// Actionable, static failure copy for the three permanent cron halt states
// (TAURI-RUST-514 / -BMW / -HCK). Surfaced verbatim in the alerts tab + run
// history in place of the generic `AGENT_JOB_USER_FAILURE_MESSAGE`, so a user
diff --git a/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs b/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs
index 033ede9845..fe7a6e0439 100644
--- a/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs
+++ b/crates/openhuman-core/src/cron/scheduler_halt_and_persist_tests.rs
@@ -314,8 +314,7 @@ async fn run_agent_job_returns_error_without_provider_key() {
let (success, output, raw_error) = run_agent_job(&config, &job).await;
assert!(!success, "Agent job without provider key should fail");
assert!(output.contains("Something went wrong. Please try again."));
- assert!(output.contains("This error has been reported."));
- assert!(output.contains("Report on Discord"));
+ assert!(!output.contains("<openhuman-link"));
assert!(
raw_error
.as_deref()
diff --git a/crates/openhuman-core/src/web_chat/web_errors/budget.rs b/crates/openhuman-core/src/web_chat/web_errors/budget.rs
index cbaa6aa9eb..730547ea69 100644
--- a/crates/openhuman-core/src/web_chat/web_errors/budget.rs
+++ b/crates/openhuman-core/src/web_chat/web_errors/budget.rs
@@ -50,7 +50,7 @@ pub(crate) fn inference_budget_exceeded_user_message() -> &'static str {
}
pub(crate) fn generic_inference_error_user_message() -> &'static str {
- "Something went wrong. Please try again.\nThis error has been reported. You can also report it on Discord.\n<openhuman-link path=\"community/discord-report\">Report on Discord</openhuman-link>"
+ "Something went wrong. Please try again."
}
/// Detect the SecurityPolicy global hourly action-budget signal
diff --git a/crates/openhuman-core/src/web_chat/web_tests_rate_limit_classification_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_rate_limit_classification_tests.rs
index e43cdab71a..a3f174455f 100644
--- a/crates/openhuman-core/src/web_chat/web_tests_rate_limit_classification_tests.rs
+++ b/crates/openhuman-core/src/web_chat/web_tests_rate_limit_classification_tests.rs
@@ -577,13 +577,9 @@ fn classify_inference_error_retryable_429_message_keeps_retry_hint() {
}
#[test]
-fn generic_error_copy_is_sanitized_and_has_discord_report_action() {
+fn generic_error_copy_is_plain_text_for_the_error_card() {
let message = generic_inference_error_user_message();
- assert!(message.contains("Something went wrong. Please try again."));
- assert!(message.contains("This error has been reported."));
- assert!(message.contains(
- "<openhuman-link path=\"community/discord-report\">Report on Discord</openhuman-link>"
- ));
+ assert_eq!(message, "Something went wrong. Please try again.");
}
#[test]
diff --git a/docs/TEST-COVERAGE-MATRIX.md b/docs/TEST-COVERAGE-MATRIX.md
index 31e2d11c09..c3452c43be 100644
--- a/docs/TEST-COVERAGE-MATRIX.md
+++ b/docs/TEST-COVERAGE-MATRIX.md
@@ -229,6 +229,7 @@ End-to-end coverage of the agent harness via the web-chat RPC surface against an
| 4.4.14 | Session todo list (the `todo` tool) | RI+VU+WD | `tests/agent_harness_e2e.rs`, `crates/openhuman-core/src/agent/tools/todo_tests.rs`, `vendor/tinyagents/crates/tinyagents-graph/src/todos/test.rs`, `app/src/features/conversations/utils/harnessState.test.ts`, `app/src/features/conversations/components/TodoChecklist.test.tsx`, `app/src/features/conversations/hooks/useThreadHarnessState.test.ts`, `app/test/e2e/specs/chat-todos-goals.spec.ts` | ✅ | Whole-list write per call (Claude/Codex shape), single-`in_progress` invariant, per-session scoping; five items ticked off across turns, live on the socket, persisted in the turn state, and rendered as the chat pane's checklist |
| 4.4.15 | Thread goal (`goal_set` / `goal_get` / `goal_complete`) | RI+RU+VU+WD | `tests/agent_harness_e2e.rs`, `crates/openhuman-core/src/agent/goals/{tools_tests.rs,runtime_tests.rs,continuation_tests.rs}`, `vendor/tinyagents/crates/tinyagents-graph/src/goals/test.rs`, `app/src/features/conversations/utils/harnessState.test.ts`, `app/src/features/conversations/components/GoalBanner.test.tsx`, `app/src/features/conversations/hooks/useThreadHarnessState.test.ts`, `app/test/e2e/specs/chat-todos-goals.spec.ts` | ✅ | Objective + token budget set, read back across turns, and completed; structured `{goal, text}` payload drives the chat pane's goal banner. Budget accounting and the budget-limit stop hook are unit-covered (the scripted e2e upstream reports no usage) |
| 4.4.16 | Builder-supplied session definition (library host) | RU | `crates/openhuman-core/src/agent/session_host/builder/builder_tests_session_definition_tests.rs` | ✅ | `SessionHostBuilder::agent_definition` stamps a caller's own `AgentDefinition` on the session, so a hosted root invocation resolves an id the process registry never held; it outranks a registry entry sharing its id, it carries the turn's tool allow-list, the session is stamped with the definition's own id, a contradicting `agent_definition_name` fails the build, and without it the same id stays unknown |
+| 4.4.17 | Chat failure presentation | RU+VU | `crates/openhuman-core/src/web_chat/web_tests_rate_limit_classification_tests.rs`, `app/src/providers/__tests__/assistantUiMessages.test.ts`, `app/src/features/conversations/aui/ChatErrorNotice.test.tsx` | ✅ | Failed turns use assistant-ui's error card; old custom link markup is removed from saved errors (#6609) |
---