Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(orca): 保留远端派活前的恢复暂停

DavidShenb71f28885dec
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
index e89fbf8013..4c351f82f1 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/agent-input-coordinator.test.ts
@@ -37,7 +37,9 @@ import type {
AgentInputProjection,
AgentInputQueuedMessage,
} from '../../../shared/agentInputQueue.js';
-import { HOST_ONLY_AGENT_PREFIX, USAGE_LIMIT_RESET_AUTO_RESUME_REASON } from '../../../shared/agentInputQueue.js';
+import { HOST_ONLY_AGENT_PREFIX, USAGE_LIMIT_RESET_AUTO_RESUME_REASON, isAutomaticInputOriginKind } from '../../../shared/agentInputQueue.js';
+import { buildRemoteWorkerQueuedMessage } from '../orcaRemoteWorkerRuntime.js';
+import { stampMobileClientOrigin } from '../mobileClientPromptNote.js';
import {
CONTINUE_AFTER_APP_EXIT_PROMPT,
CONTINUE_AFTER_ERROR_PROMPT,
@@ -46,6 +48,7 @@ import {
import type { RecoveryContextSnapshot } from '../recoveryCoordinator.js';
import {
stampTrustedDesktopQueuedOrigin,
+ stampTrustedDeviceLinkQueuedOrigin,
createMakerSendTransaction,
type MakerSendTransactionSession,
TRUSTED_DESKTOP_PI_COMMAND_SNAPSHOT,
@@ -69,6 +72,152 @@ const mocks = vi.hoisted(() => {
};
});
+describe('INPUT_ENQUEUE crash-restored remote Worker pause', () => {
+ const source = readFileSync(new URL('../register.ts', import.meta.url), 'utf8').replace(/\r\n/g, '\n');
+ const start = source.indexOf(' MAKER_INVOKE.INPUT_ENQUEUE,');
+ const handlerStart = source.indexOf(' async (event, sessionId: unknown, item: unknown, opts?: unknown) => {', start);
+ const handlerEnd = source.indexOf('\n );', handlerStart);
+ const handler = source.slice(handlerStart, handlerEnd).trim().replace(/,$/, '');
+ const compiled = transpileModule(`return (${handler});`, {
+ compilerOptions: { target: ScriptTarget.ES2022 },
+ }).outputText;
+
+ function hostInput(h: ReturnType<typeof createHarness>, remote = true, mobile = false) {
+ const noop = () => undefined;
+ const sameItem = (item: AgentInputQueuedMessage) => item;
+ const owner = {};
+ const bindings = {
+ inputCoordinator: h.coordinator,
+ requireSessionId: (id: string) => id,
+ requireQueuedMessage: sameItem,
+ prepareSharedTaskInput: (_sid: string, item: AgentInputQueuedMessage) => item,
+ getCurrentDbClientSnapshot: () => owner,
+ isDeviceLinkInvoke: () => remote,
+ isMobileControllerInvoke: () => mobile,
+ readDeviceLinkInvokeSourceDevice: () => mobile
+ ? { deviceId: 'phone', name: 'Phone', platform: 'android' }
+ : { deviceId: 'lead-computer', name: 'Lead Computer', platform: 'windows' },
+ readClaimedUiLanguage: noop,
+ getResolvedMainLocale: () => 'zh-CN',
+ getInputSessionRow: async () => ({ clearedAt: null }),
+ getMakerIfReady: () => null,
+ remoteInputClientIdWasPersisted: () => false,
+ hasInputDeliveryCancellation: () => false,
+ materializeQueuedOssAttachmentsDeferred: (_sid: string, item: AgentInputQueuedMessage) => ({ item }),
+ hydrateQueuedAgentReferences: sameItem,
+ stampTurnUiLanguage: sameItem,
+ stampTrustedDesktopQueuedOrigin,
+ stampTrustedDeviceLinkQueuedOrigin,
+ stampMobileClientOrigin,
+ isAutomaticInputOriginKind,
+ prepareDeviceLinkAutoTitle: async () => noop,
+ queuedAttachmentOwnership: { activateCurrentOwner: noop },
+ throwIpcError: (code: string, message: string) => { throw Object.assign(new Error(message), { code }); },
+ ...Object.fromEntries([
+ 'assertReviewExternalInputAllowed', 'assertTrustedAppRendererEvent', 'withSessionPermissionChange',
+ 'awaitAgentInputQueueSnapshotPersistence', 'assertRemoteInputClearNotInFlight',
+ 'readRemoteInputClearBoundaryPrecondition', 'observeLocalInputClearBoundary',
+ 'assertExpectedRemoteInputClearBoundary', 'registerQueuedAttachmentOwnership',
+ 'discardSpecificQueuedAttachmentOwnership', 'markQueuedAttachmentDurableAfterSnapshot',
+ ].map(name => [name, noop])),
+ };
+ expect(start).toBeGreaterThan(0);
+ expect(handlerStart).toBeGreaterThan(start);
+ expect(handlerEnd).toBeGreaterThan(handlerStart);
+ return new Function(...Object.keys(bindings), compiled)(...Object.values(bindings)) as
+ (event: object, sid: string, item: AgentInputQueuedMessage, opts?: unknown) => Promise<AgentInputProjection>;
+ }
+
+ function leadInput(clientId = 'lead-input') {
+ return buildRemoteWorkerQueuedMessage({
+ clientId, rawContent: 'new assignment', createOpts: makeItem('settings', '').createOpts,
+ createdAt: '2026-10-10T00:00:00.000Z',
+ });
+ }
+
+ it('keeps restored and newly delegated input paused through the actual remote enqueue handler', async () => {
+ const h = createHarness();
+ const sid = 'restarted-remote-worker';
+ h.setLoadQueueSnapshot(async () => [makeItem('restored', 'old assignment')]);
+ const enqueue = hostInput(h);
+ await enqueue({}, sid, leadInput(), { resumeRestorePausedQueue: true });
+ await enqueue({}, sid, leadInput()); // Same-client retransmission must not resume or duplicate.
+ await flush();
+ expect(h.coordinator.getProjection(sid)).toMatchObject({ queuePaused: true });
+ expect(h.coordinator.getProjection(sid).pendingQueue.map(item => item.clientId)).toEqual(['restored', 'lead-input']);
+ expect(latestSnapshotClientIds(h.persistQueueSnapshot)).toEqual(['restored', 'lead-input']);
+ expect(h.sendToAgent).not.toHaveBeenCalled();
+
+ h.coordinator.resume(sid);
+ await flush();
+ expect(h.sendToAgent).toHaveBeenCalledOnce();
+ expect(h.sendToAgent.mock.calls[0]?.[1]).toEqual({ type: 'user', content: 'old assignment' });
+ });
+
+ it.each([['phone', true, true], ['remote desktop', true, false], ['local desktop', false, false]] as const)(
+ 'allows explicit %s input to resume the restored Worker queue', async (_name, remote, mobile) => {
+ const h = createHarness();
+ const sid = 'user-resumes-remote-worker';
+ h.setLoadQueueSnapshot(async () => [makeItem('restored', 'old assignment')]);
+ await hostInput(h, remote, mobile)({}, sid, makeItem('user-input', 'continue please'));
+ await flush();
+ expect(h.coordinator.getProjection(sid).queuePaused).toBe(false);
+ expect(h.sendToAgent).toHaveBeenCalledOnce();
+ expect(h.sendToAgent.mock.calls[0]?.[1]).toEqual({ type: 'user', content: 'old assignment' });
+ expect(h.coordinator.getProjection(sid).pendingQueue.map(item => item.clientId)).toEqual(['user-input']);
+ },
+ );
+
+ it('keeps a user-stopped queue paused for both Lead and phone input', async () => {
+ const h = createHarness();
+ const sid = 'stopped-remote-worker';
+ await h.coordinator.ensureQueueRestored(sid);
+ h.setRunning(true);
+ h.coordinator.enqueue(sid, makeItem('before-stop', 'queued before stop'));
+ await flush();
+ h.coordinator.stop(sid, { keepQueue: true, pauseQueue: true });
+ h.setRunning(false);
+ await flush();
+ expect(h.coordinator.getProjection(sid).queuePaused).toBe(true);
+ await hostInput(h)({}, sid, leadInput());
+ await hostInput(h, true, true)({}, sid, makeItem('user-input', 'hello'));
+ await flush();
+ expect(h.coordinator.getProjection(sid).queuePaused).toBe(true);
+ expect(h.sendToAgent).not.toHaveBeenCalled();
+ expect(h.coordinator.getProjection(sid).pendingQueue.map(item => item.clientId)).toEqual(['before-stop', 'lead-input', 'user-input']);
+ });
+
+ it('does not pause an online Worker without a restored queue', async () => {
+ const h = createHarness();
+ await hostInput(h)({}, 'online-worker', leadInput());
+ await flush();
+ expect(h.coordinator.getProjection('online-worker').queuePaused).toBe(false);
+ expect(h.sendToAgent).toHaveBeenCalledOnce();
+ });
+
+ it('still treats local renderer input as explicit after dropping its claimed automatic origin', async () => {
+ const h = createHarness();
+ const sid = 'local-user-input';
+ h.setLoadQueueSnapshot(async () => [makeItem('restored', 'old assignment')]);
+ await hostInput(h, false)({}, sid, leadInput());
+ await flush();
+ expect(h.coordinator.getProjection(sid).queuePaused).toBe(false);
+ expect(h.sendToAgent).toHaveBeenCalledOnce();
+ expect(h.coordinator.getProjection(sid).pendingQueue[0]?.origin).toBeUndefined();
+ });
+
+ it('lets another controller send to another task without releasing the restored Worker', async () => {
+ const h = createHarness();
+ h.setLoadQueueSnapshot(async sid => sid === 'restored-worker' ? [makeItem('restored', 'old assignment')] : []);
+ await hostInput(h)({}, 'restored-worker', leadInput());
+ await hostInput(h, true, true)({}, 'other-task', makeItem('phone-input', 'ordinary input'));
+ await flush();
+ expect(h.coordinator.getProjection('restored-worker').queuePaused).toBe(true);
+ expect(h.sendToAgent).toHaveBeenCalledOnce();
+ expect(h.sendToAgent.mock.calls[0]?.[0]).toBe('other-task');
+ });
+});
+
describe('queued welcome dispatch receipts', () => {
function setup() {
const h = createHarness();
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index 40d22c653a..9e7e16c612 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -17851,11 +17851,10 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
let duplicate = false;
const projection = inputCoordinator.enqueue(sid, queued, {
...(opts && typeof opts === 'object' ? (opts as { sendAtMs?: number }) : undefined),
- // INPUT_ENQUEUE 只承载显式用户输入(composer 发送 / UI trigger / device-link
- // 被控端转投的用户消息):崩溃恢复出的暂停队列遇到显式输入即放行,解开
- // 「继续任务/新消息全部排队直到重启」的死锁。Orca 自动投递走 main 侧直调
- // enqueue,不带此 flag,恢复暂停语义不变。
- resumeRestorePausedQueue: true,
+ // 本机与远控用户显式输入可放行崩溃恢复暂停,避免「继续任务」再次排进暂停队列。
+ // 远端 Orca 派活也经此 IPC。来源盖章会剥掉 wire 的 origin,因此从规范化远控载荷
+ // 读取自动投递意图,只用于收紧恢复暂停,不授予来源身份或权限;本机仍按显式输入处理。
+ resumeRestorePausedQueue: !(deviceLinkInvoke && isAutomaticInputOriginKind(parsed.origin?.kind)),
onDuplicate: () => {
duplicate = true;
},
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 9607a1dc4d..8f9ff359ce 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -649,6 +649,9 @@ B 上的 Worker 是一条普通任务,`sessions.orca_remote_lead`(migration 01
- **A 驱动 B 的其余通道**全部是已有同账号 channel:`maker:input:enqueue`(按 `clientId` 幂等,
`durableDelivery`)、`maker:input:get-projection`(投递回执)、`maker:list-active`、`local-db:sessions:get`、
`local-db:history:messages`、`maker:abort-session`;B 不需要知道「这是协同派活」,只认来源标签。
+- **恢复暂停**:B 的 `INPUT_ENQUEUE` 按已有自动消息来源判据处理 `origin.kind`,Orca 派活不解除
+ 崩溃恢复后的队列暂停;普通手机/桌面用户输入仍可解除恢复暂停,用户 Stop 暂停不受影响。
+ 不新增 wire 字段或改变版本,A 的既有派活载荷不变;旧 B 保持其原有行为,需更新 B 才有此修复。
- **B 侧约束**:带标记的任务不能再开启协同(`assertLeadCollabProjectEnabled` 统一拒绝 Worker 与远端 Worker,
覆盖 IPC、远程与 Agent 工具入口),不能复制到其他电脑(`task-migration/service.ts`);侧栏照常显示,
任务头标注「来自 X 的协同」,结束后显示「协同已结束」。
diff --git a/docs/dev-rules/remote-and-mobile-adaptation.md b/docs/dev-rules/remote-and-mobile-adaptation.md
index 280797842d..f9da7e5278 100644
--- a/docs/dev-rules/remote-and-mobile-adaptation.md
+++ b/docs/dev-rules/remote-and-mobile-adaptation.md
@@ -111,6 +111,12 @@ relay 以 close 1013 `inbound backpressure` 主动断连,此时任何「立即
现成 session 发送锁串行执行;其它 Worker 不受阻塞。多台控制端共享同一运行设备的回归仍需实机补测。
已有多设备单测覆盖一台离线时另一台仍能回报;同 owner 的启动恢复幂等,不清空现有派活。
+ 运行设备的 `INPUT_ENQUEUE` 也承载远端 Orca 自动派活,不能一律当作用户显式输入。
+ 规范化远控载荷的自动来源意图只用于保留崩溃恢复队列的暂停,不授予来源身份或权限;
+ 本机、手机和另一台桌面的普通用户输入
+ 仍可解除恢复暂停,用户 Stop 暂停保持不变。只影响该任务,不重建 link 或 relay;
+ 内存回归运行实际 IPC handler 与 coordinator,覆盖持久队列、clientId 去重以及另一控制端的其它任务。
+
**已知未修复缺口**:远端 queued 派活仍提前执行 accepted/commit,并把旧、新输入合并为同一待回报身份,可能阻塞或覆盖旧轮次回报,也会提前清除手动中断标记。
修复需要将 active report 与未消费投递分别持久化,并覆盖连续轮次、撤回、未知回执、accepted 回滚与重启恢复;仅延迟两个回调不能补齐这个缺口。