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

address review (codex): keep every conversation's pending Beeper write tracked

Adam Eivyc54b0a09e8ab
diff --git a/client/src/components/messages/BeeperTab.test.jsx b/client/src/components/messages/BeeperTab.test.jsx
index 24c7180222..60ca8bb2cb 100644
--- a/client/src/components/messages/BeeperTab.test.jsx
+++ b/client/src/components/messages/BeeperTab.test.jsx
@@ -1226,6 +1226,24 @@ describe('a conversation write that settles after a switch', () => {
expectBStillOpen();
});
+ it('keeps an earlier conversation\'s write pending when a later conversation\'s write settles first', async () => {
+ await openA();
+ const writes = { [CONV_A]: deferred(), [CONV_B]: deferred() };
+ api.setBeeperConversationArchived.mockImplementation((id) => writes[id].promise);
+ act(() => { screen.getAllByRole('button', { name: 'Archive' }).at(-1).click(); });
+ await switchToB();
+ act(() => { screen.getAllByRole('button', { name: 'Archive' }).at(-1).click(); });
+ await waitFor(() => expect(api.setBeeperConversationArchived).toHaveBeenCalledWith(CONV_B, true, { silent: true }));
+ await act(async () => { writes[CONV_B].resolve({ ...CONV_B_RECORD, isArchived: true }); });
+
+ fireEvent.click(screen.getByRole('button', { name: /Example A/ }));
+ await screen.findByText('Placeholder A body');
+ expect(await findThreadAction('Archive')).toBeDisabled();
+ await act(async () => { writes[CONV_A].resolve({ ...CONV_A_RECORD, isArchived: true }); });
+ await waitFor(() => expect(screen.getAllByRole('button', { name: 'Unarchive' }).at(-1)).toBeEnabled());
+ expect(api.setBeeperConversationArchived).toHaveBeenCalledTimes(2);
+ });
+
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();
diff --git a/client/src/components/messages/beeper/BeeperChatSurface.jsx b/client/src/components/messages/beeper/BeeperChatSurface.jsx
index 3ef2113b60..375e5a2985 100644
--- a/client/src/components/messages/beeper/BeeperChatSurface.jsx
+++ b/client/src/components/messages/beeper/BeeperChatSurface.jsx
@@ -353,6 +353,13 @@ function ConversationRow({ conversation, unified, selected, onSelect }) {
/* ---------------------------------------------------------------- surface -- */
+const withId = (ids, id) => new Set(ids).add(id);
+const withoutId = (ids, id) => {
+ const next = new Set(ids);
+ next.delete(id);
+ return next;
+};
+
export default function BeeperChatSurface({
conversationId = null, realtime = null, invalidationSeq = 0, invalidationFrames = null, breaker = null,
sweep = null, tokenConfigured = false, accounts = [], onOpenSettings,
@@ -401,9 +408,10 @@ export default function BeeperChatSurface({
const [people, setPeople] = useState([]);
const [linkingId, setLinkingId] = useState(null);
// 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);
+ // write on one conversation never disables or spins another one's controls,
+ // and one settling never re-enables another that is still in flight.
+ const [writePendingIds, setWritePendingIds] = useState(() => new Set());
+ const [purgingIds, setPurgingIds] = useState(() => new Set());
// A PortOS-side draft buffer, keyed by conversation, so a half-written
// message survives switching threads AND leaving the page. It is deliberately
@@ -775,13 +783,13 @@ export default function BeeperChatSurface({
const applyFlag = useCallback(async (writer, value, label) => {
const id = conversationId;
if (!id) return;
- setWritePendingId(id);
+ setWritePendingIds((pending) => withId(pending, 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;
- setWritePendingId((pending) => (pending === id ? null : pending));
+ setWritePendingIds((pending) => withoutId(pending, id));
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
@@ -797,13 +805,13 @@ export default function BeeperChatSurface({
const purgeMirror = useCallback(async () => {
const id = conversationId;
if (!id) return;
- setPurgingId(id);
+ setPurgingIds((pending) => withId(pending, 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;
- setPurgingId((pending) => (pending === id ? null : pending));
+ setPurgingIds((pending) => withoutId(pending, id));
if (!result) return;
setConversations((prev) => prev.filter((row) => row.id !== id));
// The purge removes every message the mirror held for this conversation,
@@ -1223,11 +1231,11 @@ export default function BeeperChatSurface({
onOpenTribePerson={openTribePerson}
onBack={clearSelection}
onRetry={conversationId ? () => loadThread(conversationId) : null}
- writePending={Boolean(conversationId) && writePendingId === conversationId}
+ writePending={writePendingIds.has(conversationId)}
onArchive={(value) => applyFlag(api.setBeeperConversationArchived, value, 'archive')}
onLowPriority={(value) => applyFlag(api.setBeeperConversationLowPriority, value, 'update')}
onPurge={purgeMirror}
- purging={Boolean(conversationId) && purgingId === conversationId}
+ purging={purgingIds.has(conversationId)}
onAttachmentUpdated={applyAttachmentUpdate}
/>
)}