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
perf: conflicts list returns a compact projection and loads diffs on expand (#13051)
[._.]/dac05a37f4d4
diff --git a/client/src/components/sharing/ConflictsTab.jsx b/client/src/components/sharing/ConflictsTab.jsxindex e4bf7b5ce7..c2c92e9a59 100644--- a/client/src/components/sharing/ConflictsTab.jsx+++ b/client/src/components/sharing/ConflictsTab.jsx@@ -9,7 +9,7 @@ import { useEffect, useState, useCallback } from 'react';import { Loader2, GitMerge, RotateCcw, Trash2, ChevronDown, ChevronRight } from 'lucide-react';import toast from '../ui/Toast';import InlineDiff from '../ui/InlineDiff';-import { listConflicts, resolveConflict, deleteConflict } from '../../services/api';+import { listConflicts, getConflict, resolveConflict, deleteConflict } from '../../services/api';import LoadFailedState from '../ui/LoadFailedState';const asText = (v) => {@@ -37,6 +37,9 @@ export default function ConflictsTab() {useEffect(() => { load(); }, [load]);+ // Resolved/removed rows leave local state; re-downloading the list is unnecessary.+ const removeEntry = useCallback((id) => setConflicts((cs) => cs?.filter((c) => c.id !== id) ?? cs), []);+if (loading) {return <div className="flex items-center gap-2 text-gray-400 text-sm py-8"><Loader2 className="animate-spin" size={16} /> Loading conflicts…</div>;}@@ -56,7 +59,7 @@ export default function ConflictsTab() {{conflicts?.length === 0 ? (<div className="text-sm text-gray-500 py-8 text-center border border-port-border rounded-lg">✓ No pending conflicts.</div>) : (- conflicts?.map((c) => <ConflictEntry key={c.id} entry={c} onResolved={load} />)+ conflicts?.map((c) => <ConflictEntry key={c.id} entry={c} onResolved={removeEntry} />))}</div>);@@ -66,9 +69,28 @@ function ConflictEntry({ entry, onResolved }) {const [expanded, setExpanded] = useState(false);const [selectedFields, setSelectedFields] = useState(() => new Set());const [busy, setBusy] = useState(false);+ // Full entry (diff values) loads the first time the row expands; the list is a compact projection.+ const [detail, setDetail] = useState(null);+ const [detailError, setDetailError] = useState(null);+ const [detailLoading, setDetailLoading] = useState(false);const fields = (entry.diffSummary || []).map((d) => d.field);+ const loadDetail = async () => {+ setDetailLoading(true);+ setDetailError(null);+ await getConflict(entry.id, { silent: true })+ .then(setDetail)+ .catch((err) => setDetailError(err.message || 'Failed to load'));+ setDetailLoading(false);+ };++ const toggleExpanded = () => {+ const next = !expanded;+ setExpanded(next);+ if (next && !detail && !detailLoading) loadDetail();+ };+const resolve = async (action, fieldList) => {setBusy(true);const ok = await resolveConflict(entry.id, { action, ...(fieldList ? { fields: fieldList } : {}) }, { silent: true })@@ -79,7 +101,7 @@ function ConflictEntry({ entry, onResolved }) {: action === 'merge-fields' ? 'Merged selected fields.': 'Restored your version.';toast.success(msg);- onResolved();+ onResolved(entry.id);}};@@ -88,7 +110,7 @@ function ConflictEntry({ entry, onResolved }) {const ok = await deleteConflict(entry.id, { silent: true }).then(() => true).catch((err) => { toast.error(`Delete failed: ${err.message}`); return false; });setBusy(false);- if (ok) onResolved();+ if (ok) onResolved(entry.id);};const toggleField = (f) => setSelectedFields((s) => {@@ -100,7 +122,7 @@ function ConflictEntry({ entry, onResolved }) {return (<div className="border border-port-border rounded-lg bg-port-card"><div className="flex items-center justify-between gap-3 p-3">- <button type="button" onClick={() => setExpanded((v) => !v)} className="flex items-center gap-2 min-w-0 text-left">+ <button type="button" onClick={toggleExpanded} className="flex items-center gap-2 min-w-0 text-left">{expanded ? <ChevronDown size={14} className="text-gray-500 shrink-0" /> : <ChevronRight size={14} className="text-gray-500 shrink-0" />}<span className="text-sm text-white truncate">{entry.recordKind} <span className="font-mono text-[11px] text-gray-500">{entry.recordId?.slice(0, 14)}</span>@@ -126,7 +148,14 @@ function ConflictEntry({ entry, onResolved }) {{expanded && (<div className="border-t border-port-border p-3 space-y-3">- {(entry.diffSummary || []).map((d) => (+ {detailLoading && <div className="flex items-center gap-2 text-gray-400 text-xs"><Loader2 className="animate-spin" size={14} /> Loading diff…</div>}+ {detailError && (+ <div role="alert" className="text-xs text-port-error flex items-center gap-2">+ Could not load the diff: {detailError}+ <button type="button" onClick={loadDetail} className="underline">Retry</button>+ </div>+ )}+ {(detail?.diffSummary || []).map((d) => (<div key={d.field} className="border border-port-border rounded p-2"><label className="flex items-center gap-2 text-xs text-white mb-1.5"><input type="checkbox" checked={selectedFields.has(d.field)} onChange={() => toggleField(d.field)} />diff --git a/client/src/components/sharing/ConflictsTab.test.jsx b/client/src/components/sharing/ConflictsTab.test.jsxindex 0e32ea8e66..cfd0828fd5 100644--- a/client/src/components/sharing/ConflictsTab.test.jsx+++ b/client/src/components/sharing/ConflictsTab.test.jsx@@ -4,6 +4,7 @@ import userEvent from '@testing-library/user-event';vi.mock('../../services/api', () => ({listConflicts: vi.fn(),+ getConflict: vi.fn(),resolveConflict: vi.fn(),deleteConflict: vi.fn(),}));@@ -26,9 +27,13 @@ const entry = {status: 'pending',};+// The list endpoint returns a compact projection; the full entry loads on expand.+const compact = (e) => ({ ...e, diffSummary: e.diffSummary.map(({ field, changed }) => ({ field, changed })) });+beforeEach(() => {vi.clearAllMocks();- api.listConflicts.mockResolvedValue({ conflicts: [entry] });+ api.listConflicts.mockResolvedValue({ conflicts: [compact(entry)] });+ api.getConflict.mockResolvedValue(entry);});describe('ConflictsTab', () => {@@ -76,6 +81,32 @@ describe('ConflictsTab', () => {expect(screen.getByText(/via push/)).toBeInTheDocument();});+ it('fetches the full diff once on first expand and shows no values before that', async () => {+ const user = userEvent.setup();+ render(<ConflictsTab />);+ await waitFor(() => expect(screen.getByText(/2 field\(s\)/)).toBeInTheDocument());+ expect(api.getConflict).not.toHaveBeenCalled();+ expect(screen.queryByTestId('diff')).not.toBeInTheDocument();++ await user.click(screen.getByText(/u-123456789012/));+ expect(await screen.findAllByTestId('diff')).toHaveLength(2);+ expect(api.getConflict).toHaveBeenCalledWith('entry-1', expect.anything());++ await user.click(screen.getByText(/u-123456789012/)); // collapse+ await user.click(screen.getByText(/u-123456789012/)); // re-expand: cached+ expect(api.getConflict).toHaveBeenCalledTimes(1);+ });++ it('removes a resolved row locally without re-listing', async () => {+ api.resolveConflict.mockResolvedValue({ status: 'resolved' });+ const user = userEvent.setup();+ render(<ConflictsTab />);+ await waitFor(() => expect(screen.getByText(/2 field\(s\)/)).toBeInTheDocument());+ await user.click(screen.getByRole('button', { name: /Discard/ }));+ expect(await screen.findByText(/No pending conflicts/)).toBeInTheDocument();+ expect(api.listConflicts).toHaveBeenCalledTimes(1);+ });+it('restore-all resolves the whole entry', async () => {api.resolveConflict.mockResolvedValue({ status: 'resolved' });const user = userEvent.setup();@@ -121,7 +152,8 @@ describe('ConflictsTab', () => {}],status: 'pending',};- api.listConflicts.mockResolvedValue({ conflicts: [deepEntry] });+ api.listConflicts.mockResolvedValue({ conflicts: [compact(deepEntry)] });+ api.getConflict.mockResolvedValue(deepEntry);api.resolveConflict.mockResolvedValue({ status: 'resolved' });const user = userEvent.setup();render(<ConflictsTab />);diff --git a/client/src/services/apiSyncReview.js b/client/src/services/apiSyncReview.jsindex 22644b3cb5..0e08d5cd25 100644--- a/client/src/services/apiSyncReview.js+++ b/client/src/services/apiSyncReview.js@@ -40,6 +40,10 @@ export const aiResolveSeriesMerge = (body, options) =>export const listConflicts = (status, options) =>request(`/conflict-journal${status ? `?status=${encodeURIComponent(status)}` : ''}`, options);+// Full entry (snapshots + per-field diff values); the list endpoint is a compact projection.+export const getConflict = (id, options) =>+ request(`/conflict-journal/${encodeURIComponent(id)}`, options);+// body: { action: 'restore-all'|'merge-fields'|'discard', fields?: string[] }export const resolveConflict = (id, body, options) =>request(`/conflict-journal/${encodeURIComponent(id)}/resolve`, { method: 'POST', body: JSON.stringify(body), ...options });diff --git a/server/routes/conflictJournal.js b/server/routes/conflictJournal.jsindex 5d242cb74a..81e9e7b414 100644--- a/server/routes/conflictJournal.js+++ b/server/routes/conflictJournal.js@@ -34,6 +34,20 @@ const resolveSchema = z.object({fields: z.array(z.string().min(1).max(64)).max(50).optional(),});+// The list needs only the collapsed-row fields. Snapshots and per-field values+// (often MBs per entry) load on demand through GET /:id.+const toListEntry = (e) => ({+ id: e.id,+ recordKind: e.recordKind,+ recordId: e.recordId,+ detectedAt: e.detectedAt,+ source: e.source,+ status: e.status,+ localUpdatedAt: e.localUpdatedAt ?? null,+ remoteUpdatedAt: e.remoteUpdatedAt ?? null,+ diffSummary: (e.diffSummary || []).map((d) => ({ field: d.field, changed: d.changed })),+});+router.get('/', asyncHandler(async (req, res) => {const { status } = validateRequest(listQuerySchema, req.query ?? {});// #7260: while the sync base-hash file is present-but-unreadable the store is@@ -42,7 +56,7 @@ router.get('/', asyncHandler(async (req, res) => {// "no conflicts"; the Conflicts tab renders this as a warning banner.const degraded = await isBaseHashPersistBlocked();res.json({- conflicts: await resolver.listConflicts({ status: status ?? null }),+ conflicts: (await resolver.listConflicts({ status: status ?? null })).map(toListEntry),conflictDetection: degraded? { degraded: true, reason: 'sync_base_hashes.json is present but unreadable — repair or delete it and restart' }: { degraded: false },diff --git a/server/routes/conflictJournal.test.js b/server/routes/conflictJournal.test.jsindex cbcec7df30..0602cdab68 100644--- a/server/routes/conflictJournal.test.js+++ b/server/routes/conflictJournal.test.js@@ -45,6 +45,25 @@ describe('conflict-journal routes', () => {expect(res.body.conflictDetection).toEqual({ degraded: false });});+ it('GET / returns a compact projection without snapshots or per-field values; GET /:id stays full', async () => {+ const full = {+ id: 'e1', recordKind: 'universe', recordId: 'u1', detectedAt: '2026-01-01T00:00:00Z',+ source: { via: 'sync' }, status: 'pending', localUpdatedAt: 'a', remoteUpdatedAt: 'b',+ localSnapshot: { big: 'x' }, remoteSnapshot: { big: 'y' },+ diffSummary: [{ field: 'name', changed: 'both', localValue: 'l', remoteValue: 'r', parts: [{ path: 'p', localValue: 1 }] }],+ };+ resolverMock.listConflicts.mockResolvedValue([full]);+ resolverMock.getConflict.mockResolvedValue(full);+ const list = await request(makeApp()).get('/api/conflict-journal?status=pending');+ expect(list.body.conflicts).toEqual([{+ id: 'e1', recordKind: 'universe', recordId: 'u1', detectedAt: '2026-01-01T00:00:00Z',+ source: { via: 'sync' }, status: 'pending', localUpdatedAt: 'a', remoteUpdatedAt: 'b',+ diffSummary: [{ field: 'name', changed: 'both' }],+ }]);+ const one = await request(makeApp()).get('/api/conflict-journal/e1');+ expect(one.body).toEqual(full);+ });+it('GET / surfaces conflictDetection.degraded while the base-hash store is latched (#7260)', async () => {resolverMock.listConflicts.mockResolvedValue([]);libMock.isBaseHashPersistBlocked.mockResolvedValue(true);