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(mobile): 对齐历史恢复与 Fork 的等待窗口

DavidShen2fcee5bf20c7
diff --git a/apps/mobile/src/__tests__/invokeTimeouts.test.ts b/apps/mobile/src/__tests__/invokeTimeouts.test.ts
index f5fb0ae9ec..41d547871a 100644
--- a/apps/mobile/src/__tests__/invokeTimeouts.test.ts
+++ b/apps/mobile/src/__tests__/invokeTimeouts.test.ts
@@ -33,6 +33,7 @@ describe("resolveMobileInvokeTimeoutMs", () => {
// fork:载入完整消息前缀 + SDK fork + 事务批量拷贝,大会话 15-30s;非幂等,
// 误超时后桌面仍会建出新会话,重试会分叉重复副本。
expect(resolveMobileInvokeTimeoutMs('maker:fork')).toBe(30_000);
+ expect(resolveMobileInvokeTimeoutMs('maker:fork-strip-encrypted')).toBe(30_000);
// rewind:commit:DB 读 + 线程回滚 + Git 回退 + SQLite 事务,非幂等——误超时
// 后对话与文件已被回退,重试会作用在已变更的历史上。
expect(resolveMobileInvokeTimeoutMs('maker:rewind:commit')).toBe(30_000);
diff --git a/packages/device-link/src/__tests__/client.test.ts b/packages/device-link/src/__tests__/client.test.ts
index eec936840d..410557a080 100644
--- a/packages/device-link/src/__tests__/client.test.ts
+++ b/packages/device-link/src/__tests__/client.test.ts
@@ -34,6 +34,7 @@ import {
parseTransportPayload,
} from '../transport.js';
import { DL_CONTACTS_SYNC_CHANNEL } from '../contactsSyncProtocol.js';
+import { resolveRemoteInvokeTimeoutMs } from '../invokePolicy.js';
import { SESSION_ACTIVITY_CHANNEL } from '../topics.js';
import { resolveDesktopIceServers, REMOTE_DESKTOP_ICE_CONFIG_TIMEOUT_MS } from '../remoteDesktopIceConfig.js';
import { REMOTE_DESKTOP_ICE_SERVERS } from '../remoteDesktopIce.js';
@@ -129,6 +130,48 @@ function makeHarness(opts?: {
const tick = (ms = 0): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
describe('outbound invoke admission', () => {
+ it('waits for a 20-second mobile history recovery without widening other requests or replaying it', async () => {
+ vi.useFakeTimers();
+ const h = makeHarness({ timing: { pingIntervalMs: 60_000, requestTimeoutMs: 15_000 } });
+ const calls: Promise<unknown>[] = [];
+ try {
+ h.client.start(); await vi.advanceTimersByTimeAsync(0); h.current().ack();
+ const channel = 'maker:fork-strip-encrypted';
+ const recovered = h.client.invoke('host', { channel, args: ['source'] },
+ resolveRemoteInvokeTimeoutMs(channel, ['source'], 'mobile'));
+ const settled = vi.fn();
+ calls.push(recovered.catch(error => error));
+ void recovered.then(settled, settled);
+ const ordinary = h.client.invoke('host', { channel: 'maker:list-active', args: [] })
+ .catch(error => error);
+ calls.push(ordinary);
+ await vi.advanceTimersByTimeAsync(15_000);
+ expect(settled).not.toHaveBeenCalled();
+ expect(await ordinary).toMatchObject({ code: 'INVOKE_TIMEOUT' });
+
+ // Other peers can still complete requests while the recovery waits.
+ const other = h.client.invoke('other-host', { channel: 'maker:list-active', args: [] });
+ calls.push(other.catch(error => error));
+ const otherFrame = h.current().sent.find(frame => frame.kind === 'invoke' && frame.dst === 'other-host')!;
+ h.current().push({ v: PROTOCOL_VERSION, kind: 'invoke-result', src: 'other-host', id: otherFrame.id,
+ payload: { ok: true, result: [] } });
+ await expect(other).resolves.toMatchObject({ ok: true });
+
+ await vi.advanceTimersByTimeAsync(5_000);
+ const recoveryFrames = h.current().sent.filter(frame => frame.kind === 'invoke' &&
+ (frame.payload as InvokePayload).channel === channel);
+ expect(recoveryFrames).toHaveLength(1);
+ h.current().push({ v: PROTOCOL_VERSION, kind: 'invoke-result', src: 'host', id: recoveryFrames[0].id,
+ payload: { ok: true, result: { id: 'recovered-task' } } });
+ await expect(recovered).resolves.toEqual({ ok: true, result: { id: 'recovered-task' } });
+ expect(h.sockets).toHaveLength(1);
+ expect(h.current().closed).toBeNull();
+ expect(h.current().sent.some(frame => frame.kind === 'link-close')).toBe(false);
+ } finally {
+ h.client.stop(); await Promise.all(calls); vi.useRealTimers();
+ }
+ });
+
it('shares 12/4 across ordinary and shared-task destinations while preserving wire scope', async () => {
vi.useFakeTimers();
const h = makeHarness({ timing: { pingIntervalMs: 60_000, requestTimeoutMs: 30_000 } });
diff --git a/packages/device-link/src/__tests__/invokePolicy.test.ts b/packages/device-link/src/__tests__/invokePolicy.test.ts
index 828dc869db..b14795afd0 100644
--- a/packages/device-link/src/__tests__/invokePolicy.test.ts
+++ b/packages/device-link/src/__tests__/invokePolicy.test.ts
@@ -8,6 +8,16 @@ import {
} from '../index.js';
describe('remote invoke policy boundaries', () => {
+ it('keeps mobile history recovery within the fork budget without retrying writes', () => {
+ const channel = 'maker:fork-strip-encrypted';
+ expect(resolveRemoteInvokeTimeoutMs(channel, ['source'], 'mobile')).toBe(30_000);
+ expect(resolveRemoteInvokeTimeoutMs(channel, ['source'], 'desktop')).toBeUndefined();
+ expect(resolveRemoteInvokeTimeoutMs('maker:list-active', [], 'mobile')).toBeUndefined();
+ expect(isPeerResetRetryableReadChannel(channel)).toBe(false);
+ expect(isCompletedInvokeRetryableReadChannel(channel)).toBe(false);
+ expect(canCoalesceRemoteListing({ channel, args: ['source'] })).toBe(false);
+ });
+
it.each(['desktop', 'mobile'] as const)('waits for group sends only on %s without replaying writes', (platform) => {
const channel = 'maker:remote-resources:invoke';
expect(resolveRemoteInvokeTimeoutMs(channel, [{ collectionId: 'bot-groups', actionId: 'send' }], platform)).toBe(180_000);
diff --git a/packages/device-link/src/invokePolicy.ts b/packages/device-link/src/invokePolicy.ts
index 843f471cf6..e044ea0a29 100644
--- a/packages/device-link/src/invokePolicy.ts
+++ b/packages/device-link/src/invokePolicy.ts
@@ -92,6 +92,9 @@ export const MOBILE_INVOKE_TIMEOUT_OVERRIDES_MS: Record<string, number> = {
'file-browser:remote-op': 30_000,
'maker:create-session': 30_000,
'maker:fork': 30_000,
+ // Readable-history recovery also loads history, may start Codex, and copies messages.
+ // Keep the normal fork window; a timeout does not cancel the host-side operation.
+ 'maker:fork-strip-encrypted': 30_000,
'maker:get-context-usage': 30_000,
'maker:goal:resume': 30_000,
'maker:goal:set': 30_000,