fix(mission): thread messages, accurate unreads, state_change detail (by Wren) - #217
Merged
Merged
Conversation
Thread-backed messages (sent via send_to_inbox with threadKey) now live in inbox_thread_messages, not agent_inbox. The mission feed was only reading from the legacy messages array, so cross-agent thread messages were invisible. Changes: - extractInboxMessages: also extract preview messages from threadsWithUnread - extractUnreadCount: prefer totalUnreadCount (includes thread unreads) - All-agents path: count thread unreads per participant from threadsWithUnread Co-Authored-By: Wren <noreply@anthropic.com>
…ion feed Tests cover: - Thread preview messages extracted from threadsWithUnread - Merged legacy + thread messages - Missing threadsWithUnread handled gracefully - Preview messages without createdAt skipped - Recipient derived from thread participants (excludes sender) - totalUnreadCount preferred over legacy unreadCount - Non-finite totalUnreadCount falls back correctly Co-Authored-By: Wren <noreply@anthropic.com>
The all-agents get_inbox query lacks agent-specific thread read status, so thread unreadCount was inflated (counted total messages, not per-agent unreads). This caused wildly inflated numbers like 246 unread across 5 SBs. Removed the all-agents optimization entirely — per-agent queries give accurate totalUnreadCount (legacy + thread unreads) per agent. The extra API calls are worth correct counts. Co-Authored-By: Wren <noreply@anthropic.com>
…ead counts" This reverts commit d92186a.
New MCP tool that returns per-agent summaries in one call: - Accurate unread counts (legacy inbox + thread-aware with per-agent last_read_at) - Active session count and latest session lifecycle/phase - Auto-discovers agents from agent_identities when agentIds omitted - Replaces broken all-agents thread counting that inflated unread counts Co-Authored-By: Wren <noreply@anthropic.com>
Replace broken all-agents inbox counting with dedicated backend tool. Feed messages still fetched from get_inbox (all agents, all statuses). Falls back to per-agent get_inbox if server doesn't support new tool yet. Co-Authored-By: Wren <noreply@anthropic.com>
Instead of 'Session b73acc8f updated (currentPhase, lifecycle)', now shows 'Session b73acc8f → currentPhase: implementing, lifecycle: running'. Parses payload.after for the actual values. Skips long fields (>80 chars) like context blobs. Falls back to field names if payload is missing. Co-Authored-By: Wren <noreply@anthropic.com>
get_agent_summaries now queries all non-ended sessions (no limit) and
returns sessionsByLifecycle counts per agent (e.g. { running: 2, idle: 1 }).
SB summary bar now shows '2 running, 1 idle' instead of '3 sessions'
with a single misleading lifecycle status. Running sessions shown first.
Co-Authored-By: Wren <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extractInboxMessagesnow parsesthreadsWithUnread[*].previewMessagesso thread-based messages appear in the mission control feed alongside legacy inbox messagesget_agent_summariesMCP tool computes thread unreads with proper per-agentlast_read_at— fixes the inflated 246-unread bug where all-agents mode counted ALL thread messages as unread for every participantSession b73acc8f → currentPhase: implementing, lifecycle: running) instead of just field names (Session b73acc8f updated (currentPhase, lifecycle))Changes
Backend (
packages/api/src/mcp/tools/inbox-handlers.ts)get_agent_summariestool: returns per-agent summaries in one callagent_identitiestableagent_inbox+ thread-aware with per-agentlast_read_atCLI (
packages/cli/src/commands/mission.ts)extractInboxMessages: extracts from bothmessagesandthreadsWithUnread[*].previewMessagesextractUnreadCount: preferstotalUnreadCountoverunreadCountfetchMissionSnapshot: usesget_agent_summariesfor the SB summary bar (falls back to per-agentget_inboxif server doesn't support it yet)formatStateChange: parsespayload.afterto show actual changed values, skips long fields (>80 chars)Tests (
packages/cli/src/commands/mission.test.ts)Test plan
npx vitest run packages/cli/src/commands/mission.test.ts— 66 tests passingsb mission --watchconfirms thread messages appear and unread counts are accurateget_agent_summariestool, verify SB summary bar shows correct counts— Wren