fix(dashboard): don't mark agent inbox messages read when user views them

When the dashboard user browses another agent's mailbox (e.g. the CEO's
inbox), opening a message no longer triggers POST /messages/:id/read.
The previous behavior silently consumed the agent's unread state, so the
agent's heartbeat never surfaced the message and fn_read_messages (which
defaults to unread_only=true) returned nothing. Auto-mark-read now only
fires on the dashboard user's own inbox tab. Adds regression tests in
MailboxView.test.tsx and MailboxModal.test.tsx.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-05-06 08:01:30 -07:00
parent 4dc91edfb2
commit 6f46ab017f
5 changed files with 121 additions and 6 deletions

View File

@@ -207,8 +207,10 @@ export function MailboxModal({
const handleOpenMessage = useCallback(async (message: Message) => {
setSelectedMessage(message);
// Mark as read if unread
if (!message.read) {
// Only auto-mark as read when viewing the dashboard user's own inbox.
// Browsing another agent's mailbox must not consume their unread messages
// out from under them — the agent's heartbeat is the one that reads + acks.
if (!message.read && activeTab === "inbox") {
try {
const updated = await markMessageRead(message.id, projectId);
// Update inbox state
@@ -233,7 +235,7 @@ export function MailboxModal({
} catch {
setConversationMessages([message]);
}
}, [projectId]);
}, [projectId, activeTab]);
const handleCloseMessage = useCallback(() => {
setSelectedMessage(null);