Skip to content

The agent that grows with you

fix(desktop): decide image/file byte-upload by the session's own connection, not ambient

chelsealong6b3977b577e6
diff --git a/apps/desktop/src/app/chat/session-tile-actions.ts b/apps/desktop/src/app/chat/session-tile-actions.ts
index 3ad4d8a5893..4397e932f18 100644
--- a/apps/desktop/src/app/chat/session-tile-actions.ts
+++ b/apps/desktop/src/app/chat/session-tile-actions.ts
@@ -22,8 +22,8 @@ import { resetSessionBackground } from '@/store/composer-status'
import { notifyError } from '@/store/notifications'
import { clearPreviewArtifacts } from '@/store/preview-status'
import { clearAllPrompts } from '@/store/prompts'
-import { $connection, $sessions, sessionMatchesStoredId } from '@/store/session'
-import { $sessionStates, patchSessionTile, sessionTileDelegate } from '@/store/session-states'
+import { $sessions, sessionMatchesStoredId } from '@/store/session'
+import { $sessionStates, isSessionRemote, patchSessionTile, sessionTileDelegate } from '@/store/session-states'
import { broadcastSessionsChanged } from '@/store/session-sync'
import { clearSessionSubagents } from '@/store/subagents'
import { clearSessionTodos } from '@/store/todos'
@@ -178,7 +178,7 @@ export function useSessionTileActions({ requestGateway, runtimeId, scope, stored
attachments: ComposerAttachment[],
options: { updateComposerAttachments?: boolean } = {}
): Promise<{ attachments: ComposerAttachment[]; sessionId: string }> => {
- const remote = $connection.get()?.mode === 'remote'
+ const remote = isSessionRemote(storedIdRef.current ?? sessionId)
let liveSessionId = sessionId
const synced: ComposerAttachment[] = []
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts
index 540dfbf42f3..23415723a35 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts
@@ -28,7 +28,6 @@ import { clearPreviewArtifacts } from '@/store/preview-status'
import { clearAllPrompts } from '@/store/prompts'
import {
$busy,
- $connection,
$currentCwd,
$messages,
$terminalBackend,
@@ -39,7 +38,7 @@ import {
setMessages,
setTurnStartedAt
} from '@/store/session'
-import { $sessionStates } from '@/store/session-states'
+import { $sessionStates, isSessionRemote } from '@/store/session-states'
import { clearSessionSubagents } from '@/store/subagents'
import { clearSessionTodos } from '@/store/todos'
import { setSessionDraftingTool } from '@/store/tool-drafting'
@@ -342,8 +341,8 @@ export function usePromptActions({
options: { updateComposerAttachments?: boolean } = {}
): Promise<{ attachments: ComposerAttachment[]; sessionId: string }> => {
const updateComposerAttachments = options.updateComposerAttachments ?? true
- const remote = $connection.get()?.mode === 'remote'
const storedSessionId = selectedStoredSessionIdRef.current
+ const remote = isSessionRemote(storedSessionId ?? sessionId)
let liveSessionId = sessionId
const synced: ComposerAttachment[] = []
@@ -432,7 +431,7 @@ export function usePromptActions({
// image.attach_bytes.
const eagerlyUploadAttachment = useCallback(
async (sessionId: string, attachment: ComposerAttachment) => {
- const remote = $connection.get()?.mode === 'remote'
+ const remote = isSessionRemote(sessionId)
setComposerAttachmentUploadState(attachment.id, 'uploading')
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 cd0d45eb347..9ae6f5fa433 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
@@ -74,7 +74,8 @@ import { Loader2Icon } from '@/lib/icons'
import { cn } from '@/lib/utils'
import type { ComposerAttachment } from '@/store/composer'
import { notifyError } from '@/store/notifications'
-import { $connection, $terminalBackend } from '@/store/session'
+import { $terminalBackend } from '@/store/session'
+import { isSessionRemote } from '@/store/session-states'
import { notifyThreadEditClose } from '@/store/thread-scroll'
interface UserEditComposerProps {
@@ -446,7 +447,7 @@ export const UserEditComposer: FC<UserEditComposerProps> = ({ cwd, gateway, sess
return droppedFileInlineRefs(osDrops, cwd)
}
- const remote = $connection.get()?.mode === 'remote'
+ const remote = isSessionRemote(sessionId)
const requestGateway = <T,>(method: string, params?: Record<string, unknown>) =>
gateway.request<T>(method, params)
diff --git a/apps/desktop/src/store/session-states.test.ts b/apps/desktop/src/store/session-states.test.ts
index 7210771070c..9bce372be0e 100644
--- a/apps/desktop/src/store/session-states.test.ts
+++ b/apps/desktop/src/store/session-states.test.ts
@@ -4,7 +4,7 @@ import type { ClientSessionState } from '@/app/types'
import { findGroupOfPane, group, split } from '@/components/pane-shell/tree/model'
import { $layoutTree } from '@/components/pane-shell/tree/store'
import { $activeGatewayProfile } from '@/store/profile'
-import { $selectedStoredSessionId, setSessions } from '@/store/session'
+import { $connection, $selectedStoredSessionId, setSessions } from '@/store/session'
import type { SessionTile } from '@/store/session-states'
import {
$sessionStates,
@@ -12,6 +12,7 @@ import {
blankDraftTile,
focusedSessionNeedsRoute,
focusOpenSession,
+ isSessionRemote,
knownOwnerForSession,
markSelectionRestore,
nextSessionTileForWorkspace,
@@ -627,3 +628,49 @@ describe('knownOwnerForSession / requestForOwnedSession (#91684 client half)', (
expect(ambient.mock.calls[0]).toEqual(['approval.respond', { choice: 'once', session_id: 'unknown-session' }])
})
})
+
+describe('isSessionRemote (#94640)', () => {
+ beforeEach(() => {
+ $activeGatewayProfile.set('default')
+ $sessionTiles.set([])
+ })
+ afterEach(() => {
+ $sessionTiles.set([])
+ setSessions([])
+ $connection.set(null)
+ })
+
+ it('falls back to the ambient connection when the session has no known owner route', () => {
+ $connection.set({ mode: 'remote' } as never)
+ expect(isSessionRemote('unknown-session')).toBe(true)
+
+ $connection.set({ mode: 'local' } as never)
+ expect(isSessionRemote('unknown-session')).toBe(false)
+ })
+
+ it("prefers the session's OWN owner route over an ambient connection of a different mode", () => {
+ // The window's active/ambient connection is local, but this session
+ // belongs to a registered secondary REMOTE connection (Bot Mode / the
+ // unified Sessions list). Composer image uploads must still upload
+ // bytes for it — reading ambient mode here shipped a client-local
+ // composer-images path to the remote backend (#94640).
+ $connection.set({ mode: 'local' } as never)
+ $sessionTiles.set([
+ {
+ ownerRoute: { connectionId: 'homelab', mode: 'remote', profile: 'default' },
+ runtimeId: 'rt-1',
+ storedSessionId: 'stored-1'
+ }
+ ])
+
+ expect(isSessionRemote('rt-1')).toBe(true)
+ expect(isSessionRemote('stored-1')).toBe(true)
+ })
+
+ it('falls back to ambient when the owner is a bare pool profile (no connectionId/mode)', () => {
+ $connection.set({ mode: 'remote' } as never)
+ setSessions([{ id: 'stored-2', profile: 'loki' } as never])
+
+ expect(isSessionRemote('stored-2')).toBe(true)
+ })
+})
diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.ts
index 05ad65a8f61..fc3c89039ff 100644
--- a/apps/desktop/src/store/session-states.ts
+++ b/apps/desktop/src/store/session-states.ts
@@ -38,6 +38,7 @@ import { $activeGatewayProfile, normalizeProfileKey } from './profile'
import { clearAllProviderWaits, clearSessionProviderWait } from './provider-wait'
import {
$activeSessionId,
+ $connection,
$lastReadAtBySessionId,
$selectedStoredSessionId,
$sessions,
@@ -757,6 +758,27 @@ export function knownOwnerForSession(sessionId: null | string | undefined): Sess
return sessionTileOwnerRoute(storedSessionId) ?? knownSessionProfile($sessions.get(), storedSessionId)
}
+/**
+ * Whether the connection that OWNS `sessionId` is remote — never the ambient
+ * `$connection`. A session tied to a registered secondary connection (Bot
+ * Mode, the unified Sessions list) can differ from whichever connection the
+ * window currently shows; its RPCs already route to their own owner via
+ * `requestForSessionProfile`, but a caller that instead reads ambient mode to
+ * decide image.attach vs image.attach_bytes ships a client-local path to a
+ * remote backend that can't resolve it (#94640). A bare profile name (no
+ * connectionId) is a pool profile of the ambient connection, so ambient mode
+ * still applies there.
+ */
+export function isSessionRemote(sessionId: null | string | undefined): boolean {
+ const owner = knownOwnerForSession(sessionId)
+
+ if (owner && typeof owner === 'object' && owner.mode) {
+ return owner.mode === 'remote'
+ }
+
+ return $connection.get()?.mode === 'remote'
+}
+
/**
* Dispatch a session-scoped RPC through the OWNER of `sessionId` (tile route →
* known profile), falling back to the ambient dispatcher only when no owner is