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
fix: preserve API access policy when settings fail to load
Adam Eivyddac64b3a36c
diff --git a/client/src/components/settings/ApiAccessTab.jsx b/client/src/components/settings/ApiAccessTab.jsxindex 76b15b8e7b..cd2f9ce1e9 100644--- a/client/src/components/settings/ApiAccessTab.jsx+++ b/client/src/components/settings/ApiAccessTab.jsx@@ -3,6 +3,7 @@ import { Link } from 'react-router';import { Bot, Globe, Lock, Unlock, Copy, RefreshCw, ExternalLink } from 'lucide-react';import toast from '../ui/Toast';import BrailleSpinner from '../BrailleSpinner';+import Banner from '../ui/Banner';import { getApiCatalog, getSettings, updateSettings, getOpenApiSpec } from '../../services/apiSystem';import { copyToClipboard } from '../../lib/clipboard';@@ -51,6 +52,8 @@ const Toggle = ({ id, checked, onChange, label, hint, disabled }) => (export function ApiAccessTab() {const [loading, setLoading] = useState(true);+ const [settingsError, setSettingsError] = useState(false);+ const [settingsAttempt, setSettingsAttempt] = useState(0);const [savingId, setSavingId] = useState(null);const [access, setAccess] = useState({});const [agentContext, setAgentContext] = useState(DEFAULT_AGENT_CONTEXT);@@ -77,6 +80,8 @@ export function ApiAccessTab() {useEffect(() => {let active = true;+ setLoading(true);+ setSettingsError(false);getSettings({ silent: true }).then((s) => {if (!active) return;@@ -88,12 +93,12 @@ export function ApiAccessTab() {actions: { ...DEFAULT_AGENT_CONTEXT.actions, ...(s?.agentContext?.actions || {}) },});})- .catch(() => { if (active) toast.error('Failed to load API access settings'); })+ .catch(() => { if (active) setSettingsError(true); }).finally(() => { if (active) setLoading(false); });loadApiCards();loadSpec();return () => { active = false; };- }, [loadApiCards, loadSpec]);+ }, [loadApiCards, loadSpec, settingsAttempt]);const entryFor = (id) => ({ ...DEFAULT_ACCESS, ...(access[id] || {}) });@@ -145,6 +150,21 @@ export function ApiAccessTab() {});if (loading) return <BrailleSpinner text="Loading API access settings" />;+ // Both editors save complete settings slices. Defaults are safe only after+ // a successful read confirms the slices are absent, never after a failed read.+ if (settingsError) return (+ <Banner tone="error" size="md" actions={+ <button+ type="button"+ onClick={() => setSettingsAttempt((attempt) => attempt + 1)}+ className="rounded border border-port-error/40 px-3 py-1.5 text-xs hover:bg-port-error/10"+ >+ Retry+ </button>+ }>+ Failed to load API access settings+ </Banner>+ );return (<div className="space-y-6">diff --git a/client/src/components/settings/ApiAccessTab.test.jsx b/client/src/components/settings/ApiAccessTab.test.jsxindex 48eb428ca7..237f32ca0e 100644--- a/client/src/components/settings/ApiAccessTab.test.jsx+++ b/client/src/components/settings/ApiAccessTab.test.jsx@@ -44,6 +44,68 @@ const renderTab = async () => {};describe('ApiAccessTab', () => {+ it('keeps access controls unavailable after a failed read until retry restores the saved policies', async () => {+ // A failed settings read is not a fresh install. Saving defaults here could+ // remove a protected API's password requirement and erase other grants.+ const saved = {+ apiAccess: {+ voice: { exposed: true, requireAuth: true },+ sdapi: { exposed: true, requireAuth: false },+ },+ agentContext: {+ enabled: true,+ profile: 'summary',+ scopes: ['brain', 'identity'],+ actions: {+ readPortos: true, writePortos: true, callToolRecipes: true,+ manageEidoverse: false, visitEidoversePeers: true,+ },+ },+ };+ let resolveRetry;+ getSettings.mockRejectedValueOnce(new Error('temporarily offline'));+ render(<MemoryRouter><ApiAccessTab /></MemoryRouter>);++ expect(await screen.findByRole('alert')).toHaveTextContent('Failed to load API access settings');+ const expectNoWritableControls = () => {+ for (const control of [...screen.queryAllByRole('checkbox'), ...screen.queryAllByRole('combobox')]) {+ expect(control).toBeDisabled();+ }+ expect(updateSettings).not.toHaveBeenCalled();+ };+ expectNoWritableControls();+ getSettings.mockReturnValueOnce(new Promise((resolve) => { resolveRetry = resolve; }));+ fireEvent.click(screen.getByRole('button', { name: 'Retry' }));+ await waitFor(() => expect(getSettings).toHaveBeenCalledTimes(2));+ expectNoWritableControls();++ await act(async () => { resolveRetry(saved); });+ expect(await screen.findByText('Voice / TTS')).toBeTruthy();+ expect(screen.queryByRole('alert')).toBeNull();+ const exposure = screen.getAllByLabelText('Expose on the network');+ const auth = screen.getAllByLabelText('Require auth (password)');+ expect(exposure[0]).toBeChecked();+ expect(exposure[1]).toBeChecked();+ expect(auth[0]).toBeChecked();+ expect(auth[1]).not.toBeChecked();+ expect(screen.getByLabelText('Enable local MCP context')).toBeChecked();+ expect(screen.getByLabelText('Disclosure profile')).toHaveValue('summary');+ expect(screen.getByLabelText('Brain')).toBeChecked();+ expect(screen.getByLabelText('Identity export')).toBeChecked();+ expect(screen.getByLabelText('Navigation')).not.toBeChecked();+ expect(screen.getByLabelText('Allow semantic PortOS updates')).toBeChecked();++ fireEvent.click(exposure[1]);+ await waitFor(() => expect(updateSettings).toHaveBeenCalledWith({+ apiAccess: { ...saved.apiAccess, sdapi: { ...saved.apiAccess.sdapi, exposed: false } },+ }, { silent: true }));+ await waitFor(() => expect(screen.getByLabelText('Enable local MCP context')).toBeEnabled());+ fireEvent.click(screen.getByLabelText('Allow semantic PortOS reads'));+ await waitFor(() => expect(updateSettings).toHaveBeenLastCalledWith({+ agentContext: { ...saved.agentContext, actions: { ...saved.agentContext.actions, readPortos: false } },+ }, { silent: true }));+ });+it('renders a card per registry API with current state', async () => {getSettings.mockResolvedValue({ apiAccess: { voice: { exposed: true, requireAuth: false }, sdapi: { exposed: false, requireAuth: false } } });await renderTab();