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
address review (codex): merge only clone-progress fields, drop 404s, surface the stall
[._.]/ Adam Eivyed7833d47a5c
diff --git a/client/src/components/brain/tabs/LinksTab.jsx b/client/src/components/brain/tabs/LinksTab.jsxindex 842df1051f..5df64e2233 100644--- a/client/src/components/brain/tabs/LinksTab.jsx+++ b/client/src/components/brain/tabs/LinksTab.jsx@@ -84,6 +84,21 @@ const CLONE_POLL_INTERVAL_MS = 3000;// change restarts the window; after it expires the user re-triggers the clone.const CLONE_POLL_STALL_MS = 10 * 60 * 1000;+// The fields `cloneRepoInBackground` writes as a clone progresses. The poll+// merges ONLY these onto the record it already has, so a response that was+// already in flight when the user renamed a link or dragged its chip cannot+// revert that edit with a pre-edit snapshot of the whole record.+const CLONE_PROGRESS_FIELDS = ['cloneStatus', 'cloneError', 'localPath'];++/** The clone-progress fields that actually moved, or null when none did. */+function cloneProgressPatch(fresh, current) {+ const patch = {};+ for (const field of CLONE_PROGRESS_FIELDS) {+ if (fresh[field] !== current[field]) patch[field] = fresh[field];+ }+ return Object.keys(patch).length > 0 ? patch : null;+}+export default function LinksTab({ onRefresh }) {const [inputUrl, setInputUrl] = useState('');const [inputTitle, setInputTitle] = useState('');@@ -144,30 +159,36 @@ export default function LinksTab({ onRefresh }) {setStalledPollKey(inFlightKey);return;}- // A 404 (link deleted mid-clone) or a transient failure drops that id and- // leaves every other link untouched.- const fresh = await Promise.all(- inFlightIds.map(id => api.getBrainLink(id, { silent: true }).catch(() => null))- );- const byId = new Map(fresh.filter(Boolean).map(l => [l.id, l]));- if (byId.size === 0) return;+ // A 404 means the user deleted the bookmark mid-clone: drop it, or its id+ // stays in the in-flight set and is polled until the stall bound. Any other+ // failure is transient and leaves that link exactly as it is.+ const settled = await Promise.all(inFlightIds.map(id => api.getBrainLink(id, { silent: true })+ .then(fresh => ({ id, fresh }))+ .catch(err => ({ id, gone: err?.status === 404 }))));+ const byId = new Map(settled.map(r => [r.id, r]));setLinks(prev => {let changed = false;- const next = prev.map(l => {- const updated = byId.get(l.id);- // `updatedAt` is the storage layer's write clock; `cloneStatus` is a- // belt-and-braces second signal. Unchanged records keep their identity- // so the boards, chips, and search results don't re-render on a tick.- if (!updated || (updated.updatedAt === l.updatedAt && updated.cloneStatus === l.cloneStatus)) return l;+ const next = [];+ for (const link of prev) {+ const result = byId.get(link.id);+ if (result?.gone) { changed = true; continue; }+ const patch = result?.fresh ? cloneProgressPatch(result.fresh, link) : null;+ if (!patch) { next.push(link); continue; }changed = true;- return updated;- });+ next.push({ ...link, ...patch });+ }+ // Unchanged records keep their identity — and an all-quiet tick keeps the+ // array itself — so the boards, chips, and search don't re-render.return changed ? next : prev;});}, [inFlightKey]);+ // True once the poll gave up: the badges below say so rather than showing a+ // spinner for a status nothing is watching any more.+ const cloneWatchStalled = inFlightIds.length > 0 && stalledPollKey === inFlightKey;+useAutoRefetch(pollInFlightClones, CLONE_POLL_INTERVAL_MS, {- enabled: inFlightIds.length > 0 && stalledPollKey !== inFlightKey,+ enabled: inFlightIds.length > 0 && !cloneWatchStalled,// The initial `fetchLinks` already delivered current statuses, so the first// tick belongs one interval out, not immediately on enable.immediate: false,@@ -757,6 +778,14 @@ export default function LinksTab({ onRefresh }) {{link.cloneStatus === 'cloning' && 'Cloning...'}{link.cloneStatus === 'pending' && 'Pending clone'}{link.cloneStatus === 'failed' && 'Clone failed'}+ {cloneWatchStalled && isCloneInFlight(link) && (+ <span+ className="text-gray-500"+ title="No change for 10 minutes — this tab stopped checking. Reload the page to resume."+ >+ (stalled)+ </span>+ )}</span>{/* Clone error */}diff --git a/client/src/components/brain/tabs/LinksTab.test.jsx b/client/src/components/brain/tabs/LinksTab.test.jsxindex 207eb897d3..77476e44ce 100644--- a/client/src/components/brain/tabs/LinksTab.test.jsx+++ b/client/src/components/brain/tabs/LinksTab.test.jsx@@ -114,11 +114,11 @@ describe('LinksTab clone-status polling', () => {expect(getBrainLink).toHaveBeenCalledTimes(callsAfterCompletion);});- it('leaves the other links intact when one in-flight id 404s', async () => {+ it('leaves the other links intact when one in-flight id fails transiently', async () => {getBrainLinks.mockResolvedValue({ links: [link('a', 'cloning'), link('c', 'cloning')] });getBrainLink.mockImplementation(async (id) => {- if (id === 'a') throw new Error('Link not found');- return link('c', 'cloned', { updatedAt: '2026-01-01T00:05:00.000Z' });+ if (id === 'a') throw Object.assign(new Error('Server unreachable'), { status: 503 });+ return link('c', 'cloned');});await renderTab();@@ -129,6 +129,41 @@ describe('LinksTab clone-status polling', () => {expect(screen.getByText('repo-c')).toBeTruthy();});+ // Without this the deleted record keeps its slot in the in-flight set and is+ // polled every 3s until the stall bound expires.+ it('drops a link deleted mid-clone and stops polling it', async () => {+ getBrainLinks.mockResolvedValue({ links: [link('a', 'cloning'), link('c', 'cloning')] });+ getBrainLink.mockImplementation(async (id) => {+ if (id === 'a') throw Object.assign(new Error('Link not found'), { status: 404 });+ return link('c', 'cloning');+ });+ await renderTab();++ await tick();+ expect(screen.queryByText('repo-a')).toBeNull();+ expect(screen.getByText('repo-c')).toBeTruthy();++ getBrainLink.mockClear();+ await tick();+ expect(getBrainLink.mock.calls.map(([id]) => id)).toEqual(['c']);+ });++ // The poll's job is the clone badge; it must not carry a pre-edit snapshot of+ // the rest of the record back over a local change.+ it('merges only the clone-progress fields, never the whole record', async () => {+ getBrainLinks.mockResolvedValue({ links: [link('a', 'cloning', { title: 'renamed-locally' })] });+ getBrainLink.mockResolvedValue(link('a', 'cloned', { title: 'repo-a', localPath: '/repos/a' }));+ await renderTab();++ await tick();+ expect(screen.getByText('Cloned')).toBeTruthy();+ // The clone's own localPath landed…+ expect(screen.getByText('repos/a')).toBeTruthy();+ // …but the stale title from the same response did not.+ expect(screen.getByText('renamed-locally')).toBeTruthy();+ expect(screen.queryByText('repo-a')).toBeNull();+ });+it('does not re-render the list from a replaced array when a tick brings no change', async () => {getBrainLinks.mockResolvedValue({ links: [link('a', 'cloning')] });getBrainLink.mockResolvedValue(link('a', 'cloning'));@@ -153,8 +188,9 @@ describe('LinksTab clone-status polling', () => {await tick(60 * 1000);expect(getBrainLink).toHaveBeenCalledTimes(stalledAt);- // The badge still reports the last known state — the user retriggers it.+ // …and says so, rather than spinning on a status nothing is watching.expect(screen.getByText('Cloning...')).toBeTruthy();+ expect(screen.getByText('(stalled)')).toBeTruthy();});it('restarts the stall window when a clone actually progresses', async () => {