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(device-link): 避免后台配额阻塞任务首拉与恢复探测

Dash77212085d1f5
diff --git a/docs/dev-rules/remote-and-mobile-adaptation.md b/docs/dev-rules/remote-and-mobile-adaptation.md
index fa89aed55c..9cfc2d3392 100644
--- a/docs/dev-rules/remote-and-mobile-adaptation.md
+++ b/docs/dev-rules/remote-and-mobile-adaptation.md
@@ -71,7 +71,8 @@ relay 以 close 1013 `inbound backpressure` 主动断连,此时任何「立即
## 共享恢复与请求策略
普通出站 invoke 在共享 `InvokeScheduler` 中按目标设备排队:每台最多 12 个在途,
-其中 PR 引用/状态、任务列表、定时任务侧栏和用量同步等后台查询最多 4 个。
+其中 PR 引用/状态、定时任务侧栏和用量同步等后台查询最多 4 个。
+任务列表同时用于首拉与恢复探测,统一走前台配额(仍受总并发 12 限制),不被后台配额阻塞。
前台请求优先于尚未发送的后台请求;不同设备独立推进。PR 的重复聚焦/注册沿用
`PrRefsContext` 的单任务在途合并,不额外重试或保存结果。握手、订阅控制与远控心跳
不占业务队列,避免业务拥堵阻断连接或 lease 维护。
diff --git a/packages/device-link/src/__tests__/client.test.ts b/packages/device-link/src/__tests__/client.test.ts
index 7b6330c7b8..beaac553b8 100644
--- a/packages/device-link/src/__tests__/client.test.ts
+++ b/packages/device-link/src/__tests__/client.test.ts
@@ -126,6 +126,38 @@ function makeHarness(opts?: {
const tick = (ms = 0): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
describe('outbound invoke admission', () => {
+ it('sends initial session lists and recovery probes while all background slots are occupied', async () => {
+ vi.useFakeTimers();
+ const h = makeHarness({ timing: { pingIntervalMs: 60_000, requestTimeoutMs: 30_000 } });
+ const calls: Promise<unknown>[] = [];
+ try {
+ h.client.start(); await vi.advanceTimersByTimeAsync(1); h.current().ack();
+ for (let i = 0; i < 5; i++) calls.push(h.client.invoke('a', {
+ channel: 'git-context:pr-refs:list', args: [`session-${i}`],
+ }).catch(e => e));
+ const sent = () => h.current().sent.filter(e => e.kind === 'invoke');
+ expect(sent()).toHaveLength(4);
+ for (const args of [[30, 'active'], [1, 'all', { includePinned: false }]]) calls.push(h.client.invoke('a', {
+ channel: 'local-db:sessions:list', args,
+ }, 12_000).catch(e => e));
+ const lists = sent().filter(e => (e.payload as { channel: string }).channel === 'local-db:sessions:list');
+ expect(lists).toHaveLength(2);
+ expect(sent()).toHaveLength(6);
+ for (const request of lists) h.current().push({
+ v: PROTOCOL_VERSION, kind: 'invoke-result', src: 'a', id: request.id,
+ payload: { ok: true, result: [] },
+ });
+ await vi.advanceTimersByTimeAsync(1);
+ await expect(Promise.all(calls.slice(5))).resolves.toEqual([
+ { ok: true, result: [] }, { ok: true, result: [] },
+ ]);
+ // Releasing foreground slots must not let the fifth background request exceed its quota.
+ expect(sent()).toHaveLength(6);
+ } finally {
+ h.client.stop(); await Promise.all(calls); vi.useRealTimers();
+ }
+ });
+
it('batches PR refreshes, admits interactive work and keeps control traffic and other peers moving', async () => {
vi.useFakeTimers();
const h = makeHarness({ timing: { pingIntervalMs: 60_000, requestTimeoutMs: 30_000 } });
diff --git a/packages/device-link/src/invokePolicy.ts b/packages/device-link/src/invokePolicy.ts
index fe18268382..f0b2ff9911 100644
--- a/packages/device-link/src/invokePolicy.ts
+++ b/packages/device-link/src/invokePolicy.ts
@@ -2,11 +2,12 @@ import { INVOKE_TIMEOUT_OVERRIDES_MS } from './allowlist.js';
import { TASK_MIGRATION_CHANNEL } from './taskMigration.js';
import type { InvokePayload } from './protocol.js';
-/** These reads may wait behind current-task work. Not a retry or authorization policy. */
+/** These reads may wait behind current-task work. Not a retry or authorization policy.
+ * sessions:list also serves initial loading and recovery probes, so it stays foreground.
+ */
const BACKGROUND_INVOKE_CHANNELS = new Set([
'git-context:pr-refs:list',
'git-context:pr-status',
- 'local-db:sessions:list',
'maker:schedule:list-sidebar-index-runs',
'maker:usage:device-rows',
]);