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([issue-3704]): address codex review — surface skipped notes in the UI, guard slot ownership
Adam Eivy86f68974110a
diff --git a/client/src/components/OfflineNotesNotice.jsx b/client/src/components/OfflineNotesNotice.jsxnew file mode 100644index 0000000000..197ea8e24e--- /dev/null+++ b/client/src/components/OfflineNotesNotice.jsx@@ -0,0 +1,31 @@+import { CloudOff } from 'lucide-react';++/**+ * "N notes aren't downloaded yet" banner for any Obsidian vault reader.+ *+ * Vault readers skip notes macOS has evicted to iCloud rather than blocking on an+ * un-downloadable read (see `server/lib/icloudFile.js`), and report how many they+ * skipped as `skippedUnavailable`. Without surfacing that, a search over a+ * freshly-synced Mac shows "no results" for a query whose answer is sitting in an+ * un-downloaded note — presenting an incomplete answer as authoritative.+ *+ * Renders nothing when the count is 0/absent, so callers can drop it in+ * unconditionally.+ */+export default function OfflineNotesNotice({ count, className = '' }) {+ const skipped = Number(count) || 0;+ if (skipped < 1) return null;+ return (+ <div+ role="status"+ className={`flex items-start gap-2 rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs text-amber-200 ${className}`}+ >+ <CloudOff size={14} className="mt-0.5 shrink-0" aria-hidden="true" />+ <span>+ {skipped} note{skipped === 1 ? '' : 's'} {skipped === 1 ? 'is' : 'are'} stored in iCloud but not+ downloaded to this Mac, so {skipped === 1 ? 'it was' : 'they were'} left out of these results. A+ download was requested — reload in a moment to include {skipped === 1 ? 'it' : 'them'}.+ </span>+ </div>+ );+}diff --git a/client/src/components/OfflineNotesNotice.test.jsx b/client/src/components/OfflineNotesNotice.test.jsxnew file mode 100644index 0000000000..8ab0060764--- /dev/null+++ b/client/src/components/OfflineNotesNotice.test.jsx@@ -0,0 +1,29 @@+import { describe, it, expect } from 'vitest';+import { render, screen } from '@testing-library/react';+import OfflineNotesNotice from './OfflineNotesNotice.jsx';++describe('OfflineNotesNotice', () => {+ it('renders nothing when no notes were skipped', () => {+ const { container } = render(<OfflineNotesNotice count={0} />);+ // Callers drop it in unconditionally, so 0 must be invisible — not an empty box.+ expect(container).toBeEmptyDOMElement();+ });++ it('renders nothing for an absent or non-numeric count', () => {+ expect(render(<OfflineNotesNotice />).container).toBeEmptyDOMElement();+ expect(render(<OfflineNotesNotice count={undefined} />).container).toBeEmptyDOMElement();+ expect(render(<OfflineNotesNotice count={'oops'} />).container).toBeEmptyDOMElement();+ });++ it('warns, in the singular, for one skipped note', () => {+ render(<OfflineNotesNotice count={1} />);+ const status = screen.getByRole('status');+ expect(status).toHaveTextContent(/1 note is stored in iCloud/);+ expect(status).not.toHaveTextContent(/notes are/);+ });++ it('warns, in the plural, for several', () => {+ render(<OfflineNotesNotice count={12} />);+ expect(screen.getByRole('status')).toHaveTextContent(/12 notes are stored in iCloud/);+ });+});diff --git a/client/src/components/brain/tabs/NotesTab.jsx b/client/src/components/brain/tabs/NotesTab.jsxindex 8f155a2cab..cb575285fa 100644--- a/client/src/components/brain/tabs/NotesTab.jsx+++ b/client/src/components/brain/tabs/NotesTab.jsx@@ -25,6 +25,7 @@ import FolderPicker from '../../FolderPicker';import { timeAgo, formatBytes } from '../../../utils/formatters';import { useConfirmDelete } from '../../../hooks/useConfirmDelete';import { clickableProps } from '../../../lib/a11yKeyboard.js';+import OfflineNotesNotice from '../../OfflineNotesNotice.jsx';export default function NotesTab() {// Vault state@@ -38,6 +39,9 @@ export default function NotesTab() {// Notes stateconst [notes, setNotes] = useState([]);const [totalNotes, setTotalNotes] = useState(0);+ // Notes the server skipped because iCloud hasn't downloaded them — surfaced so+ // an incomplete list isn't presented as the whole vault.+ const [skippedNotes, setSkippedNotes] = useState(0);const [loading, setLoading] = useState(true);const [scanning, setScanning] = useState(false);@@ -109,6 +113,7 @@ export default function NotesTab() {if (data) {setNotes(data.notes);setTotalNotes(data.total);+ setSkippedNotes(data.skippedUnavailable || 0);}setScanning(false);};@@ -339,6 +344,8 @@ export default function NotesTab() {)}</div>+ <OfflineNotesNotice count={skippedNotes + (searchResults?.skippedUnavailable || 0)} className="mx-3 mt-2" />+{/* Stats bar */}<div className="px-3 py-1.5 border-b border-port-border flex items-center gap-3 text-xs text-gray-500"><span>{totalNotes} notes</span>diff --git a/client/src/components/wiki/tabs/BrowseTab.jsx b/client/src/components/wiki/tabs/BrowseTab.jsxindex eba0af2782..b040a9880d 100644--- a/client/src/components/wiki/tabs/BrowseTab.jsx+++ b/client/src/components/wiki/tabs/BrowseTab.jsx@@ -9,6 +9,7 @@ import InlineConfirmRow from '../../ui/InlineConfirmRow';import { timeAgo, formatBytes } from '../../../utils/formatters';import { WIKI_CATEGORIES } from '../constants.jsx';import BrailleSpinner from '../../BrailleSpinner';+import OfflineNotesNotice from '../../OfflineNotesNotice.jsx';const WIKI_FOLDERS = WIKI_CATEGORIES.map(c => ({ key: c.folder, label: c.label, icon: c.icon, color: c.textClass }));const RAW_FOLDERS = [{ key: 'raw', label: 'Raw Sources', icon: FolderOpen, color: 'text-gray-400' }];@@ -23,6 +24,8 @@ export default function BrowseTab({ vaultId, notes, rawNotes, allNotes, onRefresconst [expandedFolders, setExpandedFolders] = useState(new Set(['wiki/sources', 'wiki/entities', 'wiki/concepts']));const [activeSection, setActiveSection] = useState('wiki');const [tags, setTags] = useState([]);+ // Tag counts under-report when iCloud hasn't downloaded some notes.+ const [skippedTagNotes, setSkippedTagNotes] = useState(0);const [showTags, setShowTags] = useState(false);const [confirmDelete, setConfirmDelete] = useState(null);const editorRef = useRef(null);@@ -69,6 +72,7 @@ export default function BrowseTab({ vaultId, notes, rawNotes, allNotes, onRefresconst loadTags = async () => {const data = await api.getNotesVaultTags(vaultId).catch(() => null);if (data?.tags) setTags(data.tags);+ setSkippedTagNotes(data?.skippedUnavailable || 0);};const toggleFolder = (folder) => {@@ -130,6 +134,7 @@ export default function BrowseTab({ vaultId, notes, rawNotes, allNotes, onRefres</div>{/* Tags */}+ {showTags && <OfflineNotesNotice count={skippedTagNotes} className="mx-3 mt-2" />}{showTags && tags.length > 0 && (<div className="px-3 py-2 border-b border-port-border flex flex-wrap gap-1 max-h-24 overflow-auto">{tags.map(t => (diff --git a/client/src/components/wiki/tabs/GraphTab.jsx b/client/src/components/wiki/tabs/GraphTab.jsxindex f8fb69ed8c..f35fb1ca64 100644--- a/client/src/components/wiki/tabs/GraphTab.jsx+++ b/client/src/components/wiki/tabs/GraphTab.jsx@@ -4,6 +4,7 @@ import * as api from '../../../services/api';import { RefreshCw, Network, ZoomIn, ZoomOut } from 'lucide-react';import { WIKI_CATEGORIES } from '../constants.jsx';import BrailleSpinner from '../../BrailleSpinner';+import OfflineNotesNotice from '../../OfflineNotesNotice.jsx';export default function GraphTab({ vaultId }) {const navigate = useNavigate();@@ -202,6 +203,7 @@ export default function GraphTab({ vaultId }) {{/* Controls */}<div className="absolute top-4 right-4 z-10 flex items-center gap-2"><span className="text-xs text-gray-500">{graphData.totalNodes} nodes, {graphData.totalEdges} edges</span>+ <OfflineNotesNotice count={graphData.skippedUnavailable} className="w-full mt-2" /><buttononClick={() => setZoom(z => Math.min(z + 0.2, 3))}aria-label="Zoom in"diff --git a/client/src/components/wiki/tabs/SearchTab.jsx b/client/src/components/wiki/tabs/SearchTab.jsxindex 758a463123..4a11494b95 100644--- a/client/src/components/wiki/tabs/SearchTab.jsx+++ b/client/src/components/wiki/tabs/SearchTab.jsx@@ -2,6 +2,7 @@ import { useState, useCallback, useRef } from 'react';import { useNavigate } from 'react-router';import * as api from '../../../services/api';import { Search, FileText, X, RefreshCw, Tag } from 'lucide-react';+import OfflineNotesNotice from '../../OfflineNotesNotice.jsx';export default function SearchTab({ vaultId }) {const navigate = useNavigate();@@ -56,6 +57,7 @@ export default function SearchTab({ vaultId }) {{/* Results */}{results && (<div>+ <OfflineNotesNotice count={results.skippedUnavailable} className="mb-3" /><div className="text-sm text-gray-500 mb-3">{results.total} result{results.total !== 1 ? 's' : ''} for “{results.query}”</div>diff --git a/server/lib/icloudFile.js b/server/lib/icloudFile.jsindex 6eb4b025ab..37510acc39 100644--- a/server/lib/icloudFile.js+++ b/server/lib/icloudFile.js@@ -165,10 +165,13 @@ function markBrctlMissing() {return true;}-// Dedupe of in-flight background materializations, keyed by path, so repeated-// reads of the same evicted file don't spawn a `brctl` per request. Entries clear-// when the child exits, so a later read can retry.-const pendingDownloads = new Set();+// In-flight background materializations, `path -> child`. The child doubles as an+// identity token: cleanup must only clear the entry it owns. A deadline kill frees+// the slot before that child's 'exit' fires, so a read arriving in between can+// legitimately start a REPLACEMENT for the same path — and the old child's late+// 'exit' must not then delete the replacement's entry, which would let the next+// read spawn a duplicate and break the concurrency cap.+const pendingDownloads = new Map();// Hard cap on concurrent background downloads. Without it, a vault-wide walk over// an evicted Obsidian vault (one read per note) would spawn one `brctl` child per@@ -199,7 +202,6 @@ export function requestMaterialization(path, label = 'iCloud file') {if (!isHealablePath(path)) return false;if (pendingDownloads.has(path)) return false;if (pendingDownloads.size >= MAX_PENDING_DOWNLOADS) return false;- pendingDownloads.add(path);// try/catch at a child-process boundary (permitted by the repo's no-try/catch// rule): `spawn` can throw synchronously on resource exhaustion (EMFILE), and@@ -211,10 +213,18 @@ export function requestMaterialization(path, label = 'iCloud file') {child = spawn('brctl', ['download', path], { detached: true, stdio: 'ignore' });child.unref();} catch (err) {- pendingDownloads.delete(path);+ // Nothing was reserved yet — the slot is claimed below, after a successful+ // spawn — so there is nothing to release here.console.warn(`⚠️ could not spawn brctl download for ${label}: ${err.message}`);return false;}+ // `spawn` is synchronous, so no other read can interleave between the size+ // check above and this reservation.+ pendingDownloads.set(path, child);+ // Release only the entry THIS child owns (see the map's comment above).+ const release = () => {+ if (pendingDownloads.get(path) === child) pendingDownloads.delete(path);+ };// Kill the child if it outlives its deadline, so a wedged `brctl` frees its slot// instead of holding it forever. `unref` so the timer itself never keeps the// process alive; the 'exit' handler below clears the slot once the kill lands.@@ -225,10 +235,10 @@ export function requestMaterialization(path, label = 'iCloud file') {try { process.kill(-child.pid, 'SIGKILL'); } catch { child.kill('SIGKILL'); }// A killed-but-unreaped child would strand the slot; drop it now so healing// can resume even if 'exit' never fires.- pendingDownloads.delete(path);+ release();}, DOWNLOAD_DEADLINE_MS);deadline.unref?.();- const settle = () => { clearTimeout(deadline); pendingDownloads.delete(path); };+ const settle = () => { clearTimeout(deadline); release(); };// Capture `path` in each handler so a late exit from one child can't clear the// dedupe entry for a different path.diff --git a/server/lib/icloudFile.test.js b/server/lib/icloudFile.test.jsindex 60b234b934..a27b7db99e 100644--- a/server/lib/icloudFile.test.js+++ b/server/lib/icloudFile.test.js@@ -402,3 +402,41 @@ describe('background download deadline', () => {}});});++describe('background download slot ownership', () => {+ it("a timed-out child's late exit must not release a replacement's slot", async () => {+ const originalDeadline = icloud.DOWNLOAD_DEADLINE_MS;+ icloud._setDownloadDeadlineForTest(10);+ const killSpy = vi.spyOn(process, 'kill').mockImplementation(() => true);+ try {+ statMock.mockResolvedValue(datalessStats);+ const children = [];+ spawnMock.mockImplementation(() => { const c = makeFakeChild(); c.pid = 1000 + children.length; children.push(c); return c; });++ const P = `${UBIQUITY_DIR}/contested.md`;+ await icloud.readIfMaterialized(P).catch(() => {});+ expect(spawnMock).toHaveBeenCalledTimes(1);++ // Deadline fires and frees the slot; a fresh read then starts a REPLACEMENT+ // child for the same path.+ await new Promise(r => setTimeout(r, 30));+ await icloud.readIfMaterialized(P).catch(() => {});+ expect(spawnMock).toHaveBeenCalledTimes(2);++ // Now the ORIGINAL child finally exits. Without identity-guarded cleanup it+ // would delete the replacement's entry, letting the next read spawn a+ // duplicate for a path already downloading — and eroding the 4-child cap.+ children[0].emit('exit', null, 'SIGKILL');+ await icloud.readIfMaterialized(P).catch(() => {});+ expect(spawnMock).toHaveBeenCalledTimes(2);++ // The replacement's own exit does release it.+ children[1].emit('exit', 0, null);+ await icloud.readIfMaterialized(P).catch(() => {});+ expect(spawnMock).toHaveBeenCalledTimes(3);+ } finally {+ killSpy.mockRestore();+ icloud._setDownloadDeadlineForTest(originalDeadline);+ }+ });+});