Skip to content

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

fix(app): do not render Refresh on turns the runtime cannot reload

M3gA-Mind92c61119e508
diff --git a/app/src/components/assistant-ui/thread.reloadCapability.test.tsx b/app/src/components/assistant-ui/thread.reloadCapability.test.tsx
new file mode 100644
index 0000000000..98e18e88ad
--- /dev/null
+++ b/app/src/components/assistant-ui/thread.reloadCapability.test.tsx
@@ -0,0 +1,58 @@
+import {
+ AssistantRuntimeProvider,
+ type ThreadMessageLike,
+ useExternalStoreRuntime,
+} from '@assistant-ui/react';
+import { render, screen } from '@testing-library/react';
+import { describe, expect, it } from 'vitest';
+
+import { Thread } from './thread';
+
+/**
+ * The Refresh button must not render while the runtime cannot honour a reload.
+ *
+ * assistant-ui derives the Reload primitive's disabled state from
+ * `isRunning || isDisabled || role !== 'assistant'` and never consults
+ * `capabilities.reload`, so the button was enabled on every settled assistant
+ * message. `useOpenHumanExternalStore` supplies no `onReload`, and
+ * `ExternalStoreThreadRuntimeCore.reload` throws
+ * `Runtime does not support reloading messages.` — a clickable control whose
+ * only outcome is an exception.
+ *
+ * Both directions are asserted against the SAME `<Thread />`, toggled only by
+ * whether the adapter passes `onReload`, so the test fails if the gate is
+ * removed AND if it is hard-coded off.
+ */
+
+const messages: ThreadMessageLike[] = [
+ { role: 'user', content: [{ type: 'text', text: 'hello' }] },
+ { role: 'assistant', content: [{ type: 'text', text: 'a reply' }] },
+];
+
+function Harness({ withReload }: { withReload: boolean }) {
+ const runtime = useExternalStoreRuntime({
+ messages,
+ isRunning: false,
+ convertMessage: (m: ThreadMessageLike) => m,
+ onNew: async () => {},
+ ...(withReload ? { onReload: async () => {} } : {}),
+ });
+ return (
+ <AssistantRuntimeProvider runtime={runtime}>
+ <Thread />
+ </AssistantRuntimeProvider>
+ );
+}
+
+describe('assistant action bar reload gate', () => {
+ it('renders no Refresh button when the runtime cannot reload', () => {
+ render(<Harness withReload={false} />);
+ expect(screen.getAllByTestId('agent-message').length).toBeGreaterThan(0);
+ expect(screen.queryAllByRole('button', { name: 'Refresh' })).toHaveLength(0);
+ });
+
+ it('renders the Refresh button when the runtime can reload', () => {
+ render(<Harness withReload />);
+ expect(screen.getAllByRole('button', { name: 'Refresh' }).length).toBeGreaterThan(0);
+ });
+});
diff --git a/app/src/components/assistant-ui/thread.tsx b/app/src/components/assistant-ui/thread.tsx
index a872bdc2c2..329c38861a 100644
--- a/app/src/components/assistant-ui/thread.tsx
+++ b/app/src/components/assistant-ui/thread.tsx
@@ -28,7 +28,10 @@ import { TooltipIconButton } from '@/components/assistant-ui/tooltip-icon-button
import { Button } from '@/components/assistant-ui/ui/button';
import { Skeleton } from '@/components/assistant-ui/ui/skeleton';
import ModelQualityPill from '@/components/chat/ModelQualityPill';
-import { useAuiEditCapabilities } from '@/features/conversations/components/aui/auiThreadState';
+import {
+ useAuiEditCapabilities,
+ useAuiReloadCapability,
+} from '@/features/conversations/components/aui/auiThreadState';
import {
ActionBarMorePrimitive,
ActionBarPrimitive,
@@ -1050,6 +1053,23 @@ const AssistantMessage: FC = () => {
};
const AssistantActionBar: FC = () => {
+ // assistant-ui's own disabled predicate for Reload is
+ // `isRunning || isDisabled || role !== 'assistant'` — it never consults
+ // `capabilities.reload`, so the button ships enabled on every settled
+ // assistant message while the external-store adapter supplies no `onReload`
+ // and the runtime throws on click.
+ //
+ // Hoisted to a `const` rather than written inline for the same coverage
+ // reason as `editAction` in `UserActionBar`.
+ const canReload = useAuiReloadCapability();
+ const reloadAction = canReload ? (
+ <ActionBarPrimitive.Reload asChild>
+ <TooltipIconButton tooltip="Refresh">
+ <RefreshCwIcon />
+ </TooltipIconButton>
+ </ActionBarPrimitive.Reload>
+ ) : null;
+
return (
<ActionBarPrimitive.Root
hideWhenRunning
@@ -1065,11 +1085,7 @@ const AssistantActionBar: FC = () => {
</AuiIf>
</TooltipIconButton>
</ActionBarPrimitive.Copy>
- <ActionBarPrimitive.Reload asChild>
- <TooltipIconButton tooltip="Refresh">
- <RefreshCwIcon />
- </TooltipIconButton>
- </ActionBarPrimitive.Reload>
+ {reloadAction}
<ActionBarMorePrimitive.Root>
<ActionBarMorePrimitive.Trigger asChild>
<TooltipIconButton tooltip="More" className="data-[state=open]:bg-accent">
diff --git a/app/src/features/conversations/components/aui/auiThreadState.ts b/app/src/features/conversations/components/aui/auiThreadState.ts
index 896de8ff2f..98b2113e8d 100644
--- a/app/src/features/conversations/components/aui/auiThreadState.ts
+++ b/app/src/features/conversations/components/aui/auiThreadState.ts
@@ -37,6 +37,8 @@ const selectCanEdit = (s: AssistantState) => s.optional.thread?.capabilities.edi
const selectCanSwitchToBranch = (s: AssistantState) =>
s.optional.thread?.capabilities.switchToBranch;
+const selectCanReload = (s: AssistantState) => s.optional.thread?.capabilities.reload;
+
/**
* Whether the runtime believes a turn is in flight.
*
@@ -79,6 +81,23 @@ export function useAuiEditCapabilities(): { canEdit: boolean; canSwitchToBranch:
return { canEdit, canSwitchToBranch };
}
+/**
+ * Whether the runtime can re-run an assistant turn.
+ *
+ * Same defect class as Edit and BranchPicker, and it bites harder: assistant-ui
+ * computes the Reload button's disabled state from
+ * `isRunning || isDisabled || role !== 'assistant'` and never consults
+ * `capabilities.reload`, so the button is *enabled* on every settled assistant
+ * message. `useOpenHumanExternalStore` supplies no `onReload`, and the runtime
+ * throws `Runtime does not support reloading messages.` on click.
+ *
+ * Gated rather than deleted, so the affordance appears by itself the day the
+ * adapter grows `onReload`.
+ */
+export function useAuiReloadCapability(): boolean {
+ return useAuiState(selectCanReload) ?? false;
+}
+
/**
* THE EDIT / BRANCH SEAM.
*