Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
perf(device-link): 将远程调用并发调整为 12/4
Dash0c98ad0cb870
diff --git a/docs/dev-rules/remote-and-mobile-adaptation.md b/docs/dev-rules/remote-and-mobile-adaptation.mdindex 93b1cc6dfd..fa89aed55c 100644--- a/docs/dev-rules/remote-and-mobile-adaptation.md+++ b/docs/dev-rules/remote-and-mobile-adaptation.md@@ -70,8 +70,8 @@ relay 以 close 1013 `inbound backpressure` 主动断连,此时任何「立即## 共享恢复与请求策略-普通出站 invoke 在共享 `InvokeScheduler` 中按目标设备排队:每台最多 8 个在途,-其中 PR 引用/状态、任务列表、定时任务侧栏和用量同步等后台查询最多 2 个。+普通出站 invoke 在共享 `InvokeScheduler` 中按目标设备排队:每台最多 12 个在途,+其中 PR 引用/状态、任务列表、定时任务侧栏和用量同步等后台查询最多 4 个。前台请求优先于尚未发送的后台请求;不同设备独立推进。PR 的重复聚焦/注册沿用`PrRefsContext` 的单任务在途合并,不额外重试或保存结果。握手、订阅控制与远控心跳不占业务队列,避免业务拥堵阻断连接或 lease 维护。diff --git a/packages/device-link/src/__tests__/client.test.ts b/packages/device-link/src/__tests__/client.test.tsindex 25e59c3f56..7b6330c7b8 100644--- a/packages/device-link/src/__tests__/client.test.ts+++ b/packages/device-link/src/__tests__/client.test.ts@@ -135,19 +135,19 @@ describe('outbound invoke admission', () => {for (let i = 0; i < 30; i++) calls.push(h.client.invoke('a', {channel: 'git-context:pr-refs:list', args: [`session-${i}`],}).catch(e => e));- for (let i = 0; i < 8; i++) calls.push(h.client.invoke('a', {+ for (let i = 0; i < 10; i++) calls.push(h.client.invoke('a', {channel: 'local-db:task-tags:execute', args: [{ action: 'get', sessionIds: [`session-${i}`] }],}).catch(e => e));const sent = () => h.current().sent.filter(e => e.kind === 'invoke');- expect(sent()).toHaveLength(8);- expect(sent().filter(e => (e.payload as { channel: string }).channel === 'git-context:pr-refs:list')).toHaveLength(2);+ expect(sent()).toHaveLength(12);+ expect(sent().filter(e => (e.payload as { channel: string }).channel === 'git-context:pr-refs:list')).toHaveLength(4);calls.push(h.client.invoke('a', { channel: 'device-link:subscribe', args: [] }).catch(e => e));calls.push(h.client.invoke('b', { channel: 'local-db:task-tags:execute', args: [] }).catch(e => e));- expect(sent()).toHaveLength(10);+ expect(sent()).toHaveLength(14);const first = sent()[0];h.current().push({ v: PROTOCOL_VERSION, kind: 'invoke-result', src: 'a', id: first.id, payload: { ok: true, result: [] } });await vi.advanceTimersByTimeAsync(1);- expect(sent()).toHaveLength(11);+ expect(sent()).toHaveLength(15);expect(sent().at(-1)?.payload).toMatchObject({ channel: 'local-db:task-tags:execute' });} finally {h.client.stop(); await Promise.all(calls); vi.useRealTimers();@@ -9232,9 +9232,9 @@ describe('confirmed duplicate-open gap repair', () => {await pump(); await p;};await open(phone); await open(healthy);- // Eight requests are sent; two remain locally queued and must be cancelled on reconnect.- for (let i = 0; i < 8; i++) relay.dropNext((sender, env) => sender === 'desktop' && env.dst === 'phone' && env.kind === 'invoke-result');- const old = Promise.all(Array.from({ length: 10 }, () => phone.invoke('desktop', { channel: 'maker:provider:list', args: [] }, 60000).catch(e => e)));+ // Twelve requests are sent; two remain locally queued and must be cancelled on reconnect.+ for (let i = 0; i < 12; i++) relay.dropNext((sender, env) => sender === 'desktop' && env.dst === 'phone' && env.kind === 'invoke-result');+ const old = Promise.all(Array.from({ length: 14 }, () => phone.invoke('desktop', { channel: 'maker:provider:list', args: [] }, 60000).catch(e => e)));await pump(); await vi.advanceTimersByTimeAsync(1000);phone.restartConnection('phone-only-reconnect');await vi.advanceTimersByTimeAsync(1); await pump(); await open(phone);@@ -9247,8 +9247,8 @@ describe('confirmed duplicate-open gap repair', () => {expect(sockets.mock.calls.filter(x => x[0] === 'desktop')).toHaveLength(1);expect(sockets.mock.calls.filter(x => x[0] === 'healthy')).toHaveLength(1);const oldResults = await old;- expect(oldResults.slice(0, 8)).toEqual(Array.from({ length: 8 }, () => ({ ok: true, result: 'x'.repeat(100000) })));- for (const result of oldResults.slice(8)) {+ expect(oldResults.slice(0, 12)).toEqual(Array.from({ length: 12 }, () => ({ ok: true, result: 'x'.repeat(100000) })));+ for (const result of oldResults.slice(12)) {expect(result).toMatchObject({ code: 'NOT_CONNECTED' });expect(result.inFlight).not.toBe(true);}diff --git a/packages/device-link/src/__tests__/invokeScheduler.test.ts b/packages/device-link/src/__tests__/invokeScheduler.test.tsindex 68a511c9e7..39815958fc 100644--- a/packages/device-link/src/__tests__/invokeScheduler.test.ts+++ b/packages/device-link/src/__tests__/invokeScheduler.test.ts@@ -26,7 +26,7 @@ describe("invoke admission", () => {return job.promise;}),);- const foreground = Array.from({ length: 8 }, deferred);+ const foreground = Array.from({ length: 10 }, deferred);const foregroundResults = foreground.map((job, index) =>scheduler.run("a", false, 30_000, () => {started.push(`foreground-${index}`);@@ -36,26 +36,28 @@ describe("invoke admission", () => {expect(started).toEqual(["background-0","background-1",- ...Array.from({ length: 6 }, (_, i) => `foreground-${i}`),+ "background-2",+ "background-3",+ ...Array.from({ length: 8 }, (_, i) => `foreground-${i}`),]);pending[0].resolve();await flush();- expect(started.at(-1)).toBe("foreground-6");+ expect(started.at(-1)).toBe("foreground-8");pending[1].resolve();await flush();- expect(started.at(-1)).toBe("foreground-7");+ expect(started.at(-1)).toBe("foreground-9");for (const job of foreground) job.resolve();await flush();- expect(started.slice(-2)).toEqual(["background-2", "background-3"]);+ expect(started.slice(-2)).toEqual(["background-4", "background-5"]);for (const job of pending) job.resolve();await Promise.all([...results, ...foregroundResults]);- expect(started).toHaveLength(40);+ expect(started).toHaveLength(42);});it("keeps two peers independent and never sends cancelled queued writes after reconnect", async () => {const scheduler = new InvokeScheduler();const active = deferred();- const running = Array.from({ length: 8 }, () =>+ const running = Array.from({ length: 12 }, () =>scheduler.run("a", false, 30_000, () => active.promise),);const write = vi.fn(async () => {});@@ -84,7 +86,7 @@ describe("invoke admission", () => {vi.useFakeTimers();const scheduler = new InvokeScheduler();const active = deferred();- const running = Array.from({ length: 8 }, () =>+ const running = Array.from({ length: 12 }, () =>scheduler.run("a", false, 30_000, () => active.promise),);const send = vi.fn(async () => {});@@ -107,7 +109,7 @@ describe("invoke admission", () => {vi.useFakeTimers();const scheduler = new InvokeScheduler();const active = deferred();- const running = Array.from({ length: 8 }, () =>+ const running = Array.from({ length: 12 }, () =>scheduler.run("a", false, 30_000, () => active.promise),);const send = vi.fn(async () => {});@@ -141,7 +143,7 @@ describe("invoke admission", () => {it("reserves waiting positions for user actions when background refreshes fill their queue", async () => {const scheduler = new InvokeScheduler();const active = deferred();- const pending = Array.from({ length: 98 }, () =>+ const pending = Array.from({ length: 100 }, () =>scheduler.run("a", true, 30_000, () => active.promise).catch((e) => e),);await expect(diff --git a/packages/device-link/src/invokeScheduler.ts b/packages/device-link/src/invokeScheduler.tsindex 2bac202f37..2bf2ade085 100644--- a/packages/device-link/src/invokeScheduler.ts+++ b/packages/device-link/src/invokeScheduler.ts@@ -1,7 +1,7 @@import { DeviceLinkError } from "./protocol.js";-const MAX_ACTIVE = 8;-const MAX_BACKGROUND_ACTIVE = 2;+const MAX_ACTIVE = 12;+const MAX_BACKGROUND_ACTIVE = 4;const MAX_QUEUED = 128;// Background refreshes cannot consume the last waiting positions for user actions.const MAX_BACKGROUND_QUEUED = 96;