Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
[issue-11673] Reset action states after failed requests (#11714)
[._.]/763702d79b6f
diff --git a/client/src/components/agents/tabs/OverviewTab.jsx b/client/src/components/agents/tabs/OverviewTab.jsxindex f5fd92d5e7..ebe67af783 100644--- a/client/src/components/agents/tabs/OverviewTab.jsx+++ b/client/src/components/agents/tabs/OverviewTab.jsx@@ -196,10 +196,15 @@ export default function OverviewTab({ agentId, agent, onAgentUpdate }) {const handleEngage = async () => {if (!agentId || !quickAccountId) return;setEngaging(true);- const result = await api.engageAgent({ agentId, accountId: quickAccountId, maxComments: 1, maxVotes: 3 });- setEngaging(false);- toast.success(`Engaged: ${result.votes?.length || 0} votes, ${result.comments?.length || 0} comments`);- refetchRateLimits();+ try {+ const result = await api.engageAgent({ agentId, accountId: quickAccountId, maxComments: 1, maxVotes: 3 });+ toast.success(`Engaged: ${result.votes?.length || 0} votes, ${result.comments?.length || 0} comments`);+ refetchRateLimits();+ } catch {+ // The request helper already shows the failure toast.+ } finally {+ setEngaging(false);+ }};const handleCheckPosts = async () => {@@ -262,9 +267,14 @@ export default function OverviewTab({ agentId, agent, onAgentUpdate }) {const handleAccountTest = async (id) => {setTestingId(id);setTestResult(null);- const result = await api.testPlatformAccount(id);- setTestResult({ accountId: id, ...result });- setTestingId(null);+ try {+ const result = await api.testPlatformAccount(id, { silent: true });+ setTestResult({ accountId: id, ...result });+ } catch (err) {+ setTestResult({ accountId: id, success: false, message: err.message || 'Account test failed' });+ } finally {+ setTestingId(null);+ }};const handleAccountClaim = async (id) => {diff --git a/client/src/components/agents/tabs/OverviewTab.test.jsx b/client/src/components/agents/tabs/OverviewTab.test.jsxindex 9bd4c1c623..623f295e6b 100644--- a/client/src/components/agents/tabs/OverviewTab.test.jsx+++ b/client/src/components/agents/tabs/OverviewTab.test.jsx@@ -1,5 +1,5 @@import { beforeEach, describe, expect, it, vi } from 'vitest';-import { render, screen, within } from '@testing-library/react';+import { act, fireEvent, render, screen, within } from '@testing-library/react';import { MemoryRouter } from 'react-router';vi.mock('../../../services/api', () => ({@@ -7,10 +7,11 @@ vi.mock('../../../services/api', () => ({getProviders: vi.fn(),getAgentActivityStats: vi.fn(),getAgentRateLimits: vi.fn(),+ testPlatformAccount: vi.fn(),updateAgentPersonality: vi.fn(),}));-import { getPlatformAccounts, getProviders, getAgentActivityStats } from '../../../services/api';+import { getPlatformAccounts, getProviders, getAgentActivityStats, getAgentRateLimits, testPlatformAccount } from '../../../services/api';import OverviewTab from './OverviewTab';const providers = [@@ -22,6 +23,7 @@ const providers = [beforeEach(() => {vi.clearAllMocks();getPlatformAccounts.mockResolvedValue([]);+ getAgentRateLimits.mockResolvedValue({});getProviders.mockResolvedValue({ providers });getAgentActivityStats.mockResolvedValue(null);});@@ -63,3 +65,19 @@ describe('agent AI provider pickers', () => {expect(within(challenge).queryByRole('option', { name: 'Example TUI' })).not.toBeInTheDocument();});});++it('shows a failed account test inline and releases the Test button for retry', async () => {+ getPlatformAccounts.mockResolvedValue([{+ id: 'account-1', platform: 'moltbook', status: 'active', credentials: { username: 'example-user' },+ }]);+ testPlatformAccount.mockRejectedValueOnce(new Error('Platform unavailable'));++ render(<MemoryRouter><OverviewTab agentId="agent-1" agent={{ id: 'agent-1', name: 'Example Agent', enabled: true }} /></MemoryRouter>);+ const testButton = await screen.findByRole('button', { name: 'Test' });++ await act(async () => { fireEvent.click(testButton); });++ expect(await screen.findByText('Platform unavailable')).toBeInTheDocument();+ expect(testButton).toBeEnabled();+ expect(testPlatformAccount).toHaveBeenCalledWith('account-1', { silent: true });+});diff --git a/client/src/components/agents/tabs/PublishedTab.jsx b/client/src/components/agents/tabs/PublishedTab.jsxindex 0d2b94e5ee..dd0ac81432 100644--- a/client/src/components/agents/tabs/PublishedTab.jsx+++ b/client/src/components/agents/tabs/PublishedTab.jsx@@ -1,6 +1,7 @@import { useState, useEffect, useCallback } from 'react';import * as api from '../../../services/api';import BrailleSpinner from '../../BrailleSpinner';+import LoadFailedState from '../../ui/LoadFailedState';import { FormField } from '../../ui/FormField';import { timeAgo, formatDateTime } from '../../../utils/formatters';@@ -9,6 +10,7 @@ export default function PublishedTab({ agentId }) {const [selectedAccountId, setSelectedAccountId] = useState('');const [published, setPublished] = useState({ posts: [], comments: [] });const [publishedLoading, setPublishedLoading] = useState(false);+ const [publishedError, setPublishedError] = useState(false);const [publishedDays, setPublishedDays] = useState(7);const [loading, setLoading] = useState(true);@@ -33,9 +35,15 @@ export default function PublishedTab({ agentId }) {return;}setPublishedLoading(true);- const data = await api.getAgentPublished({ agentId, accountId: selectedAccountId, days: publishedDays });- setPublished(data);- setPublishedLoading(false);+ setPublishedError(false);+ try {+ const data = await api.getAgentPublished({ agentId, accountId: selectedAccountId, days: publishedDays }, { silent: true });+ setPublished(data);+ } catch {+ setPublishedError(true);+ } finally {+ setPublishedLoading(false);+ }}, [agentId, selectedAccountId, publishedDays]);useEffect(() => {@@ -93,6 +101,7 @@ export default function PublishedTab({ agentId }) {{selectedAccountId && (<div className="bg-port-card border border-port-border rounded-lg p-4">+ {publishedError ? <LoadFailedState title="Could not load published content." onRetry={loadPublished} /> : <><div className="flex items-center gap-3 mb-4"><h3 className="font-semibold text-white">Published Content</h3>{published.posts.length > 0 && (@@ -238,6 +247,7 @@ export default function PublishedTab({ agentId }) {No published content in the last {publishedDays} days</p>)}+ </>}</div>)}</div>diff --git a/client/src/components/agents/tabs/PublishedTab.test.jsx b/client/src/components/agents/tabs/PublishedTab.test.jsxnew file mode 100644index 0000000000..28d9851e81--- /dev/null+++ b/client/src/components/agents/tabs/PublishedTab.test.jsx@@ -0,0 +1,38 @@+import { act, fireEvent, render, screen } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++vi.mock('../../../services/api', () => ({+ getPlatformAccounts: vi.fn(),+ getAgentPublished: vi.fn(),+}));++import * as api from '../../../services/api';+import PublishedTab from './PublishedTab.jsx';++describe('PublishedTab', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ api.getPlatformAccounts.mockResolvedValue([{+ id: 'account-1', status: 'active', credentials: { username: 'example-user' },+ }]);+ });++ it('shows a retryable error and releases Refresh after a failed published-content load', async () => {+ api.getAgentPublished.mockRejectedValueOnce(new Error('network unavailable')).mockResolvedValue({ posts: [], comments: [] });++ render(<PublishedTab agentId="agent-1" />);++ const retry = await screen.findByRole('button', { name: 'Retry' });+ const refresh = screen.getByRole('button', { name: 'Refresh' });+ expect(refresh).toBeEnabled();+ expect(api.getAgentPublished).toHaveBeenLastCalledWith(+ { agentId: 'agent-1', accountId: 'account-1', days: 7 },+ { silent: true },+ );++ await act(async () => { fireEvent.click(retry); });++ expect(await screen.findByText(/No published content in the last 7 days/)).toBeInTheDocument();+ expect(api.getAgentPublished).toHaveBeenCalledTimes(2);+ });+});diff --git a/client/src/components/agents/tabs/SchedulesTab.jsx b/client/src/components/agents/tabs/SchedulesTab.jsxindex 528140b97c..0498f09aca 100644--- a/client/src/components/agents/tabs/SchedulesTab.jsx+++ b/client/src/components/agents/tabs/SchedulesTab.jsx@@ -88,9 +88,14 @@ export default function SchedulesTab({ agentId }) {const handleRunNow = async (id) => {setRunningId(id);- await api.runAutomationScheduleNow(id);- setRunningId(null);- fetchData();+ try {+ await api.runAutomationScheduleNow(id);+ fetchData();+ } catch {+ // The request helper already shows the failure toast.+ } finally {+ setRunningId(null);+ }};const getAccountName = (accountId) => {diff --git a/client/src/components/agents/tabs/SchedulesTab.test.jsx b/client/src/components/agents/tabs/SchedulesTab.test.jsxindex 7656bad7e9..50d2eaedee 100644--- a/client/src/components/agents/tabs/SchedulesTab.test.jsx+++ b/client/src/components/agents/tabs/SchedulesTab.test.jsx@@ -6,6 +6,7 @@ vi.mock('../../../services/api', () => ({getAutomationSchedules: vi.fn(),getPlatformAccounts: vi.fn(),getScheduleStats: vi.fn(),+ runAutomationScheduleNow: vi.fn(),}));import * as api from '../../../services/api';@@ -36,4 +37,23 @@ describe('SchedulesTab', () => {expect(await screen.findByText('No schedules')).toBeInTheDocument();expect(api.getAutomationSchedules).toHaveBeenCalledTimes(2);});++ it('re-enables Run Now after the schedule request fails', async () => {+ api.getAutomationSchedules.mockResolvedValue([{+ id: 'schedule-1', agentId: 'agent-1', accountId: 'account-1', enabled: true,+ action: { type: 'heartbeat', params: {} }, schedule: { type: 'interval', intervalMs: 60000 },+ rateLimit: { maxPerDay: 5 },+ }]);+ api.getPlatformAccounts.mockResolvedValue([{ id: 'account-1', status: 'active', credentials: { username: 'example-user' } }]);+ api.getScheduleStats.mockResolvedValue(null);+ api.runAutomationScheduleNow.mockRejectedValueOnce(new Error('Run failed'));++ render(<SchedulesTab agentId="agent-1" />);+ const runButton = await screen.findByRole('button', { name: 'Run Now' });++ await act(async () => { fireEvent.click(runButton); });++ expect(runButton).toBeEnabled();+ expect(runButton).toHaveTextContent('Run Now');+ });});diff --git a/client/src/components/agents/tabs/ToolsTab.jsx b/client/src/components/agents/tabs/ToolsTab.jsxindex a95e6daee6..88f375764b 100644--- a/client/src/components/agents/tabs/ToolsTab.jsx+++ b/client/src/components/agents/tabs/ToolsTab.jsx@@ -119,17 +119,27 @@ export default function ToolsTab({ agentId, agent }) {const handleBrowseFeed = async () => {if (!selectedAccountId) return;setFeedLoading(true);- const feed = await api.getAgentFeed({ accountId: selectedAccountId, sort: feedSort, limit: 25 });- setFeedPosts(feed.posts || feed || []);- setFeedLoading(false);+ try {+ const feed = await api.getAgentFeed({ accountId: selectedAccountId, sort: feedSort, limit: 25 });+ setFeedPosts(feed.posts || feed || []);+ } catch {+ // The request helper already shows the failure toast.+ } finally {+ setFeedLoading(false);+ }};const handleFindRelevant = async () => {if (!agentId || !selectedAccountId) return;setFeedLoading(true);- const posts = await api.getAgentRelevantPosts({ agentId, accountId: selectedAccountId, maxResults: 10 });- setFeedPosts(posts);- setFeedLoading(false);+ try {+ const posts = await api.getAgentRelevantPosts({ agentId, accountId: selectedAccountId, maxResults: 10 });+ setFeedPosts(posts);+ } catch {+ // The request helper already shows the failure toast.+ } finally {+ setFeedLoading(false);+ }};const handleViewPost = async (post) => {@@ -271,11 +281,16 @@ export default function ToolsTab({ agentId, agent }) {if (!agentId || !selectedAccountId) return;setEngaging(true);setEngageResult(null);- const result = await api.engageAgent({ agentId, accountId: selectedAccountId, maxComments: 1, maxVotes: 3 });- setEngageResult(result);- setEngaging(false);- toast.success(`Engaged: ${result.votes?.length || 0} votes, ${result.comments?.length || 0} comments`);- api.getAgentRateLimits(selectedAccountId).then(setRateLimits).catch(err => console.warn('⚠️ Failed to refresh rate limits: ' + err.message));+ try {+ const result = await api.engageAgent({ agentId, accountId: selectedAccountId, maxComments: 1, maxVotes: 3 });+ setEngageResult(result);+ toast.success(`Engaged: ${result.votes?.length || 0} votes, ${result.comments?.length || 0} comments`);+ api.getAgentRateLimits(selectedAccountId).then(setRateLimits).catch(err => console.warn('⚠️ Failed to refresh rate limits: ' + err.message));+ } catch {+ // The request helper already shows the failure toast.+ } finally {+ setEngaging(false);+ }};// Check Posts (Monitor)diff --git a/client/src/components/agents/tabs/ToolsTab.test.jsx b/client/src/components/agents/tabs/ToolsTab.test.jsxnew file mode 100644index 0000000000..b6a9e53b86--- /dev/null+++ b/client/src/components/agents/tabs/ToolsTab.test.jsx@@ -0,0 +1,40 @@+import { act, fireEvent, render, screen } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++vi.mock('../../../services/api', () => ({+ getPlatformAccounts: vi.fn(),+ getAgentRateLimits: vi.fn(),+ getAgentSubmolts: vi.fn(),+ getAgentDrafts: vi.fn(),+ getAgentFeed: vi.fn(),+ getAgentRelevantPosts: vi.fn(),+ engageAgent: vi.fn(),+}));++import * as api from '../../../services/api';+import ToolsTab from './ToolsTab.jsx';++describe('ToolsTab action failures', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ api.getPlatformAccounts.mockResolvedValue([{+ id: 'account-1', status: 'active', credentials: { username: 'example-user' },+ }]);+ api.getAgentRateLimits.mockResolvedValue({});+ api.getAgentSubmolts.mockResolvedValue([]);+ api.getAgentDrafts.mockResolvedValue([]);+ });++ it('re-enables feed actions after the request fails', async () => {+ api.getAgentFeed.mockRejectedValueOnce(new Error('feed unavailable'));++ render(<ToolsTab agentId="agent-1" agent={{ id: 'agent-1', aiConfig: {} }} />);+ const browse = await screen.findByRole('button', { name: 'Browse Feed' });++ await act(async () => { fireEvent.click(browse); });++ expect(browse).toBeEnabled();+ expect(browse).toHaveTextContent('Browse Feed');+ expect(api.getAgentFeed).toHaveBeenCalledWith({ accountId: 'account-1', sort: 'hot', limit: 25 });+ });+});diff --git a/client/src/components/digital-twin/tabs/ExportTab.jsx b/client/src/components/digital-twin/tabs/ExportTab.jsxindex c1289f70d7..c6936c0562 100644--- a/client/src/components/digital-twin/tabs/ExportTab.jsx+++ b/client/src/components/digital-twin/tabs/ExportTab.jsx@@ -59,13 +59,18 @@ export default function ExportTab({ onRefresh: _onRefresh }) {const handleExport = async () => {setExporting(true);- const result = await api.exportSoul(- selectedFormat,- selectedDocs.length > 0 ? selectedDocs : null,- includeDisabled- );- setExportResult(result);- setExporting(false);+ try {+ const result = await api.exportSoul(+ selectedFormat,+ selectedDocs.length > 0 ? selectedDocs : null,+ includeDisabled+ );+ setExportResult(result);+ } catch {+ // The request helper already shows the failure toast.+ } finally {+ setExporting(false);+ }};const handleCopyExport = async () => {diff --git a/client/src/components/digital-twin/tabs/ExportTab.test.jsx b/client/src/components/digital-twin/tabs/ExportTab.test.jsxnew file mode 100644index 0000000000..a071bfc752--- /dev/null+++ b/client/src/components/digital-twin/tabs/ExportTab.test.jsx@@ -0,0 +1,31 @@+import { act, fireEvent, render, screen } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++vi.mock('../../../services/api', () => ({+ getDigitalTwinDocuments: vi.fn(),+ getDigitalTwinExportFormats: vi.fn(),+ exportSoul: vi.fn(),+}));++import * as api from '../../../services/api';+import ExportTab from './ExportTab.jsx';++describe('ExportTab', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ api.getDigitalTwinDocuments.mockResolvedValue([{ id: 'doc-1', enabled: true, title: 'Example' }]);+ api.getDigitalTwinExportFormats.mockResolvedValue([]);+ });++ it('re-enables Generate Export after the export request fails', async () => {+ api.exportSoul.mockRejectedValueOnce(new Error('export unavailable'));++ render(<ExportTab />);+ const exportButton = await screen.findByRole('button', { name: 'Generate Export' });++ await act(async () => { fireEvent.click(exportButton); });++ expect(exportButton).toBeEnabled();+ expect(exportButton).toHaveTextContent('Generate Export');+ });+});diff --git a/client/src/components/digital-twin/tabs/GoalsTab.jsx b/client/src/components/digital-twin/tabs/GoalsTab.jsxindex fb6dc1fe60..c43b249437 100644--- a/client/src/components/digital-twin/tabs/GoalsTab.jsx+++ b/client/src/components/digital-twin/tabs/GoalsTab.jsx@@ -77,9 +77,14 @@ export default function GoalsTab({ onRefresh }) {const handleDeriveLongevity = async () => {setDerivingLongevity(true);- await api.deriveLongevity();- setDerivingLongevity(false);- await loadData();+ try {+ await api.deriveLongevity();+ await loadData();+ } catch {+ // The request helper already shows the failure toast.+ } finally {+ setDerivingLongevity(false);+ }};const handleCreateGoal = async () => {diff --git a/client/src/components/digital-twin/tabs/GoalsTab.test.jsx b/client/src/components/digital-twin/tabs/GoalsTab.test.jsxnew file mode 100644index 0000000000..c9c7b73616--- /dev/null+++ b/client/src/components/digital-twin/tabs/GoalsTab.test.jsx@@ -0,0 +1,31 @@+import { act, fireEvent, render, screen } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++vi.mock('../../../services/api', () => ({+ getGoals: vi.fn(),+ getLongevity: vi.fn(),+ deriveLongevity: vi.fn(),+}));++import * as api from '../../../services/api';+import GoalsTab from './GoalsTab.jsx';++describe('GoalsTab', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ api.getGoals.mockResolvedValue({ birthDate: '1990-01-01', goals: [] });+ api.getLongevity.mockResolvedValue(null);+ });++ it('re-enables longevity derivation after the request fails', async () => {+ api.deriveLongevity.mockRejectedValueOnce(new Error('derive unavailable'));++ render(<GoalsTab />);+ const derive = await screen.findByRole('button', { name: 'Re-derive' });++ await act(async () => { fireEvent.click(derive); });++ expect(derive).toBeEnabled();+ expect(derive).toHaveTextContent('Re-derive');+ });+});diff --git a/client/src/services/apiAccounts.js b/client/src/services/apiAccounts.jsindex f21c23d4d9..8bd7dc4154 100644--- a/client/src/services/apiAccounts.js+++ b/client/src/services/apiAccounts.js@@ -13,7 +13,7 @@ export const registerPlatformAccount = ({ agentId, platform, name, description }body: JSON.stringify({ agentId, platform, name, description })});export const deletePlatformAccount = (id) => request(`/agents/accounts/${id}`, { method: 'DELETE' });-export const testPlatformAccount = (id) => request(`/agents/accounts/${id}/test`, { method: 'POST' });+export const testPlatformAccount = (id, options = {}) => request(`/agents/accounts/${id}/test`, { method: 'POST', ...options });export const claimPlatformAccount = (id) => request(`/agents/accounts/${id}/claim`, { method: 'POST' });// Agent Tools@@ -51,8 +51,8 @@ export const getAgentRelevantPosts = ({ agentId, accountId, maxResults }) => {export const getAgentSubmolts = (accountId) => request(`/agents/tools/submolts?accountId=${accountId}`);export const getAgentPost = (accountId, postId) => request(`/agents/tools/post/${postId}?accountId=${accountId}`);export const getAgentRateLimits = (accountId) => request(`/agents/tools/rate-limits?accountId=${accountId}`);-export const getAgentPublished = ({ agentId, accountId, days = 7 }) =>- request(`/agents/tools/published?agentId=${agentId}&accountId=${accountId}&days=${days}`);+export const getAgentPublished = ({ agentId, accountId, days = 7 }, options = {}) =>+ request(`/agents/tools/published?agentId=${agentId}&accountId=${accountId}&days=${days}`, options);export const checkAgentPosts = ({ agentId, accountId, days, maxReplies, maxUpvotes }) =>request('/agents/tools/check-posts', {method: 'POST',