Skip to content

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

review: LI config-load error/retry path + skip over-persist on blank custom rows (#2262)

Adam Eivybf86375a6157
diff --git a/client/src/components/apps/EditAppDrawer.jsx b/client/src/components/apps/EditAppDrawer.jsx
index 80d6869b3f..0a46c3c5dd 100644
--- a/client/src/components/apps/EditAppDrawer.jsx
+++ b/client/src/components/apps/EditAppDrawer.jsx
@@ -1,4 +1,4 @@
-import { useState, useEffect } from 'react';
+import { useState, useEffect, useCallback } from 'react';
import { Link } from 'react-router-dom';
import { GitBranch, GitPullRequest, Lock, Copy } from 'lucide-react';
import IconPicker from '../IconPicker';
@@ -90,6 +90,7 @@ export default function EditAppDrawer({ app, onClose, onSave }) {
const [liProviders, setLiProviders] = useState([]);
const [liIsPortos, setLiIsPortos] = useState(app.id === PORTOS_APP_ID);
const [liLoaded, setLiLoaded] = useState(false);
+ const [liError, setLiError] = useState(false);
const [tlsUpgrading, setTlsUpgrading] = useState(false);
const [tlsResult, setTlsResult] = useState(null);
const [tlsError, setTlsError] = useState(null);
@@ -155,9 +156,13 @@ export default function EditAppDrawer({ app, onClose, onSave }) {
// Load the app's effective Layered Intelligence config + the CLI provider list
// (the loop runs an agentic CLI, same as other CoS work). The tab edits a
- // working copy; on save we diff it against the baseline.
- useEffect(() => {
+ // working copy; on save we diff it against the baseline. On failure we set
+ // liError so the tab can show a retry instead of hanging on "Loading…" — the
+ // config fetch is {silent:true}, so there's no toast to surface the failure.
+ const loadLayeredIntelligence = useCallback(() => {
let cancelled = false;
+ setLiLoaded(false);
+ setLiError(false);
Promise.all([
api.getAppLayeredIntelligence(app.id),
api.getProviders({ silent: true }).catch(() => ({ providers: [] }))
@@ -168,11 +173,18 @@ export default function EditAppDrawer({ app, onClose, onSave }) {
setLiBaseline(cfg);
setLiIsPortos(!!li?.isPortos);
setLiProviders((provData?.providers || []).filter(p => p.type === 'cli' && p.enabled !== false));
+ setLiError(!cfg);
+ setLiLoaded(true);
+ }).catch(() => {
+ if (cancelled) return;
+ setLiError(true);
setLiLoaded(true);
- }).catch(() => { if (!cancelled) setLiLoaded(true); });
+ });
return () => { cancelled = true; };
}, [app.id]);
+ useEffect(() => loadLayeredIntelligence(), [loadLayeredIntelligence]);
+
const updateLiConfig = (patch) => setLiConfig(prev => ({ ...(prev || {}), ...patch }));
useEffect(() => {
@@ -651,7 +663,9 @@ export default function EditAppDrawer({ app, onClose, onSave }) {
onChange={updateLiConfig}
providers={liProviders}
isPortos={liIsPortos}
- loaded={liLoaded && !!liConfig}
+ loaded={liLoaded}
+ error={liError}
+ onRetry={loadLayeredIntelligence}
/>
)}
diff --git a/client/src/components/apps/LayeredIntelligenceTab.jsx b/client/src/components/apps/LayeredIntelligenceTab.jsx
index ee6beb4100..c07d654f92 100644
--- a/client/src/components/apps/LayeredIntelligenceTab.jsx
+++ b/client/src/components/apps/LayeredIntelligenceTab.jsx
@@ -47,11 +47,19 @@ function sameScopes(a, b) {
return a.every(s => sb.has(s));
}
+// Sanitize a custom-source list to what actually gets persisted: file-type
+// entries with a trimmed, non-blank ref. Used both to compare against the
+// baseline and to build the emitted value, so a half-typed/blank row that
+// sanitizes away doesn't register as a change (and over-persist the config).
+function sanitizeCustom(list) {
+ return (Array.isArray(list) ? list : [])
+ .map(s => ({ type: 'file', ref: String(s?.ref || '').trim() }))
+ .filter(s => s.ref);
+}
+
function sameCustom(a, b) {
- const A = Array.isArray(a) ? a : [];
- const B = Array.isArray(b) ? b : [];
- if (A.length !== B.length) return false;
- return A.every((s, i) => s?.type === B[i]?.type && s?.ref === B[i]?.ref);
+ if (a.length !== b.length) return false;
+ return a.every((s, i) => s.type === b[i].type && s.ref === b[i].ref);
}
/**
@@ -76,14 +84,13 @@ export function buildLayeredIntelligenceUpdate(baseline, current) {
const curSources = current.sources || {};
const baseSources = baseline.sources || {};
+ const curCustom = sanitizeCustom(curSources.custom);
const toggleChanged = LI_SOURCE_FIELDS.some(f => !!curSources[f.key] !== !!baseSources[f.key]);
- const customChanged = !sameCustom(curSources.custom, baseSources.custom);
+ const customChanged = !sameCustom(curCustom, sanitizeCustom(baseSources.custom));
if (toggleChanged || customChanged) {
update.sources = {
...Object.fromEntries(LI_SOURCE_FIELDS.map(f => [f.key, !!curSources[f.key]])),
- custom: (Array.isArray(curSources.custom) ? curSources.custom : [])
- .map(s => ({ type: 'file', ref: String(s?.ref || '').trim() }))
- .filter(s => s.ref)
+ custom: curCustom
};
}
@@ -101,10 +108,26 @@ export function buildLayeredIntelligenceUpdate(baseline, current) {
* with a partial update. `sources` updates merge one level deep here so a single
* toggle doesn't wipe the others.
*/
-export default function LayeredIntelligenceTab({ li, onChange, providers, isPortos, loaded }) {
+export default function LayeredIntelligenceTab({ li, onChange, providers, isPortos, loaded, error = false, onRetry }) {
if (!loaded) {
return <div className="text-sm text-gray-500">Loading Layered Intelligence config…</div>;
}
+ if (error || !li || Object.keys(li).length === 0) {
+ return (
+ <div className="space-y-3">
+ <Banner tone="error" size="md">Couldn&apos;t load the Layered Intelligence config for this app.</Banner>
+ {onRetry && (
+ <button
+ type="button"
+ onClick={onRetry}
+ className="text-xs px-3 py-1.5 bg-port-accent/20 text-port-accent hover:bg-port-accent/30 rounded"
+ >
+ Retry
+ </button>
+ )}
+ </div>
+ );
+ }
const sources = li.sources || {};
const custom = Array.isArray(sources.custom) ? sources.custom : [];
diff --git a/client/src/components/apps/LayeredIntelligenceTab.test.jsx b/client/src/components/apps/LayeredIntelligenceTab.test.jsx
index 1e7d67c4b2..d42af51455 100644
--- a/client/src/components/apps/LayeredIntelligenceTab.test.jsx
+++ b/client/src/components/apps/LayeredIntelligenceTab.test.jsx
@@ -57,6 +57,16 @@ describe('buildLayeredIntelligenceUpdate', () => {
expect(update.sources.custom).toEqual([{ type: 'file', ref: 'docs/x.md' }]);
});
+ it('ignores a blank custom-source row that sanitizes back to the baseline (no over-persist)', () => {
+ const withCustom = { ...baseline, sources: { ...baseline.sources, custom: [{ type: 'file', ref: 'docs/x.md' }] } };
+ // User clicks "Add file" but leaves the new row blank → sanitizes away → no change.
+ const update = buildLayeredIntelligenceUpdate(withCustom, {
+ ...withCustom,
+ sources: { ...withCustom.sources, custom: [{ type: 'file', ref: 'docs/x.md' }, { type: 'file', ref: '' }] }
+ });
+ expect(update).toBeNull();
+ });
+
it('detects allowedScopes changes regardless of order', () => {
// reordered = no change
expect(buildLayeredIntelligenceUpdate(baseline, { ...baseline, allowedScopes: ['app-data-gap', 'app-improvement'] })).toBeNull();
@@ -92,6 +102,19 @@ describe('LayeredIntelligenceTab (render)', () => {
expect(screen.getByText('PortOS self')).toBeInTheDocument();
});
+ it('shows an error + retry when the config failed to load', () => {
+ const onRetry = vi.fn();
+ render(<LayeredIntelligenceTab {...props} loaded={true} error={true} onRetry={onRetry} />);
+ expect(screen.getByText(/Couldn.t load the Layered Intelligence config/i)).toBeInTheDocument();
+ fireEvent.click(screen.getByRole('button', { name: /Retry/i }));
+ expect(onRetry).toHaveBeenCalled();
+ });
+
+ it('treats an empty config as an error (no fields to render)', () => {
+ render(<LayeredIntelligenceTab {...props} li={{}} loaded={true} />);
+ expect(screen.getByText(/Couldn.t load the Layered Intelligence config/i)).toBeInTheDocument();
+ });
+
it('calls onChange when a source toggle flips', () => {
const onChange = vi.fn();
render(<LayeredIntelligenceTab {...props} onChange={onChange} isPortos={false} />);