Skip to content

The agent that grows with you

fix(desktop): mount every chat.empty contributor, not just the first

Brooklyn Nicholson832ec82f759c
diff --git a/apps/desktop/src/components/assistant-ui/chat-empty-slot.test.tsx b/apps/desktop/src/components/assistant-ui/chat-empty-slot.test.tsx
new file mode 100644
index 00000000000..38e6a7afdd3
--- /dev/null
+++ b/apps/desktop/src/components/assistant-ui/chat-empty-slot.test.tsx
@@ -0,0 +1,76 @@
+/**
+ * The `chat.empty` slot mounts EVERY contributor, not just the first.
+ *
+ * Ownership of an empty transcript is per session and is not known until each
+ * plugin has loaded its own data, so a first-wins slot let whichever plugin
+ * happened to register first suppress the one that actually owns the chat —
+ * silently, permanently, and only for some users, since registration order
+ * depends on which plugins are installed.
+ */
+
+import { render, screen } from '@testing-library/react'
+import { afterEach, describe, expect, it } from 'vitest'
+
+import { registry } from '@/contrib'
+import { CHAT_EMPTY_AREA, type ChatEmptyContribution } from '@/lib/chat-empty'
+
+import { ChatEmptySlot } from './chat-empty-slot'
+
+const disposers: (() => void)[] = []
+
+function contribute(id: string, render: ChatEmptyContribution['render']) {
+ disposers.push(registry.register({ area: CHAT_EMPTY_AREA, data: { render }, id }))
+}
+
+afterEach(() => {
+ for (const dispose of disposers.splice(0)) {
+ dispose()
+ }
+})
+
+describe('an empty transcript asks every contributor', () => {
+ it('renders the owner even when an earlier contributor declined', () => {
+ contribute('declines', () => null)
+ contribute('owns', ({ sessionId }) => <span data-testid="owner">owner of {sessionId}</span>)
+
+ render(<ChatEmptySlot sessionId="s-1" />)
+
+ expect(screen.getByTestId('owner').textContent).toBe('owner of s-1')
+ })
+
+ it('renders nothing when everyone declines', () => {
+ contribute('a', () => null)
+ contribute('b', () => null)
+
+ const { container } = render(<ChatEmptySlot sessionId="s-1" />)
+
+ expect(container.textContent).toBe('')
+ })
+
+ it('renders nothing when nobody contributes at all', () => {
+ const { container } = render(<ChatEmptySlot sessionId="s-1" />)
+
+ expect(container.textContent).toBe('')
+ })
+
+ it('shows a conflict rather than hiding one of the claimants', () => {
+ contribute('first', () => <span>first</span>)
+ contribute('second', () => <span>second</span>)
+
+ render(<ChatEmptySlot sessionId="s-1" />)
+
+ expect(screen.getByText('first')).toBeTruthy()
+ expect(screen.getByText('second')).toBeTruthy()
+ })
+
+ it('isolates a throwing contributor from the ones beside it', () => {
+ contribute('boom', () => {
+ throw new Error('contributor exploded')
+ })
+ contribute('owns', () => <span data-testid="owner">still here</span>)
+
+ render(<ChatEmptySlot sessionId="s-1" />)
+
+ expect(screen.getByTestId('owner').textContent).toBe('still here')
+ })
+})
diff --git a/apps/desktop/src/components/assistant-ui/chat-empty-slot.tsx b/apps/desktop/src/components/assistant-ui/chat-empty-slot.tsx
index 3009f2a9801..cccdb9f7629 100644
--- a/apps/desktop/src/components/assistant-ui/chat-empty-slot.tsx
+++ b/apps/desktop/src/components/assistant-ui/chat-empty-slot.tsx
@@ -6,31 +6,50 @@ import { ContribBoundary, ContribRender } from '@/contrib/react/boundary'
import { CHAT_EMPTY_AREA, type ChatEmptyContribution } from '@/lib/chat-empty'
/**
- * The empty transcript's contributed slot. Mounts the first registration and
- * lets it decide — it renders the session's empty state, or nothing at all if
- * the session isn't one it owns.
+ * The empty transcript's contributed slot. Mounts every registration and lets
+ * each decide — it renders the session's empty state, or nothing at all if the
+ * session isn't one it owns.
*
* Deliberately a mount rather than a claim the transcript resolves up front:
* whether a session has an empty state depends on data the plugin loads on its
* own clock (a bot chat's roster lands after the transcript), and only a
* mounted component can subscribe and appear when it arrives.
+ *
+ * That same asynchrony is why the slot cannot mount only the first
+ * registration. Ownership is per session and is not known until each has
+ * loaded, so first-wins would let a plugin that DECLINES a session suppress the
+ * one that owns it, permanently and silently, purely on registration order.
+ * Mounting all of them means disjoint owners each work; two claiming the same
+ * session render both, which is a visible conflict rather than a silent drop.
*/
-export const ChatEmptySlot: FC<{ sessionId: string }> = ({ sessionId }) => {
- const contributions = useContributions(CHAT_EMPTY_AREA)
- const match = contributions[0]
- const render = (match?.data as ChatEmptyContribution | undefined)?.render
-
+const ChatEmptyEntry: FC<{ id: string; render: ChatEmptyContribution['render']; sessionId: string }> = ({
+ id,
+ render,
+ sessionId
+}) => {
// Stable component identity: ContribRender mounts this AS a component, so a
// fresh closure per render would remount the empty state on every tick.
- const renderEmpty = useMemo(() => (render ? () => render({ sessionId }) : null), [render, sessionId])
-
- if (!match || !renderEmpty) {
- return null
- }
+ const renderEmpty = useMemo(() => () => render({ sessionId }), [render, sessionId])
return (
- <ContribBoundary id={match.id}>
+ <ContribBoundary id={id}>
<ContribRender render={renderEmpty} />
</ContribBoundary>
)
}
+
+export const ChatEmptySlot: FC<{ sessionId: string }> = ({ sessionId }) => {
+ const contributions = useContributions(CHAT_EMPTY_AREA)
+
+ return (
+ <>
+ {contributions.map(contribution => {
+ const render = (contribution.data as ChatEmptyContribution | undefined)?.render
+
+ return render ? (
+ <ChatEmptyEntry id={contribution.id} key={contribution.id} render={render} sessionId={sessionId} />
+ ) : null
+ })}
+ </>
+ )
+}
diff --git a/apps/desktop/src/lib/chat-empty.ts b/apps/desktop/src/lib/chat-empty.ts
index fca784ef558..adacd0df880 100644
--- a/apps/desktop/src/lib/chat-empty.ts
+++ b/apps/desktop/src/lib/chat-empty.ts
@@ -12,6 +12,11 @@ import type { ReactNode } from 'react'
* So the slot is contributed. A plugin claims the sessions it owns by
* returning an element for them and `null` for everything else, which is also
* how it stands down while the transcript is still hydrating.
+ *
+ * Ownership is per session, so EVERY registration is mounted and each answers
+ * for itself. Declining is free; two plugins claiming one session render both,
+ * which is the visible cost of never letting registration order silently
+ * suppress the plugin that actually owns the chat.
*/
export const CHAT_EMPTY_AREA = 'chat.empty'