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

fix: open exact memories and ideas from On This Day (#9763)

Adam Eivy5c023a6e23c9
diff --git a/client/src/components/brain/tabs/BrainCollectionPagination.test.jsx b/client/src/components/brain/tabs/BrainCollectionPagination.test.jsx
index 6b2be07584..a264cc731d 100644
--- a/client/src/components/brain/tabs/BrainCollectionPagination.test.jsx
+++ b/client/src/components/brain/tabs/BrainCollectionPagination.test.jsx
@@ -304,7 +304,7 @@ describe('Brain collection pagination & UI bounds', () => {
// Ensure detail endpoint was called on demand
await waitFor(() => {
- expect(api.getBrainMemory).toHaveBeenCalledWith('mem-deeplink');
+ expect(api.getBrainMemory).toHaveBeenCalledWith('mem-deeplink', { silent: true });
});
// Full content rendered in reader pane
diff --git a/client/src/components/brain/tabs/MemoryTab.jsx b/client/src/components/brain/tabs/MemoryTab.jsx
index 06a96b235a..515980e0ec 100644
--- a/client/src/components/brain/tabs/MemoryTab.jsx
+++ b/client/src/components/brain/tabs/MemoryTab.jsx
@@ -72,7 +72,8 @@ export default function MemoryTab({ onRefresh, fixedType = null }) {
const [searchQuery, setSearchQuery] = useState('');
const [debouncedSearch, setDebouncedSearch] = useState('');
const [backendStatus, setBackendStatus] = useState(null);
- const [deepLinkedRecord, setDeepLinkedRecord] = useState(null);
+ const [detailResult, setDetailResult] = useState(null);
+ const selectedType = fixedType || recordType || activeType;
const { isConfirming, requestDelete, cancelDelete } = useConfirmDelete();
useEffect(() => {
@@ -143,58 +144,50 @@ export default function MemoryTab({ onRefresh, fixedType = null }) {
return () => socket.off('connect', handleConnect);
}, [paged.refreshFirst]);
- // Direct URL deep-link or truncated record detail fetch
+ // Resolve the URL independently of the current collection page. Track the
+ // requested identity even for a missing record so pending and missing differ.
+ const listedRecord = activeType === selectedType
+ ? records.find(r => r.id === recordId && !r.contentTruncated)
+ : null;
useEffect(() => {
- if (!recordId) {
- setDeepLinkedRecord(null);
- return;
- }
- const existing = records.find(r => r.id === recordId);
- if (!existing || existing.contentTruncated) {
- let active = true;
- const fetchRecord = async () => {
- let full = null;
- switch (activeType) {
- case 'people':
- full = await api.getBrainPerson(recordId).catch(() => null);
- break;
- case 'projects':
- full = await api.getBrainProject(recordId).catch(() => null);
- break;
- case 'ideas':
- full = await api.getBrainIdea(recordId).catch(() => null);
- break;
- case 'admin':
- full = await api.getBrainAdminItem(recordId).catch(() => null);
- break;
- case 'memories':
- default:
- full = await api.getBrainMemory(recordId).catch(() => null);
- break;
- }
- if (active) {
- if (full && !full.archived && !deletedIdsRef.current.has(full.id)) {
- setDeepLinkedRecord(full);
- } else {
- setDeepLinkedRecord(null);
- }
- }
- };
- fetchRecord();
- return () => { active = false; };
- } else {
- setDeepLinkedRecord(null);
- }
- }, [recordId, activeType, records]);
+ if (!recordId || listedRecord) return;
+ let active = true;
+ const fetchRecord = async () => {
+ let full = null;
+ const options = { silent: true };
+ switch (selectedType) {
+ case 'people':
+ full = await api.getBrainPerson(recordId, options).catch(() => null);
+ break;
+ case 'projects':
+ full = await api.getBrainProject(recordId, options).catch(() => null);
+ break;
+ case 'ideas':
+ full = await api.getBrainIdea(recordId, options).catch(() => null);
+ break;
+ case 'admin':
+ full = await api.getBrainAdminItem(recordId, options).catch(() => null);
+ break;
+ case 'memories':
+ default:
+ full = await api.getBrainMemory(recordId, options).catch(() => null);
+ break;
+ }
+ if (active) {
+ const record = full?.id === recordId && !full.archived && !deletedIdsRef.current.has(full.id)
+ ? full : null;
+ setDetailResult({ id: recordId, type: selectedType, record });
+ }
+ };
+ // Clear a previous visit's result, including when Back revisits the same ID.
+ setDetailResult(null);
+ fetchRecord();
+ return () => { active = false; };
+ }, [recordId, selectedType, listedRecord]);
- const viewerRecord = useMemo(() => {
- if (!recordId) return null;
- const existing = records.find(r => r.id === recordId);
- if (deepLinkedRecord && deepLinkedRecord.id === recordId) {
- return deepLinkedRecord;
- }
- return existing || null;
- }, [recordId, records, deepLinkedRecord]);
+ const detailResolved = detailResult?.id === recordId && detailResult?.type === selectedType;
+ const viewerRecord = recordId ? (listedRecord || (detailResolved ? detailResult.record : null)) : null;
+ const viewerLoading = !!recordId && !listedRecord && !detailResolved;
const fetchBackendStatus = useCallback(() => {
api.getMemoryBackendStatus().then(setBackendStatus).catch(() => null);
@@ -698,7 +691,15 @@ export default function MemoryTab({ onRefresh, fixedType = null }) {
{activeType === 'ideas' && (
<>
<div className="flex items-center gap-2">
- <h3 className="font-medium text-white">{record.title}</h3>
+ <h3 className="font-medium text-white">
+ <button
+ onClick={() => navigate(`${basePath}/ideas/${encodeURIComponent(record.id)}${location.search}`)}
+ className="text-left hover:text-port-accent"
+ aria-label={`Read ${record.title || 'idea'}`}
+ >
+ {record.title}
+ </button>
+ </h3>
<span className={`px-2 py-0.5 text-xs rounded border ${IDEA_STATUS_COLORS[record.status || 'active']}`}>
{record.status || 'active'}
</span>
@@ -917,7 +918,7 @@ export default function MemoryTab({ onRefresh, fixedType = null }) {
{/* Main content area: split into list + sidebar preview when an entry is active */}
<div className={`flex flex-col lg:flex-row gap-4 ${fixedType ? 'items-start' : 'flex-1 min-h-0 overflow-hidden'}`}>
{/* Left column: search, add form, records list */}
- <div role="region" aria-label="Memory entries" tabIndex={0} className={`flex-1 min-w-0 w-full space-y-4 ${fixedType ? '' : 'min-h-0 overflow-y-auto overscroll-contain'} ${recordId && !loading ? 'hidden lg:block' : 'block'}`}>
+ <div role="region" aria-label="Memory entries" tabIndex={0} className={`flex-1 min-w-0 w-full space-y-4 ${fixedType ? '' : 'min-h-0 overflow-y-auto overscroll-contain'} ${recordId ? 'hidden lg:block' : 'block'}`}>
{/* Search filter */}
<div className="relative">
<Search size={16} className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-500" />
@@ -1002,9 +1003,16 @@ export default function MemoryTab({ onRefresh, fixedType = null }) {
</div>
{/* Right column: Sidebar preview for full content */}
- {recordId && !loading && (
+ {recordId && (
<div className={`w-full lg:w-[480px] xl:w-[560px] 2xl:w-[640px] shrink-0 ${fixedType ? '' : 'h-full min-h-0 overflow-y-auto'}`}>
- {viewerRecord ? (
+ {viewerLoading ? (
+ <aside aria-label="Loading entry" className="bg-port-card border border-port-border rounded-lg p-4">
+ <BrailleSpinner text="Loading entry" />
+ <button onClick={closeReader} className="block min-h-[44px] text-port-accent hover:underline">
+ Back to entries
+ </button>
+ </aside>
+ ) : viewerRecord ? (
<ConversationViewer
key={viewerRecord.id}
record={viewerRecord}
@@ -1019,7 +1027,7 @@ export default function MemoryTab({ onRefresh, fixedType = null }) {
className="bg-port-card border border-port-border rounded-lg p-4 flex flex-col w-full shadow-lg lg:sticky lg:top-4"
>
<Banner tone="warning" title="Entry not found">
- This entry may have been deleted or archived.
+ This entry may have been deleted, archived, or could not be loaded.
<button onClick={closeReader} className="block min-h-[44px] text-port-accent hover:underline">
Back to entries
</button>
diff --git a/client/src/components/dashboard/builtins/OnThisDayWidget.jsx b/client/src/components/dashboard/builtins/OnThisDayWidget.jsx
index af01ecc02e..6a645923f3 100644
--- a/client/src/components/dashboard/builtins/OnThisDayWidget.jsx
+++ b/client/src/components/dashboard/builtins/OnThisDayWidget.jsx
@@ -9,8 +9,8 @@ import { History, Lightbulb, BookOpen, NotebookPen } from 'lucide-react';
// lookbacks, so a mounted widget always has rows — no empty state needed.
const ROW_META = {
journal: { icon: NotebookPen, label: 'Daily Log', link: (item) => `/brain/daily-log?date=${item.date}` },
- memory: { icon: BookOpen, label: 'Memory', link: () => '/brain/memory' },
- idea: { icon: Lightbulb, label: 'Idea', link: () => '/brain/ideas' },
+ memory: { icon: BookOpen, label: 'Memory', link: (item) => `/brain/memory/memories/${encodeURIComponent(item.id)}` },
+ idea: { icon: Lightbulb, label: 'Idea', link: (item) => `/brain/ideas/ideas/${encodeURIComponent(item.id)}` },
};
const yearsAgoLabel = (yearsAgo) => (yearsAgo === 1 ? '1 year ago' : `${yearsAgo} years ago`);
diff --git a/client/src/components/dashboard/builtins/OnThisDayWidget.navigation.test.jsx b/client/src/components/dashboard/builtins/OnThisDayWidget.navigation.test.jsx
new file mode 100644
index 0000000000..4710ba7bd0
--- /dev/null
+++ b/client/src/components/dashboard/builtins/OnThisDayWidget.navigation.test.jsx
@@ -0,0 +1,147 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { act, cleanup, fireEvent, render, screen, within } from '@testing-library/react';
+import { MemoryRouter, Route, Routes, useLocation, useNavigate } from 'react-router';
+import Brain from '../../../pages/Brain';
+import OnThisDayWidget from './OnThisDayWidget';
+
+const api = vi.hoisted(() => ({
+ getBrainSummary: vi.fn().mockResolvedValue({ counts: {} }),
+ getBrainSettings: vi.fn().mockResolvedValue({}),
+ getMemoryBackendStatus: vi.fn().mockResolvedValue({ backend: 'postgres' }),
+ getBrainMemories: vi.fn(),
+ getBrainMemory: vi.fn(),
+ getBrainIdeas: vi.fn(),
+ getBrainIdea: vi.fn(),
+}));
+vi.mock('../../../services/api', () => api);
+vi.mock('../../../services/socket', () => ({ default: { on: vi.fn(), off: vi.fn() } }));
+
+const first = { id: 'example-first', title: 'Example first', content: '**First full text**', notes: '**First full text**' };
+const second = { id: 'example-second', title: 'Example second', content: '**Second full text**', notes: '**Second full text**' };
+
+function Navigation() {
+ const navigate = useNavigate();
+ return <>
+ <output data-testid="location">{useLocation().pathname}</output>
+ <button onClick={() => navigate(-1)}>Browser Back</button>
+ <button onClick={() => navigate('/brain/memory/memories/example-first')}>Select first memory</button>
+ </>;
+}
+
+function mount(type, path = '/') {
+ return render(
+ <MemoryRouter initialEntries={[path]}>
+ <Navigation />
+ <Routes>
+ <Route path="/" element={<OnThisDayWidget dashboardState={{ brainOnThisDay: {
+ total: 2, items: [first, second].map(record => ({ ...record, type, yearsAgo: 1 }))
+ } }} />} />
+ {/* Use the same base and detail route shapes as App, with real lazy Brain tabs. */}
+ <Route path="/brain/:tab/:recordType/:recordId" element={<Brain />} />
+ <Route path="/brain/:tab" element={<Brain />} />
+ </Routes>
+ </MemoryRouter>
+ );
+}
+
+beforeEach(() => {
+ api.getBrainMemories.mockResolvedValue({ items: [first], total: 2, nextCursor: 'older-page' });
+ api.getBrainIdeas.mockResolvedValue({ items: [first], total: 2, nextCursor: 'older-page' });
+ api.getBrainMemory.mockResolvedValue(second);
+ api.getBrainIdea.mockResolvedValue(second);
+ vi.stubGlobal('IntersectionObserver', class {
+ observe() {}
+ disconnect() {}
+ });
+});
+afterEach(() => { cleanup(); vi.clearAllMocks(); vi.unstubAllGlobals(); });
+
+describe('On This Day record destinations', () => {
+ it.each([
+ ['memory', '/brain/memory/memories/example-second', 'getBrainMemory'],
+ ['idea', '/brain/ideas/ideas/example-second', 'getBrainIdea'],
+ ])('opens the exact %s outside the visible page, preserves its URL on reload, and goes Back', async (type, path, getter) => {
+ let resolveDetail;
+ let resolvePage;
+ const listGetter = type === 'memory' ? 'getBrainMemories' : 'getBrainIdeas';
+ const page = { items: [first], total: 2, nextCursor: 'older-page' };
+ api[listGetter].mockImplementation(() => new Promise(resolve => { resolvePage = resolve; }));
+ api[getter].mockImplementation(() => new Promise(resolve => { resolveDetail = resolve; }));
+ const view = mount(type);
+ fireEvent.click(screen.getByRole('link', { name: /Example second/ }));
+ expect(screen.getByTestId('location').textContent).toBe(path);
+ expect(await screen.findByRole('complementary', { name: 'Loading entry' })).toBeTruthy();
+ expect(screen.queryByText('Entry not found')).toBeNull();
+ expect(screen.queryByRole('complementary', { name: 'Preview: Example first' })).toBeNull();
+
+ await act(async () => resolveDetail(second));
+ const reader = await screen.findByRole('complementary', { name: 'Preview: Example second' });
+ expect(within(reader).getByText('Second full text').tagName).toBe('STRONG');
+ expect(api[getter]).toHaveBeenCalledWith(second.id, { silent: true });
+ // The selected reader renders even while the collection page is still pending.
+ await act(async () => resolvePage(page));
+ api[listGetter].mockResolvedValue(page);
+
+ // A fresh mount starts with only the URL, just as a reload does.
+ view.unmount();
+ api[getter].mockResolvedValue(second);
+ const reloaded = mount(type, path);
+ expect(await screen.findByRole('complementary', { name: 'Preview: Example second' })).toBeTruthy();
+ fireEvent.click(screen.getByRole('button', { name: 'Close entry reader' }));
+ expect(screen.getByTestId('location').textContent).toBe(type === 'memory' ? '/brain/memory' : '/brain/ideas');
+ expect(await screen.findByRole('button', { name: 'Read Example first' })).toBeTruthy();
+ reloaded.unmount();
+
+ mount(type);
+ fireEvent.click(screen.getByRole('link', { name: /Example second/ }));
+ await screen.findByRole('complementary', { name: 'Preview: Example second' });
+ fireEvent.click(screen.getByRole('button', { name: 'Browser Back' }));
+ expect(screen.getByTestId('location').textContent).toBe('/');
+ expect(screen.getByRole('link', { name: /Example first/ })).toBeTruthy();
+ // The other resurfaced record still selects its own existing reader.
+ fireEvent.click(screen.getByRole('link', { name: /Example first/ }));
+ expect(await screen.findByRole('complementary', { name: 'Preview: Example first' })).toBeTruthy();
+ fireEvent.click(screen.getByRole('button', { name: 'Browser Back' }));
+ expect(screen.getByTestId('location').textContent).toBe('/');
+ });
+
+ it.each([
+ ['memory', '/brain/memory/memories/example-deleted', 'getBrainMemory'],
+ ['idea', '/brain/ideas/ideas/example-deleted', 'getBrainIdea'],
+ ])('shows missing or unavailable %s without substituting the first list record', async (type, path, getter) => {
+ if (type === 'memory') api[getter].mockResolvedValue(null);
+ else api[getter].mockRejectedValue(new Error('Example unavailable'));
+ mount(type, path);
+ expect(await screen.findByText('Entry not found')).toBeTruthy();
+ expect(screen.getByText(/could not be loaded/)).toBeTruthy();
+ expect(screen.queryByRole('complementary', { name: 'Preview: Example first' })).toBeNull();
+ fireEvent.click(screen.getByRole('button', { name: 'Back to entries' }));
+ expect(await screen.findByRole('button', { name: 'Read Example first' })).toBeTruthy();
+ });
+
+ it.each([
+ ['memory', '/brain/memory'],
+ ['idea', '/brain/ideas'],
+ ])('returns to the prior %s collection with browser Back', async (type, path) => {
+ mount(type, path);
+ fireEvent.click(await screen.findByRole('button', { name: 'Read Example first' }));
+ expect(await screen.findByRole('complementary', { name: 'Preview: Example first' })).toBeTruthy();
+ fireEvent.click(screen.getByRole('button', { name: 'Browser Back' }));
+ expect(screen.getByTestId('location').textContent).toBe(path);
+ expect(await screen.findByRole('button', { name: 'Read Example first' })).toBeTruthy();
+ expect(screen.queryByRole('complementary')).toBeNull();
+ });
+
+ it('drops a superseded detail response when another URL selects a different record', async () => {
+ let resolveDetail;
+ api.getBrainMemory.mockImplementation(() => new Promise(resolve => { resolveDetail = resolve; }));
+ mount('memory', '/brain/memory/memories/example-second');
+ await screen.findByRole('complementary', { name: 'Loading entry' });
+ fireEvent.click(screen.getByRole('button', { name: 'Select first memory' }));
+ await screen.findByRole('complementary', { name: 'Preview: Example first' });
+ await act(async () => resolveDetail(second));
+ expect(screen.getByTestId('location').textContent).toBe('/brain/memory/memories/example-first');
+ expect(screen.getByRole('complementary', { name: 'Preview: Example first' })).toBeTruthy();
+ expect(screen.queryByRole('complementary', { name: 'Preview: Example second' })).toBeNull();
+ });
+});
diff --git a/client/src/components/dashboard/builtins/OnThisDayWidget.test.jsx b/client/src/components/dashboard/builtins/OnThisDayWidget.test.jsx
index b1b631abfa..80ec2f31f2 100644
--- a/client/src/components/dashboard/builtins/OnThisDayWidget.test.jsx
+++ b/client/src/components/dashboard/builtins/OnThisDayWidget.test.jsx
@@ -29,7 +29,7 @@ describe('OnThisDayWidget', () => {
});
const hrefs = screen.getAllByRole('link').map((a) => a.getAttribute('href'));
- expect(hrefs).toEqual(['/brain/daily-log?date=2025-09-01', '/brain/memory', '/brain/ideas']);
+ expect(hrefs).toEqual(['/brain/daily-log?date=2025-09-01', '/brain/memory/memories/m1', '/brain/ideas/ideas/i1']);
expect(screen.getByText('1 year ago · Daily Log')).toBeTruthy();
expect(screen.getByText('2 years ago · Memory')).toBeTruthy();
expect(screen.getByText('shipped the thing')).toBeTruthy();