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: keep a Beeper write for one conversation off the one you switched to
Adam Eivy5a2314bc96c5
diff --git a/client/src/components/messages/BeeperTab.test.jsx b/client/src/components/messages/BeeperTab.test.jsxindex 133f27f7b1..fa9a801d46 100644--- a/client/src/components/messages/BeeperTab.test.jsx+++ b/client/src/components/messages/BeeperTab.test.jsx@@ -1167,6 +1167,119 @@ describe('the two wired rail controls', () => {});});+// The composer and Send are bound to the conversation in the URL. Every write+// that answers for the conversation it was issued from must therefore stay off+// the thread once the user has opened another one; otherwise the header,+// roster and messages name one contact while Send goes to another.+describe('a conversation write that settles after a switch', () => {+ const SAM = { sourceUserId: 'user-1', displayName: 'Sam Example', handle: '+15550100', tribePersonId: null, tribePersonName: null, observedVia: 'participant-list' };+ const CONV_A_RECORD = conversation({ id: CONV_A, title: 'Example A', sourceChatId: 'chat-example-1', participants: [SAM] });+ const CONV_B_RECORD = conversation({ id: CONV_B, title: 'Example B', sourceChatId: 'chat-example-2' });+ const deferred = () => {+ let resolve;+ const promise = new Promise((done) => { resolve = done; });+ return { promise, resolve };+ };+ const findThreadAction = (name) => waitFor(() => {+ const controls = screen.getAllByRole('button', { name });+ expect(controls.length).toBeGreaterThan(1);+ return controls.at(-1);+ });+ const openA = async () => {+ api.getBeeperConversations.mockResolvedValue({ conversations: [CONV_A_RECORD, CONV_B_RECORD], nextCursor: null });+ api.getBeeperConversation.mockImplementation((id) => Promise.resolve(id === CONV_B ? CONV_B_RECORD : CONV_A_RECORD));+ api.getBeeperMessages.mockImplementation((id) => Promise.resolve({+ messages: [{+ id: id === CONV_B ? 'm-b' : 'm-a', conversationId: id, senderId: 'user-1', body: id === CONV_B ? 'Placeholder B body' : 'Placeholder A body', sentAt: '2026-09-01T10:00:00.000Z', attachments: [],+ }],+ nextCursor: null,+ }));+ renderTab(`/messages/beeper/${CONV_A}`);+ await screen.findByText('Placeholder A body');+ };+ const switchToB = async () => {+ fireEvent.click(screen.getByRole('button', { name: /Example B/ }));+ await screen.findByText('Placeholder B body');+ };+ const expectBStillOpen = () => {+ expect(screen.getByText('Placeholder B body')).toBeInTheDocument();+ expect(screen.queryByText('Placeholder A body')).toBeNull();+ expect(screen.getByPlaceholderText(/^Message Example B/)).toBeInTheDocument();+ };++ it('keeps an archive answer for the previous conversation off the one now open', async () => {+ await openA();+ const archive = deferred();+ api.setBeeperConversationArchived.mockReturnValue(archive.promise);+ act(() => { screen.getAllByRole('button', { name: 'Archive' }).at(-1).click(); });+ await waitFor(() => expect(api.setBeeperConversationArchived).toHaveBeenCalledWith(CONV_A, true, { silent: true }));++ await switchToB();+ // The other conversation's own controls are not held by A's pending write.+ expect(await findThreadAction('Archive')).toBeEnabled();+ const listReads = api.getBeeperConversations.mock.calls.length;+ await act(async () => { archive.resolve({ ...CONV_A_RECORD, isArchived: true }); });++ // The list still refetches, because the archived row changed scope.+ await waitFor(() => expect(api.getBeeperConversations.mock.calls.length).toBeGreaterThan(listReads));+ expect(screen.queryByRole('button', { name: 'Unarchive' })).toBeNull();+ expectBStillOpen();+ });++ it('does not reload the previous conversation into the open one when a participant link settles', async () => {+ api.getTribePeople.mockResolvedValue([{ id: '55555555-5555-4555-8555-555555555555', name: 'Alex Example' }]);+ await openA();+ const link = deferred();+ api.linkBeeperParticipant.mockReturnValue(link.promise);+ act(() => { screen.getByRole('button', { name: 'People' }).click(); });+ const picker = await screen.findByLabelText('Link Sam Example to a Tribe person');+ act(() => { picker.focus(); });+ act(() => { fireEvent.mouseDown(screen.getByRole('option', { name: 'Alex Example' })); });+ await waitFor(() => expect(api.linkBeeperParticipant).toHaveBeenCalled());++ await switchToB();+ const detailReads = api.getBeeperConversation.mock.calls.length;+ await act(async () => { link.resolve({ participant: {}, displacedPersonId: null }); });+ await act(async () => {});++ expect(api.getBeeperConversation.mock.calls.length).toBe(detailReads);+ expectBStillOpen();+ });++ it('stays on the open conversation when a purge of the previous one settles', async () => {+ await openA();+ const purge = deferred();+ api.purgeBeeperConversation.mockReturnValue(purge.promise);+ await act(async () => {});+ fireEvent.click(screen.getByRole('button', { name: /^Purge$/ }));+ fireEvent.change(await screen.findByLabelText(/Type purge to confirm/i), { target: { value: 'purge' } });+ fireEvent.click(screen.getByRole('button', { name: /Purge mirror/i }));+ await waitFor(() => expect(api.purgeBeeperConversation).toHaveBeenCalledWith(CONV_A, { silent: true }));++ await switchToB();+ await act(async () => {+ purge.resolve({ purged: true, conversationId: CONV_A, messagesRemoved: 1, filesRemoved: 0, bytesFreed: 0 });+ });++ // A's row is gone from the list, but B stays open.+ await waitFor(() => expect(screen.queryByRole('button', { name: /Example A/ })).toBeNull());+ expect(screen.queryByText('Pick a conversation')).toBeNull();+ expectBStillOpen();+ });++ it('shows the load error, not the previous conversation, when the newly opened one fails to load', async () => {+ await openA();+ api.getBeeperConversation.mockImplementation((id) => (id === CONV_B+ ? Promise.reject(Object.assign(new Error('Beeper mirror unavailable'), { status: 503 }))+ : Promise.resolve(CONV_A_RECORD)));+ fireEvent.click(screen.getByRole('button', { name: /Example B/ }));++ expect(await screen.findByText('Could not open this conversation')).toBeInTheDocument();+ expect(screen.queryByText('Placeholder A body')).toBeNull();+ expect(screen.queryByPlaceholderText(/^Message /)).toBeNull();+ });+});+// The LOCAL "seen in PortOS" watermark (#83) — the fix for opening an unread// thread leaving its badge untouched. This NEVER reaches Beeper: no PATCH,// no read receipt — see `markBeeperConversationSeen` (`apiBeeper.js`) and itsdiff --git a/client/src/components/messages/beeper/BeeperChatSurface.jsx b/client/src/components/messages/beeper/BeeperChatSurface.jsxindex 8e256404ab..3b9e8f278d 100644--- a/client/src/components/messages/beeper/BeeperChatSurface.jsx+++ b/client/src/components/messages/beeper/BeeperChatSurface.jsx@@ -400,8 +400,10 @@ export default function BeeperChatSurface({const [people, setPeople] = useState([]);const [linkingId, setLinkingId] = useState(null);- const [writePending, setWritePending] = useState(false);- const [purging, setPurging] = useState(false);+ // The conversation ids whose rail write / purge is in flight, so a pending+ // write on one conversation never disables or spins another one's controls.+ const [writePendingId, setWritePendingId] = useState(null);+ const [purgingId, setPurgingId] = useState(null);// A PortOS-side draft buffer, keyed by conversation, so a half-written// message survives switching threads AND leaving the page. It is deliberately@@ -416,6 +418,11 @@ export default function BeeperChatSurface({// burst can put several list fetches in flight at once.const listGenRef = useRef(0);const threadGenRef = useRef(0);+ // The conversation `conversation`/`messages` belong to. The composer sends to+ // the URL's conversation, so a write that settles for any other id must stay+ // off the thread, and a switch must not leave the previous conversation's+ // header, roster and messages on screen while the new one loads or fails.+ const threadIdRef = useRef(null);const scope = savedScope || LIVE_SYSTEM_SCOPES.has(scopeParam) || scopeParam.startsWith(NETWORK_SCOPE_PREFIX)? scopeParam@@ -504,6 +511,7 @@ export default function BeeperChatSurface({const loadThread = useCallback(async (id) => {if (!id) {+ threadIdRef.current = null;setConversation(null);setMessages([]);setMessageCursor(null);@@ -512,6 +520,12 @@ export default function BeeperChatSurface({return;}const generation = ++threadGenRef.current;+ if (threadIdRef.current !== id) {+ threadIdRef.current = id;+ setConversation(null);+ setMessages([]);+ setMessageCursor(null);+ }setThreadLoading(true);setThreadError(null);const [result, error] = await Promise.all([@@ -758,20 +772,21 @@ export default function BeeperChatSurface({// the response — not an optimistic guess — updates local state. A write never// retries, so a failure is reported once and left failed.const applyFlag = useCallback(async (writer, value, label) => {- if (!conversationId) return;- setWritePending(true);- const updated = await writer(conversationId, value, { silent: true }).catch((err) => {+ const id = conversationId;+ if (!id) return;+ setWritePendingId(id);+ const updated = await writer(id, value, { silent: true }).catch((err) => {toast.error(err?.message || `Could not ${label} this conversation`);return null;});if (!mountedRef.current) return;- setWritePending(false);+ setWritePendingId((pending) => (pending === id ? null : pending));if (!updated) return;// The open thread's own row is set from the server's answer; the LIST is// refetched rather than merged, because archiving changes which scope a// conversation belongs to — a local merge would leave it sitting in a// scope it no longer matches until the next load anyway.- setConversation(updated);+ if (threadIdRef.current === id) setConversation(updated);loadList();}, [conversationId, loadList, mountedRef]);@@ -779,23 +794,26 @@ export default function BeeperChatSurface({// rather than refetched: the row is gone, the thread has nothing left to// show, and the surface navigates back to the list it came from.const purgeMirror = useCallback(async () => {- if (!conversationId) return;- setPurging(true);- const result = await api.purgeBeeperConversation(conversationId, { silent: true }).catch((err) => {+ const id = conversationId;+ if (!id) return;+ setPurgingId(id);+ const result = await api.purgeBeeperConversation(id, { silent: true }).catch((err) => {toast.error(err?.message || 'Could not purge this conversation');return null;});if (!mountedRef.current) return;- setPurging(false);+ setPurgingId((pending) => (pending === id ? null : pending));if (!result) return;- setConversations((prev) => prev.filter((row) => row.id !== conversationId));+ setConversations((prev) => prev.filter((row) => row.id !== id));// The purge removes every message the mirror held for this conversation,// so a drafted-but-unsent reply left in `drafts` would otherwise survive// it forever in localStorage — nothing else ever clears an entry once its// conversation is gone from the list. Same shape `setDraft` uses.setDraft('');toast.success(`Mirror purged — ${result.messagesRemoved} message(s), ${result.filesRemoved} attachment file(s) removed`);- clearSelection();+ // Only leave the thread the purge emptied; a reader who has since opened+ // another conversation stays on it.+ if (threadIdRef.current === id) clearSelection();}, [clearSelection, conversationId, mountedRef, setDraft]);// One attachment changed under the thread (a "fetch anyway", a keep toggle).@@ -826,7 +844,7 @@ export default function BeeperChatSurface({setLinkingId(null);if (!result) return;if (result.displacedPersonId) toast.success('Handle moved from another Tribe person');- loadThread(conversationId);+ if (threadIdRef.current === conversationId) loadThread(conversationId);}, [conversationId, loadThread, mountedRef]);// The confirm-and-rename form (#97 part A) hands back the edited fields@@ -849,7 +867,7 @@ export default function BeeperChatSurface({setLinkingId(null);if (!result) return;toast.success('Linked to a new Tribe person');- loadThread(conversationId);+ if (threadIdRef.current === conversationId) loadThread(conversationId);api.getTribePeople({ silent: true }).then((data) => { if (mountedRef.current) setPeople(Array.isArray(data) ? data : (data?.people || [])); }).catch(() => {});@@ -878,7 +896,7 @@ export default function BeeperChatSurface({});if (!mountedRef.current) return;setLinkingId(null);- loadThread(conversationId);+ if (threadIdRef.current === conversationId) loadThread(conversationId);}, [conversationId, loadThread, mountedRef]);const pinned = useMemo(@@ -1204,11 +1222,11 @@ export default function BeeperChatSurface({onOpenTribePerson={openTribePerson}onBack={clearSelection}onRetry={conversationId ? () => loadThread(conversationId) : null}- writePending={writePending}+ writePending={Boolean(conversationId) && writePendingId === conversationId}onArchive={(value) => applyFlag(api.setBeeperConversationArchived, value, 'archive')}onLowPriority={(value) => applyFlag(api.setBeeperConversationLowPriority, value, 'update')}onPurge={purgeMirror}- purging={purging}+ purging={Boolean(conversationId) && purgingId === conversationId}onAttachmentUpdated={applyAttachmentUpdate}/>)}