Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

remote: a turn the paired phone started never waits for a card only the computer draws

purple5422fbd03f20
diff --git a/src/api/mcp/workflow-tools.ts b/src/api/mcp/workflow-tools.ts
index 10974f09..2338d3be 100644
--- a/src/api/mcp/workflow-tools.ts
+++ b/src/api/mcp/workflow-tools.ts
@@ -20,6 +20,7 @@ import { v4 as uuid } from 'uuid'
import type { ToolArgs } from './types'
import type { AgentRunContext } from '../agent-context'
import { backendCall } from '../backend'
+import { isPhoneTurn, PHONE_TURN_NO_CARD } from '../../lib/remote-turn-caps'
import { startModelDownload } from '../discover'
import { restartComfyForNewNodes } from '../comfy-restart'
import { clearNodeCache } from '../comfyui-nodes'
@@ -229,6 +230,7 @@ export async function executeWorkflowInstall(args: ToolArgs, run?: AgentRunConte
if (!id) return 'Error: id is missing. Use an id from workflow_find, checked with workflow_inspect. Nothing changed.'
if (!hasComfy()) return NO_COMFY
if (!run?.settingsCard) return NOT_HERE
+ if (isPhoneTurn(run.conversationId)) return PHONE_TURN_NO_CARD
const c = candidateById(id)
if (!c) return `Error: there is no workflow "${cleanName(id, 40)}" from this session. Call workflow_find first.`
@@ -378,6 +380,7 @@ export async function executeWorkflowAssign(args: ToolArgs, run?: AgentRunContex
if (!rawModel) return 'Error: model is missing (a model file name as ComfyUI lists it). Nothing changed.'
if (!hasComfy()) return NO_COMFY
if (!run?.settingsCard) return NOT_HERE
+ if (isPhoneTurn(run.conversationId)) return PHONE_TURN_NO_CARD
const verdict = checkSelfControl(run, { names: assignNames, strong: false, what: 'which workflow a model uses' })
if (!verdict.ok) { audit(run, want, 'refused', verdict.why); return verdict.reply }
const list = useWorkflowStore.getState().installedWorkflows
diff --git a/src/lib/__tests__/phone-turn-no-desktop-card.test.ts b/src/lib/__tests__/phone-turn-no-desktop-card.test.ts
new file mode 100644
index 00000000..248d1729
--- /dev/null
+++ b/src/lib/__tests__/phone-turn-no-desktop-card.test.ts
@@ -0,0 +1,42 @@
+/**
+ * M310: a turn the paired phone started in a shared chat must not wait for a
+ * card that only the computer draws. Before the fix, "Open this address?"
+ * (strict web addresses, on by default in 3.1.0), the settings card and the
+ * workflow card stood at the computer and the phone hung for up to 10 minutes.
+ */
+import { describe, it, expect, afterEach, vi } from 'vitest'
+import { setTurnCaps, clearTurnCaps, isPhoneTurn, PHONE_TURN_NO_CARD } from '../remote-turn-caps'
+import { guardWebUrl } from '../web-url-provenance'
+import { checkSelfControl } from '../self-control-policy'
+import { useWebUrlConfirmStore } from '../../stores/webUrlConfirmStore'
+import type { AgentRunContext } from '../../api/agent-context'
+
+const ALL = { agent: true, files: true, terminal: true, create: true }
+const run = (conversationId: string) => ({ conversationId, toolCallId: 't1', settingsCard: true } as unknown as AgentRunContext)
+
+afterEach(() => { clearTurnCaps('phone-chat'); vi.restoreAllMocks() })
+
+describe('a phone turn gets no desktop card', () => {
+ it('knows a phone turn only while it runs', () => {
+ expect(isPhoneTurn('phone-chat')).toBe(false)
+ setTurnCaps('phone-chat', ALL)
+ expect(isPhoneTurn('phone-chat')).toBe(true)
+ expect(isPhoneTurn('other')).toBe(false)
+ clearTurnCaps('phone-chat')
+ expect(isPhoneTurn('phone-chat')).toBe(false)
+ })
+
+ it('an unknown web address is refused with "ask for the link" instead of a card', async () => {
+ const ask = vi.spyOn(useWebUrlConfirmStore.getState(), 'ask')
+ setTurnCaps('phone-chat', ALL)
+ const out = await guardWebUrl('https://made-up.example.org/x', 'web_fetch', run('phone-chat'))
+ expect(out).toMatch(/Ask the user to send the link/)
+ expect(ask).not.toHaveBeenCalled()
+ })
+
+ it('the settings card is refused in a phone turn and allowed again after it', () => {
+ setTurnCaps('phone-chat', ALL)
+ const v = checkSelfControl(run('phone-chat'), { names: () => true, strong: false, what: 'Temperature' })
+ expect(v).toEqual({ ok: false, why: 'surface', reply: PHONE_TURN_NO_CARD })
+ })
+})
diff --git a/src/lib/remote-turn-caps.ts b/src/lib/remote-turn-caps.ts
index 976ff1d1..ca175c4f 100644
--- a/src/lib/remote-turn-caps.ts
+++ b/src/lib/remote-turn-caps.ts
@@ -38,6 +38,20 @@ export function turnCaps(convId: string | undefined): Partial<PermissionMap> | u
return convId ? caps.get(convId) : undefined
}
+/**
+ * A turn the paired phone started is running in this chat. The cards of the
+ * desktop (Open this address?, settings, workflow installs) are not drawn on
+ * the phone, so such a run must not wait for one: nobody at the phone could
+ * answer it, and the phone would hang until the card times out (M310).
+ */
+export function isPhoneTurn(convId: string | null | undefined): boolean {
+ return !!convId && caps.has(convId)
+}
+
+/** What a card tool answers in a phone turn. */
+export const PHONE_TURN_NO_CARD =
+ 'Error: this chat runs from the paired phone, where the confirmation card of this computer is not shown. Nothing changed. Tell the user to ask for it at the computer.'
+
/**
* The category a tool counts as for the phone's rights. A tool of an
* external MCP server can do anything its server does, so it needs the
diff --git a/src/lib/self-control-policy.ts b/src/lib/self-control-policy.ts
index aafb706f..8531744f 100644
--- a/src/lib/self-control-policy.ts
+++ b/src/lib/self-control-policy.ts
@@ -22,6 +22,7 @@
import { useChatStore } from '../stores/chatStore'
import { previousRunOf, type AgentRunContext } from '../api/agent-context'
import { taintLabel } from './run-taint'
+import { isPhoneTurn, PHONE_TURN_NO_CARD } from './remote-turn-caps'
import type { Message } from '../types/chat'
export const MAX_CARDS_PER_RUN = 3
@@ -82,6 +83,8 @@ export function checkSelfControl(run: AgentRunContext | undefined, ask: PolicyAs
if (!run?.settingsCard) {
return { ok: false, why: 'surface', reply: 'Error: LU can only be changed in a chat where the user sees the confirmation card. Nothing changed.' }
}
+ // A turn the paired phone started: the card would wait at the computer.
+ if (isPhoneTurn(run.conversationId)) return { ok: false, why: 'surface', reply: PHONE_TURN_NO_CARD }
const taintedBy = taintLabel(run)
if (ask.strong && taintedBy) {
return {
diff --git a/src/lib/web-url-provenance.ts b/src/lib/web-url-provenance.ts
index 2f983518..19ea9cfb 100644
--- a/src/lib/web-url-provenance.ts
+++ b/src/lib/web-url-provenance.ts
@@ -19,6 +19,7 @@
// catalog imports it, and the chat store pulls half the app in behind it.
import type { AgentRunContext } from '../api/agent-context'
import { isMobile } from './device-kind'
+import { isPhoneTurn } from './remote-turn-caps'
const URL_IN_TEXT = /https?:\/\/[^\s<>"'`)\]}]+/gi
/** Tools whose results are web content (their links were chosen by a page). */
@@ -169,7 +170,9 @@ export async function guardWebUrl(
// No card can be drawn on the phone (its tool rows have none) or for a call
// outside a chat run (a workflow step): there the model is told to ask, and
// nothing waits for a click that cannot come.
- if (isMobile() || !run) {
+ // A turn the paired phone started in a shared chat is the same case: the
+ // card would stand at the computer while the user waits at the phone.
+ if (isMobile() || !run || isPhoneTurn(convId)) {
return `Error: ${url} was not given by the user and did not appear in a web result of this conversation, so it was not opened. Ask the user to send the link if they want it read.`
}
const { useWebUrlConfirmStore } = await import('../stores/webUrlConfirmStore')