Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop-app): resend review fixes — dirty-composer guard, unrestorable toast, focus nudge, preview size estimate

Mc9eb1d3c2aea
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsx
index 14be2aca8..b91ede933 100644
--- a/desktop-app/ui/src/App.tsx
+++ b/desktop-app/ui/src/App.tsx
@@ -131,9 +131,7 @@ const SANDBOX_UI_DEEP_LINK_MANUAL_TEAM_CHANGE_MESSAGE =
// stored route untouched — the caller must NOT invoke the setter, because
// passing `undefined` to it would erase A's previously-saved route.
type OutgoingRouteDecision =
- | { action: 'set'; routePath: string }
- | { action: 'clear' }
- | { action: 'preserve' }
+ { action: 'set'; routePath: string } | { action: 'clear' } | { action: 'preserve' }
async function readOutgoingRouteDecision(
outgoingAppRef: string | undefined
@@ -2221,6 +2219,7 @@ export function App() {
handleDenyNotification: vm.handleDenyNotification,
handleRefreshPendingApprovals: vm.handleRefreshPendingApprovals,
handleDecidePendingApproval: vm.handleDecidePendingApproval,
+ pushToast: vm.pushToast,
}),
[
vm.clearNotifications,
@@ -2236,6 +2235,7 @@ export function App() {
vm.pendingApprovalActionId,
vm.pendingApprovals,
vm.pendingApprovalsLoading,
+ vm.pushToast,
vm.removeNotification,
vm.resolveApprovalNotification,
vm.toasts,
@@ -2286,6 +2286,12 @@ export function App() {
]
)
+ // Stable focus-request bumper shared through ChatComposerStateContext: the
+ // composer focuses (and scrolls) itself when the id increments (TASK-42).
+ const requestComposerFocus = React.useCallback(() => {
+ setComposerFocusRequestId(value => value + 1)
+ }, [])
+
const chatComposerStateValue = React.useMemo(
() => ({
activeChatId: vm.activeChatId,
@@ -2296,6 +2302,7 @@ export function App() {
failedAgentSend: vm.failedAgentSend,
activeMessageCount: vm.activeMessages.length,
composerFocusRequestId,
+ requestComposerFocus,
}),
[
vm.activeChatId,
@@ -2306,6 +2313,7 @@ export function App() {
vm.failedAgentSend,
vm.activeMessages.length,
composerFocusRequestId,
+ requestComposerFocus,
]
)
diff --git a/desktop-app/ui/src/components/agents/ChatThread.tsx b/desktop-app/ui/src/components/agents/ChatThread.tsx
index 87a796abc..292de723c 100644
--- a/desktop-app/ui/src/components/agents/ChatThread.tsx
+++ b/desktop-app/ui/src/components/agents/ChatThread.tsx
@@ -8,6 +8,7 @@ import {
useState,
} from 'react'
import { useAgentChatActionsContext } from '@contexts/AgentChatActionsContext'
+import { useChatComposerStateContext } from '@contexts/ChatComposerStateContext'
import { useChatListContext } from '@contexts/ChatListContext'
import { useChatThreadStateContext } from '@contexts/ChatThreadStateContext'
import { useMcpRuntimeContext } from '@contexts/McpRuntimeContext'
@@ -33,7 +34,7 @@ import {
getChatMessageAttachmentTypeLabel,
parseChatMessageDisplay,
} from '../../lib/chatMessageAttachments'
-import { setComposerDraft } from '../../lib/composerDraftStore'
+import { getComposerDraft, setComposerDraft } from '../../lib/composerDraftStore'
import { buildComposerResendDraft, findNearestPrecedingUserMessage } from '../../lib/composerResend'
import {
extractHtmlVisualization,
@@ -250,7 +251,13 @@ function MessageAttachmentList({ attachments }: { attachments: ChatMessageAttach
})}
{previewAttachment ? (
<GfsImagePreview
- byteLength={previewAttachment.sizeBytes ?? previewAttachment.dataBase64!.length}
+ byteLength={
+ previewAttachment.sizeBytes ??
+ // Base64 length overstates the decoded size by ~33%; the accurate
+ // 3/4 estimate keeps the 10 MB early-skip from refusing previews
+ // that are actually under the limit (PR #859 review).
+ Math.floor(((previewAttachment.dataBase64 ?? '').length * 3) / 4)
+ }
fileName={previewAttachment.filename || previewAttachment.label}
dataBase64={previewAttachment.dataBase64}
mimeType={previewAttachment.mimeType || 'image/png'}
@@ -263,7 +270,9 @@ function MessageAttachmentList({ attachments }: { attachments: ChatMessageAttach
export function ChatThread({ showAgentLabel = false, onScrollPositionChange }: ChatThreadProps) {
const { selectedAgent, handleSelectChatAgent: onStartNewChat } = useNavigationContext()
- const { decideApproval } = useNotificationsContext()
+ const { decideApproval, pushToast } = useNotificationsContext()
+ const { composerImageAttachments, composerReferenceAttachments, requestComposerFocus } =
+ useChatComposerStateContext()
const {
activeMessages,
groupedMessages,
@@ -491,9 +500,24 @@ export function ChatThread({ showAgentLabel = false, onScrollPositionChange }: C
// plugin/connector/file indicators re-applied as composer references. The
// source is always a user message: resending a reply re-issues the prompt that
// produced it (see `findNearestPrecedingUserMessage`).
+ //
+ // Replace-vs-append contract (PR #859 review): like the failed-send recovery
+ // path (`handleRecoverFailedAgentSend`), resend REFUSES to touch a dirty
+ // composer instead of silently merging into a half-written draft — text is
+ // replaced and attachments are appended by the store handlers, so merging
+ // would strand the user's earlier chips under the resent ones. Once the
+ // composer is clean, the resend is a full repopulate.
const handleResendMessage = useCallback(
(source: Pick<RenderableChatMessage, 'content' | 'attachments'>) => {
if (!activeChatId) return
+ if (
+ getComposerDraft(activeChatId) ||
+ composerImageAttachments.length ||
+ composerReferenceAttachments.length
+ ) {
+ pushToast('Keep or clear the current draft before resending this message.', 'error')
+ return
+ }
const draft = buildComposerResendDraft(source)
setComposerDraft(activeChatId, draft.content)
if (draft.imageAttachments.length) {
@@ -502,8 +526,24 @@ export function ChatThread({ showAgentLabel = false, onScrollPositionChange }: C
if (draft.referenceAttachments.length) {
onAddComposerReferenceAttachments(draft.referenceAttachments)
}
+ if (draft.unrestorable.length) {
+ const count = draft.unrestorable.length
+ pushToast(
+ `${count} ${count === 1 ? 'attachment' : 'attachments'} from the original message couldn't be restored.`,
+ 'warn'
+ )
+ }
+ requestComposerFocus()
},
- [activeChatId, onAddComposerImageAttachments, onAddComposerReferenceAttachments]
+ [
+ activeChatId,
+ composerImageAttachments,
+ composerReferenceAttachments,
+ onAddComposerImageAttachments,
+ onAddComposerReferenceAttachments,
+ pushToast,
+ requestComposerFocus,
+ ]
)
const renderProgressStepper = useCallback(
diff --git a/desktop-app/ui/src/components/agents/NudgeArea.tsx b/desktop-app/ui/src/components/agents/NudgeArea.tsx
index e3725d6fb..5b09a4cd4 100644
--- a/desktop-app/ui/src/components/agents/NudgeArea.tsx
+++ b/desktop-app/ui/src/components/agents/NudgeArea.tsx
@@ -85,7 +85,10 @@ export function NudgeArea({ agentRef, chatId, onStartNewChat, onRefreshState }:
// window too.
if (state.status === 'suspended' || state.pendingApproval) return null
if (tier === 'T1' || tier === 'T2') return null
- const taskIdentity = state.taskId || key
+ // Degenerate-taskId fallback (PR #859 review): keying an id-less task's
+ // dismissal to the CHAT key would suppress every future task in the chat,
+ // contradicting "a new task starts fresh". `startedAt` stays per-task.
+ const taskIdentity = state.taskId || `${key}@${state.startedAt}`
if (dismissedTaskIds.has(taskIdentity)) return null
const dismissButton = (
diff --git a/desktop-app/ui/src/components/agents/__tests__/AgentWorkspace.chatScroll.test.tsx b/desktop-app/ui/src/components/agents/__tests__/AgentWorkspace.chatScroll.test.tsx
index 1413e92d2..f79d33a9d 100644
--- a/desktop-app/ui/src/components/agents/__tests__/AgentWorkspace.chatScroll.test.tsx
+++ b/desktop-app/ui/src/components/agents/__tests__/AgentWorkspace.chatScroll.test.tsx
@@ -60,6 +60,13 @@ vi.mock('@hooks/domain/useConnectorsController', async importActual => ({
}),
}))
vi.mock('../ComposerPanel', () => ({ ComposerPanel: () => null }))
+vi.mock('@contexts/ChatComposerStateContext', () => ({
+ useChatComposerStateContext: () => ({
+ composerImageAttachments: [],
+ composerReferenceAttachments: [],
+ requestComposerFocus: vi.fn(),
+ }),
+}))
vi.mock('../ContextWindowIndicator', () => ({ ContextWindowIndicator: () => null }))
vi.mock('../InFlightAssistantPlaceholder', () => ({ InFlightAssistantPlaceholder: () => null }))
vi.mock('../NudgeArea', () => ({ NudgeArea: () => null }))
@@ -178,6 +185,7 @@ function WorkspaceHarness({
pendingApprovalsLoading: false,
pendingApprovalActionId: null,
toasts: [],
+ pushToast: vi.fn(),
markNotificationsRead: vi.fn(),
clearNotifications: vi.fn(),
removeNotification: vi.fn(),
diff --git a/desktop-app/ui/src/components/agents/__tests__/ChatThread.renderSemantics.test.tsx b/desktop-app/ui/src/components/agents/__tests__/ChatThread.renderSemantics.test.tsx
index 838dd7971..1452578f4 100644
--- a/desktop-app/ui/src/components/agents/__tests__/ChatThread.renderSemantics.test.tsx
+++ b/desktop-app/ui/src/components/agents/__tests__/ChatThread.renderSemantics.test.tsx
@@ -6,7 +6,12 @@ import type { AgentChatMessage } from '../../../uiTypes'
import { ChatThread } from '../ChatThread'
const navigationValue = { selectedAgent: 'agent-x', handleSelectChatAgent: vi.fn() }
-const notificationsValue = { decideApproval: vi.fn() }
+const notificationsValue = { decideApproval: vi.fn(), pushToast: vi.fn() }
+const composerStateValue = {
+ composerImageAttachments: [] as never[],
+ composerReferenceAttachments: [] as never[],
+ requestComposerFocus: vi.fn(),
+}
const chatListValue = {
chatList: [],
chatListLoading: false,
@@ -27,6 +32,9 @@ vi.mock('@contexts/NavigationContext', () => ({
vi.mock('@contexts/NotificationsContext', () => ({
useNotificationsContext: () => notificationsValue,
}))
+vi.mock('@contexts/ChatComposerStateContext', () => ({
+ useChatComposerStateContext: () => composerStateValue,
+}))
vi.mock('@contexts/ChatListContext', () => ({
useChatListContext: () => chatListValue,
}))
diff --git a/desktop-app/ui/src/components/agents/__tests__/ChatThread.resend.test.tsx b/desktop-app/ui/src/components/agents/__tests__/ChatThread.resend.test.tsx
index 3ad2df7e3..b603ad5a8 100644
--- a/desktop-app/ui/src/components/agents/__tests__/ChatThread.resend.test.tsx
+++ b/desktop-app/ui/src/components/agents/__tests__/ChatThread.resend.test.tsx
@@ -1,13 +1,18 @@
// @vitest-environment jsdom
import { afterEach, describe, expect, it, vi } from 'vitest'
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
-import { getComposerDraft, resetComposerDraftStore } from '@lib/composerDraftStore'
+import {
+ getComposerDraft,
+ resetComposerDraftStore,
+ setComposerDraft,
+} from '@lib/composerDraftStore'
import { buildLoadedChatSemanticModels } from '../../../lib/chatMessageSemantics'
-import type { AgentChatMessage } from '../../../uiTypes'
+import type { AgentChatMessage, ComposerImageAttachment } from '../../../uiTypes'
import { ChatThread } from '../ChatThread'
const navigationValue = { selectedAgent: 'agent-x', handleSelectChatAgent: vi.fn() }
-const notificationsValue = { decideApproval: vi.fn() }
+const pushToast = vi.fn()
+const notificationsValue = { decideApproval: vi.fn(), pushToast }
const chatListValue = {
chatList: [],
chatListLoading: false,
@@ -24,6 +29,11 @@ const actionsValue = {
handleAddComposerReferenceAttachments: addComposerReferenceAttachments,
}
const runtimeValue = { cancelTask: vi.fn() }
+const requestComposerFocus = vi.fn()
+const composerStateValue = {
+ composerImageAttachments: [] as ComposerImageAttachment[],
+ composerReferenceAttachments: [] as never[],
+}
let messages: AgentChatMessage[] = []
let groupedMessages: Array<{ role: 'user' | 'assistant' | 'system'; items: AgentChatMessage[] }> =
[]
@@ -34,6 +44,13 @@ vi.mock('@contexts/NavigationContext', () => ({
vi.mock('@contexts/NotificationsContext', () => ({
useNotificationsContext: () => notificationsValue,
}))
+vi.mock('@contexts/ChatComposerStateContext', () => ({
+ useChatComposerStateContext: () => ({
+ composerImageAttachments: composerStateValue.composerImageAttachments,
+ composerReferenceAttachments: composerStateValue.composerReferenceAttachments,
+ requestComposerFocus,
+ }),
+}))
vi.mock('@contexts/ChatListContext', () => ({
useChatListContext: () => chatListValue,
}))
@@ -96,10 +113,18 @@ function userMessageWithAttachments(): AgentChatMessage {
}
}
+function renderWithUserMessage(user: AgentChatMessage) {
+ messages = [user]
+ groupedMessages = [{ role: 'user', items: [user] }]
+ render(<ChatThread />)
+}
+
afterEach(() => {
cleanup()
messages = []
groupedMessages = []
+ composerStateValue.composerImageAttachments = []
+ composerStateValue.composerReferenceAttachments = []
resetComposerDraftStore()
vi.clearAllMocks()
vi.restoreAllMocks()
@@ -108,11 +133,7 @@ afterEach(() => {
describe('ChatThread resend action (TASK-42)', () => {
it('re-populates the composer draft and re-attaches files + plugin indicators from a user message', () => {
- const user = userMessageWithAttachments()
- messages = [user]
- groupedMessages = [{ role: 'user', items: [user] }]
-
- render(<ChatThread />)
+ renderWithUserMessage(userMessageWithAttachments())
fireEvent.click(screen.getByRole('button', { name: 'Resend message' }))
@@ -137,6 +158,8 @@ describe('ChatThread resend action (TASK-42)', () => {
label: 'revenue',
},
])
+ // A long-thread user must notice the repopulated composer.
+ expect(requestComposerFocus).toHaveBeenCalledTimes(1)
})
it('resending from an assistant message re-issues the originating user prompt (text + attachments + indicators)', () => {
@@ -178,6 +201,7 @@ describe('ChatThread resend action (TASK-42)', () => {
expect(addComposerReferenceAttachments.mock.calls[0]![0]).toEqual([
expect.objectContaining({ type: 'plugin', namespace: 'profits', name: 'revenue' }),
])
+ expect(requestComposerFocus).toHaveBeenCalledTimes(1)
})
it('hides the resend action on an assistant message with no preceding user prompt', () => {
@@ -218,4 +242,73 @@ describe('ChatThread resend action (TASK-42)', () => {
expect(getComposerDraft('chat-1')).toBe('Summarize the chart with the plugin')
expect(addComposerImageAttachments).toHaveBeenCalledTimes(1)
})
+
+ describe('dirty-composer contract (PR #859 review: refuse like handleRecoverFailedAgentSend)', () => {
+ it('refuses with an error toast when the composer holds draft text', () => {
+ setComposerDraft('chat-1', 'a half-written draft')
+ renderWithUserMessage(userMessageWithAttachments())
+
+ fireEvent.click(screen.getByRole('button', { name: 'Resend message' }))
+
+ expect(pushToast).toHaveBeenCalledTimes(1)
+ expect(pushToast.mock.calls[0]![0]).toBe(
+ 'Keep or clear the current draft before resending this message.'
+ )
+ expect(pushToast.mock.calls[0]![1]).toBe('error')
+ // The dirty draft is untouched and nothing was populated.
+ expect(getComposerDraft('chat-1')).toBe('a half-written draft')
+ expect(addComposerImageAttachments).not.toHaveBeenCalled()
+ expect(addComposerReferenceAttachments).not.toHaveBeenCalled()
+ expect(requestComposerFocus).not.toHaveBeenCalled()
+ })
+
+ it('refuses with an error toast when the composer holds pending attachments', () => {
+ composerStateValue.composerImageAttachments = [
+ {
+ id: 'pending-1',
+ name: 'already-there.png',
+ mimeType: 'image/png',
+ dataBase64: 'cGVuZGluZw==',
+ sizeBytes: 7,
+ previewDataUrl: 'data:image/png;base64,cGVuZGluZw==',
+ },
+ ]
+ renderWithUserMessage(userMessageWithAttachments())
+
+ fireEvent.click(screen.getByRole('button', { name: 'Resend message' }))
+
+ expect(pushToast).toHaveBeenCalledTimes(1)
+ expect(pushToast.mock.calls[0]![1]).toBe('error')
+ expect(addComposerImageAttachments).not.toHaveBeenCalled()
+ expect(addComposerReferenceAttachments).not.toHaveBeenCalled()
+ expect(requestComposerFocus).not.toHaveBeenCalled()
+ })
+ })
+
+ it("surfaces a warn toast when original attachments can't be restored (PR #859 review)", () => {
+ const user: AgentChatMessage = {
+ id: 'user-legacy',
+ role: 'user',
+ content: 'Analyze these',
+ timestamp: 1,
+ attachments: [
+ { id: 'legacy-1', type: 'uploaded_file', label: 'old-shot.png', addedOrder: 0 },
+ { id: 'legacy-2', type: 'uploaded_file', label: 'older-shot.png', addedOrder: 1 },
+ ],
+ }
+ renderWithUserMessage(user)
+
+ fireEvent.click(screen.getByRole('button', { name: 'Resend message' }))
+
+ // The resend itself still happens (text restored, focus nudged)…
+ expect(getComposerDraft('chat-1')).toBe('Analyze these')
+ expect(requestComposerFocus).toHaveBeenCalledTimes(1)
+ expect(addComposerImageAttachments).not.toHaveBeenCalled()
+ // …but the loss is reported, not silent.
+ expect(pushToast).toHaveBeenCalledTimes(1)
+ expect(pushToast.mock.calls[0]![0]).toBe(
+ "2 attachments from the original message couldn't be restored."
+ )
+ expect(pushToast.mock.calls[0]![1]).toBe('warn')
+ })
})
diff --git a/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx b/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx
index ab454c74e..bdf8816e1 100644
--- a/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx
+++ b/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx
@@ -35,6 +35,7 @@ const composerState: ChatComposerStateContextValue = {
activeChatId: null,
activeMessageCount: 0,
composerFocusRequestId: 0,
+ requestComposerFocus: vi.fn(),
}
const draftState = { value: '', set: vi.fn() }
@@ -305,12 +306,10 @@ describe('ComposerPanel reference submenu portaling', () => {
it('keeps the menu mounted through a mousedown on a portaled submenu item so its click fires', async () => {
// A clickable plugin so the submenu holds a real menuitem, not an empty state.
- window.clerum.workflows.list = vi.fn(
- async (): Promise<WorkflowRecipeListResult> => ({
- items: [{ metadata: { namespace: 'ns', name: 'plug-a' } }],
- count: 1,
- })
- )
+ window.clerum.workflows.list = vi.fn(async (): Promise<WorkflowRecipeListResult> => ({
+ items: [{ metadata: { namespace: 'ns', name: 'plug-a' } }],
+ count: 1,
+ }))
render(<ComposerPanel inline={false} />)
fireEvent.click(screen.getByRole('button', { name: 'Add context' }))
diff --git a/desktop-app/ui/src/components/agents/__tests__/chatThread.attachmentPreview.test.tsx b/desktop-app/ui/src/components/agents/__tests__/chatThread.attachmentPreview.test.tsx
index ded558c90..92164adc4 100644
--- a/desktop-app/ui/src/components/agents/__tests__/chatThread.attachmentPreview.test.tsx
+++ b/desktop-app/ui/src/components/agents/__tests__/chatThread.attachmentPreview.test.tsx
@@ -14,7 +14,12 @@ import type { AgentChatMessage, TaskProgress } from '../../../uiTypes'
import { ChatThread } from '../ChatThread'
const navValue = { selectedAgent: 'agent-x', handleSelectChatAgent: vi.fn() }
-const notificationsValue = { decideApproval: vi.fn() }
+const notificationsValue = { decideApproval: vi.fn(), pushToast: vi.fn() }
+const composerStateValue = {
+ composerImageAttachments: [] as never[],
+ composerReferenceAttachments: [] as never[],
+ requestComposerFocus: vi.fn(),
+}
const chatListValue = { chatList: [], chatListLoading: false, sessionStateByChatId: {} }
const actionsValue = {
chatEndRef: { current: null },
@@ -29,6 +34,9 @@ vi.mock('@contexts/NavigationContext', () => ({ useNavigationContext: () => navV
vi.mock('@contexts/NotificationsContext', () => ({
useNotificationsContext: () => notificationsValue,
}))
+vi.mock('@contexts/ChatComposerStateContext', () => ({
+ useChatComposerStateContext: () => composerStateValue,
+}))
vi.mock('@contexts/ChatListContext', () => ({ useChatListContext: () => chatListValue }))
vi.mock('@contexts/AgentChatActionsContext', () => ({
useAgentChatActionsContext: () => actionsValue,
@@ -178,4 +186,39 @@ describe('ChatThread uploaded-image attachment preview (BUG-176)', () => {
expect(container.querySelector('.message-attachment-preview-trigger')).toBeNull()
expect(screen.queryByRole('dialog')).toBeNull()
})
+
+ it('estimates byteLength from base64 at 3/4, not raw length, when sizeBytes is absent (PR #859 review)', async () => {
+ // base64 length 10,519,760 exceeds the 10,485,760-byte preview limit, so
+ // the old raw-length fallback would early-skip the preview; the accurate
+ // 3/4 estimate (7,889,820 bytes) is under the limit and must render.
+ // Multiple of 4 so atob accepts it; decodes to 7,889,820 null bytes.
+ const base64Length = 10 * 1024 * 1024 + 34_000
+ messages = [
+ {
+ id: 'msg-4',
+ role: 'user',
+ content: 'big one',
+ timestamp: 1,
+ attachments: [
+ {
+ id: 'image-4',
+ type: 'uploaded_file',
+ label: 'big.png',
+ filename: 'big.png',
+ mimeType: 'image/png',
+ encoding: 'base64',
+ dataBase64: 'A'.repeat(base64Length),
+ },
+ ],
+ },
+ ]
+ render(<ChatThread />)
+
+ fireEvent.click(screen.getByRole('button', { name: /big\.png/i }))
+
+ // Under the accurate estimate the preview opens instead of the size error.
+ const dialog = await screen.findByRole('dialog')
+ expect(dialog).toBeTruthy()
+ expect(await screen.findByAltText(/Preview of big\.png/i)).toBeTruthy()
+ })
})
diff --git a/desktop-app/ui/src/components/agents/__tests__/chatThread.connectFailure.test.tsx b/desktop-app/ui/src/components/agents/__tests__/chatThread.connectFailure.test.tsx
index c86386072..b3b1d6a29 100644
--- a/desktop-app/ui/src/components/agents/__tests__/chatThread.connectFailure.test.tsx
+++ b/desktop-app/ui/src/components/agents/__tests__/chatThread.connectFailure.test.tsx
@@ -13,7 +13,12 @@ import { ChatThread } from '../ChatThread'
// for a `role: 'user'` group whose message id has an entry in `progressByMessageId`.
// The context values are mutated per-test; the mock factories read them lazily.
const navigationValue = { selectedAgent: 'agent-x', handleSelectChatAgent: vi.fn() }
-const notificationsValue = { decideApproval: vi.fn() }
+const notificationsValue = { decideApproval: vi.fn(), pushToast: vi.fn() }
+const composerStateValue = {
+ composerImageAttachments: [] as never[],
+ composerReferenceAttachments: [] as never[],
+ requestComposerFocus: vi.fn(),
+}
const chatListValue = { chatList: [], chatListLoading: false, sessionStateByChatId: {} }
const actionsValue = {
chatEndRef: { current: null },
@@ -30,6 +35,9 @@ vi.mock('@contexts/NavigationContext', () => ({ useNavigationContext: () => navi
vi.mock('@contexts/NotificationsContext', () => ({
useNotificationsContext: () => notificationsValue,
}))
+vi.mock('@contexts/ChatComposerStateContext', () => ({
+ useChatComposerStateContext: () => composerStateValue,
+}))
vi.mock('@contexts/ChatListContext', () => ({ useChatListContext: () => chatListValue }))
vi.mock('@contexts/AgentChatActionsContext', () => ({
useAgentChatActionsContext: () => actionsValue,
diff --git a/desktop-app/ui/src/components/agents/__tests__/chatThread.toolSteps.test.tsx b/desktop-app/ui/src/components/agents/__tests__/chatThread.toolSteps.test.tsx
index 569adc9b3..eda89e527 100644
--- a/desktop-app/ui/src/components/agents/__tests__/chatThread.toolSteps.test.tsx
+++ b/desktop-app/ui/src/components/agents/__tests__/chatThread.toolSteps.test.tsx
@@ -20,7 +20,12 @@ import { ChatThread } from '../ChatThread'
// ── context stubs (ChatThread reads everything from 6 contexts) ──
const navValue = { selectedAgent: 'agent-x', handleSelectChatAgent: vi.fn() }
-const notificationsValue = { resolveApprovalNotification: vi.fn() }
+const notificationsValue = { resolveApprovalNotification: vi.fn(), pushToast: vi.fn() }
+const composerStateValue = {
+ composerImageAttachments: [] as never[],
+ composerReferenceAttachments: [] as never[],
+ requestComposerFocus: vi.fn(),
+}
const chatListValue = { chatList: [], chatListLoading: false, sessionStateByChatId: {} }
const actionsValue = {
chatEndRef: { current: null },
@@ -51,6 +56,9 @@ vi.mock('@contexts/NavigationContext', () => ({ useNavigationContext: () => navV
vi.mock('@contexts/NotificationsContext', () => ({
useNotificationsContext: () => notificationsValue,
}))
+vi.mock('@contexts/ChatComposerStateContext', () => ({
+ useChatComposerStateContext: () => composerStateValue,
+}))
vi.mock('@contexts/ChatListContext', () => ({ useChatListContext: () => chatListValue }))
vi.mock('@contexts/AgentChatActionsContext', () => ({
useAgentChatActionsContext: () => actionsValue,
diff --git a/desktop-app/ui/src/components/agents/__tests__/nudgeArea.test.tsx b/desktop-app/ui/src/components/agents/__tests__/nudgeArea.test.tsx
index d15f7eef2..5c8c4ad5c 100644
--- a/desktop-app/ui/src/components/agents/__tests__/nudgeArea.test.tsx
+++ b/desktop-app/ui/src/components/agents/__tests__/nudgeArea.test.tsx
@@ -298,4 +298,27 @@ describe('NudgeArea dismissal (TASK-228)', () => {
})
expect(container.firstChild).toBeNull()
})
+
+ it('does not let a dismissal of a degenerate (empty) task id leak onto the next task in the chat (PR #859 review)', () => {
+ // `taskId` is typed non-optional, but a degenerate '' must not key the
+ // dismissal to the CHAT: the next task (also id-less, later `startedAt`)
+ // starts fresh instead of inheriting the suppression.
+ const first = task(150_000, { taskId: '' })
+ const byKey = new Map<string, TaskState>([['agent-x::c1', first]])
+ const { tracker, emit } = liveKeyedTracker(byKey)
+ const { container } = render(nudgeElement(tracker))
+ expect(screen.getByText(/taking longer than usual/i)).toBeTruthy()
+
+ act(() => {
+ screen
+ .getByRole('button', { name: /dismiss this suggestion/i })
+ .dispatchEvent(new MouseEvent('click', { bubbles: true }))
+ })
+ expect(container.firstChild).toBeNull()
+
+ act(() => {
+ emit('agent-x::c1', task(150_000, { taskId: '', startedAt: first.startedAt + 5_000 }))
+ })
+ expect(screen.getByText(/taking longer than usual/i)).toBeTruthy()
+ })
})
diff --git a/desktop-app/ui/src/contexts/ChatComposerStateContext/types.ts b/desktop-app/ui/src/contexts/ChatComposerStateContext/types.ts
index b9188ee81..20619985e 100644
--- a/desktop-app/ui/src/contexts/ChatComposerStateContext/types.ts
+++ b/desktop-app/ui/src/contexts/ChatComposerStateContext/types.ts
@@ -20,6 +20,12 @@ export interface ChatComposerStateContextValue {
failedAgentSend: FailedAgentSend | null
activeMessageCount: number
composerFocusRequestId: number
+ /**
+ * Bumps `composerFocusRequestId` so the mounted composer focuses (and
+ * scrolls) itself. Stable identity — safe in deps. Used by surfaces outside
+ * the composer (e.g. TASK-42 resend) to draw attention to a repopulated draft.
+ */
+ requestComposerFocus: () => void
}
export interface ChatComposerStateProviderProps {
diff --git a/desktop-app/ui/src/contexts/NotificationsContext.tsx b/desktop-app/ui/src/contexts/NotificationsContext.tsx
index e5f9638f1..7c664b124 100644
--- a/desktop-app/ui/src/contexts/NotificationsContext.tsx
+++ b/desktop-app/ui/src/contexts/NotificationsContext.tsx
@@ -1,7 +1,7 @@
import { createContext, useContext } from 'react'
import type { PendingWorkflowApproval } from '../../../src/types'
import type { ApprovalDecisionTarget } from '../hooks/domain/approvalDecision'
-import type { AppNotification, ToastMessage } from '../uiTypes'
+import type { AppNotification, ToastMessage, Tone } from '../uiTypes'
export interface NotificationsContextValue {
notifications: AppNotification[]
@@ -11,6 +11,8 @@ export interface NotificationsContextValue {
pendingApprovalsLoading: boolean
pendingApprovalActionId: string | null
toasts: ToastMessage[]
+ /** Pushes onto the app toast stack (same controller the status bar uses). */
+ pushToast: (message: string, tone: Tone, options?: { durationMs?: number }) => void
markNotificationsRead: () => void
clearNotifications: () => void
removeNotification: (notificationId: string) => void