Skip to content

The agent that grows with you

fix(desktop): route reload.mcp, onboarding.skip and edit-drop uploads to the owner

Teknium2eba248121ef
diff --git a/apps/desktop/src/components/assistant-ui/thread/user-edit-composer-owner-route.test.tsx b/apps/desktop/src/components/assistant-ui/thread/user-edit-composer-owner-route.test.tsx
index c2691d054b8..9872daba329 100644
--- a/apps/desktop/src/components/assistant-ui/thread/user-edit-composer-owner-route.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/user-edit-composer-owner-route.test.tsx
@@ -12,17 +12,18 @@ import type { HermesGateway } from '@/hermes'
import { useIncrementalExternalStoreRuntime } from '@/lib/incremental-external-store-runtime'
import { queryClient } from '@/lib/query-client'
import type * as GatewayStore from '@/store/gateway'
-import { _resetSessionOwnerHintsForTests, setSessionOwnerHint } from '@/store/session'
+import { $sessions, _resetSessionOwnerHintsForTests, setSessionOwnerHint } from '@/store/session'
import { assistantMessage, stubThreadEnvironment, stubThreadViewportSize, userMessage } from '../test-utils'
import { Thread } from '.'
-const routed = vi.hoisted(() => ({ requestGatewayForAgent: vi.fn() }))
+const routed = vi.hoisted(() => ({ requestGatewayForAgent: vi.fn(), requestGatewayForProfile: vi.fn() }))
vi.mock('@/store/gateway', async importOriginal => ({
...(await importOriginal<typeof GatewayStore>()),
- requestGatewayForAgent: routed.requestGatewayForAgent
+ requestGatewayForAgent: routed.requestGatewayForAgent,
+ requestGatewayForProfile: routed.requestGatewayForProfile
}))
stubThreadEnvironment()
@@ -63,7 +64,9 @@ afterEach(() => {
cleanup()
queryClient.clear()
_resetSessionOwnerHintsForTests()
+ $sessions.set([])
routed.requestGatewayForAgent.mockReset()
+ routed.requestGatewayForProfile.mockReset()
})
describe('message-edit composer completions', () => {
@@ -84,3 +87,53 @@ describe('message-edit composer completions', () => {
expect(gateway.request).not.toHaveBeenCalledWith('commands.catalog', expect.anything())
})
})
+
+describe('message-edit composer attachment drops', () => {
+ // A session row that names only its profile is a bare-string owner. Its
+ // upload still belongs on that profile's socket, never the ambient one.
+ it('stage a dropped image on a bare-profile owner, not the ambient socket', async () => {
+ _resetSessionOwnerHintsForTests()
+ $sessions.set([{ id: SESSION, profile: 'research' }] as never)
+ routed.requestGatewayForProfile.mockImplementation(async (_profile: string, method: string) =>
+ method === 'image.attach' ? { attached: true, path: '/research/cache/shot.png' } : CATALOG
+ )
+ const previous = window.hermesDesktop
+ Object.defineProperty(window, 'hermesDesktop', {
+ configurable: true,
+ value: { ...previous, getPathForFile: () => '/Users/me/shot.png' }
+ })
+
+ const gateway = { request: vi.fn(async () => CATALOG) } as unknown as HermesGateway & {
+ request: ReturnType<typeof vi.fn>
+ }
+
+ try {
+ render(<Harness gateway={gateway} />)
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit message' }))
+ const editor = await screen.findByRole('textbox', { name: 'Edit message' })
+ const file = new File(['png'], 'shot.png', { type: 'image/png' })
+
+ fireEvent.drop(editor, {
+ dataTransfer: {
+ files: Object.assign([file], { item: () => file }),
+ getData: () => '',
+ items: [{ getAsFile: () => file, kind: 'file', webkitGetAsEntry: () => ({ isDirectory: false }) }],
+ types: ['Files']
+ }
+ })
+
+ await waitFor(() =>
+ expect(routed.requestGatewayForProfile).toHaveBeenCalledWith(
+ 'research',
+ 'image.attach',
+ { path: '/Users/me/shot.png', session_id: SESSION },
+ undefined,
+ undefined
+ )
+ )
+ expect(gateway.request).not.toHaveBeenCalledWith('image.attach', expect.anything())
+ } finally {
+ Object.defineProperty(window, 'hermesDesktop', { configurable: true, value: previous })
+ }
+ })
+})
diff --git a/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx b/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx
index db97f9bf6c5..a275e6a0717 100644
--- a/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx
@@ -79,7 +79,8 @@ import { cn } from '@/lib/utils'
import type { ComposerAttachment } from '@/store/composer'
import { notifyError } from '@/store/notifications'
import { $terminalBackend } from '@/store/session'
-import { isSessionRemote } from '@/store/session-states'
+import { ambientRequestFor } from '@/store/session-gone-latch'
+import { isSessionRemote, requestForOwnedSession } from '@/store/session-states'
import { useForcedTextDirection } from '@/store/text-direction'
import { notifyThreadEditClose } from '@/store/thread-scroll'
@@ -462,8 +463,12 @@ export const UserEditComposer: FC<UserEditComposerProps> = ({ cwd, gateway, sess
const remote = isSessionRemote(sessionId)
+ // Staged on the edited session's owner: a bare-profile owner otherwise
+ // rides the ambient socket, which refuses another profile's session.
+ const ambient = ambientRequestFor(gateway)
+
const requestGateway = <T,>(method: string, params?: Record<string, unknown>) =>
- gateway.request<T>(method, params)
+ requestForOwnedSession<T>(sessionId, ambient, method, params)
const refs: InlineRefInput[] = []
diff --git a/apps/desktop/src/lib/mcp-reload.ts b/apps/desktop/src/lib/mcp-reload.ts
index 8907dd198be..881649d8c97 100644
--- a/apps/desktop/src/lib/mcp-reload.ts
+++ b/apps/desktop/src/lib/mcp-reload.ts
@@ -1,9 +1,10 @@
import type { ReloadMcpResult } from '@hermes/shared'
-import type { HermesGateway } from '@/hermes'
import { translateNow } from '@/i18n'
import { $gateway } from '@/store/gateway'
import { notify } from '@/store/notifications'
+import { ambientRequestFor } from '@/store/session-gone-latch'
+import { requestForOwnedSession } from '@/store/session-states'
/**
* What `reload.mcp` did for the chat that asked. The gateway decides and commits; Desktop only reads its
@@ -23,10 +24,12 @@ export interface McpReloadOutcome {
export class McpReloadDeferred extends Error {}
export async function reloadMcp(
- gateway: Pick<HermesGateway, 'request'>,
+ gateway: Parameters<typeof ambientRequestFor>[0],
sessionId: null | string | undefined
): Promise<McpReloadOutcome> {
- const result = await gateway.request<ReloadMcpResult>('reload.mcp', {
+ // The chat's MCP set lives on its owner; the ambient socket refuses (or
+ // reloads the wrong profile for) another profile's session.
+ const result = await requestForOwnedSession<ReloadMcpResult>(sessionId, ambientRequestFor(gateway), 'reload.mcp', {
confirm: true,
session_id: sessionId ?? undefined
})
diff --git a/apps/desktop/src/lib/session-owner-routed-rpcs.test.tsx b/apps/desktop/src/lib/session-owner-routed-rpcs.test.tsx
index e312eeb9d69..d72662b0ca0 100644
--- a/apps/desktop/src/lib/session-owner-routed-rpcs.test.tsx
+++ b/apps/desktop/src/lib/session-owner-routed-rpcs.test.tsx
@@ -37,6 +37,8 @@ const { requestOneShot } = await import('./oneshot')
const { setSessionYolo } = await import('./yolo-session')
const { renameSessionPreferringRpc } = await import('@/app/chat/sidebar/session-actions-menu')
const { ModelVisibilityDialog } = await import('@/components/model-visibility-dialog')
+const { reloadMcp } = await import('./mcp-reload')
+const { skipOnboarding } = await import('@/store/onboarding-run')
stubResizeObserver()
@@ -103,6 +105,31 @@ describe('session_id RPCs go to the session owner, not the ambient socket', () =
})
})
+ it('reload.mcp reloads the chat on its owner', async () => {
+ mocks.requestGatewayForAgent.mockResolvedValue({ session: 'applied', session_servers: ['linear'] })
+
+ await expect(reloadMcp(mocks.ambient as never, RUNTIME)).resolves.toMatchObject({ sessionServers: ['linear'] })
+
+ expect(mocks.ambient.request).not.toHaveBeenCalled()
+ expect(mocks.requestGatewayForAgent).toHaveBeenCalledWith('local', 'research', 'reload.mcp', {
+ confirm: true,
+ session_id: RUNTIME
+ })
+ })
+
+ it('Skip setup ends the onboarding run on its owner', async () => {
+ const ambientRequest = vi.fn(async () => {
+ throw new Error('not_found')
+ })
+
+ await skipOnboarding(ambientRequest as never, RUNTIME)
+
+ expect(ambientRequest).not.toHaveBeenCalled()
+ expect(mocks.requestGatewayForAgent).toHaveBeenCalledWith('local', 'research', 'onboarding.skip', {
+ session_id: RUNTIME
+ })
+ })
+
it('Edit Models reads model.options for a secondary-profile session from its owner, under its profile', async () => {
const catalog: ModelOptionsResult = { providers: [{ models: ['m-research'], name: 'R', slug: 'r' }] }
mocks.requestGatewayForAgent.mockResolvedValue(catalog)
diff --git a/apps/desktop/src/store/onboarding-run.ts b/apps/desktop/src/store/onboarding-run.ts
index 70455e6e3e9..bba5bd98fb9 100644
--- a/apps/desktop/src/store/onboarding-run.ts
+++ b/apps/desktop/src/store/onboarding-run.ts
@@ -30,6 +30,7 @@ import { markOnboardingDecided, ONBOARDING_DECIDE_OFFER_MS, setOnboardingSurface
import { $onboardingSession } from './onboarding-session'
import { ensureGatewayProfile, newSessionInProfile } from './profile'
import { $connection, $gatewayState, $selectedStoredSessionId } from './session'
+import { requestForOwnedSession } from './session-states'
import { dropSetupBeat } from './setup-beat'
export type OnboardingRequest = <T = unknown>(
@@ -312,7 +313,8 @@ export function endOnboarding(outcome: 'done' | 'skipped'): void {
/** Skip setup: the backend ends the run and closes the card that waits, and a new chat opens. A failed
* skip leaves the run going, so Skip setup stays on offer; the caller reports the error. */
export async function skipOnboarding(request: OnboardingRequest, runtimeId: string): Promise<void> {
- await request('onboarding.skip', { session_id: runtimeId })
+ // The run's chat may belong to a non-launch profile; only its owner can end it.
+ await requestForOwnedSession(runtimeId, request, 'onboarding.skip', { session_id: runtimeId })
leaveSkipped()
}