Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(device-link): bound direct ACK wait for large results
MagicLizi87b5c8a0ae7f
diff --git a/docs/dev-rules/remote-and-mobile-adaptation.md b/docs/dev-rules/remote-and-mobile-adaptation.mdindex ad8b46e112..c600658531 100644--- a/docs/dev-rules/remote-and-mobile-adaptation.md+++ b/docs/dev-rules/remote-and-mobile-adaptation.md@@ -124,7 +124,8 @@ relay 以 close 1013 `inbound backpressure` 主动断连,此时任何「立即授权仍由 relay 执行。relay 报告对端离线(含被移出账号)、链路被关闭或撤权、客户端停止时立即撤下直连。ACK 原路返回,单向失效时发送端不会被困在直连上。- **故障半径三问**:① 故障层级是单个 peer 的直连通道(通道关闭、写入失败、发送缓冲- 在一个可靠重试基准期内没有下降,或已发出的帧过了重发期限仍未确认);缓冲仍有进展时+ 在一个可靠重试基准期内没有下降,或已发出的帧过了自适应 ACK 基准期仍未确认);直连+ 判活不乘 relay 的大消息字节退避,单条大结果也能及时回退;缓冲仍有进展时继续等待排空,不误判正常背压;② 动作只撤下这一台设备的直连,把它仍未确认的帧恢复为未发送、按 relay 既有恢复预算(先探测一批、收到 ACK 再继续)重发,不重连relay、不重建链路,直连的失败不消耗 relay 的重试次数;③ 回归见diff --git a/packages/device-link/src/__tests__/client.test.ts b/packages/device-link/src/__tests__/client.test.tsindex 9a499f0335..f98cfc4090 100644--- a/packages/device-link/src/__tests__/client.test.ts+++ b/packages/device-link/src/__tests__/client.test.ts@@ -10562,8 +10562,8 @@ describe('直连优先、中继兜底(Device Link direct path)', () => {} finally { h.client.stop(); vi.useRealTimers(); }});- // A small tail can reach its retry deadline while a fragmented head is still cooling down.- it.each(['ack-timeout', 'send-failed'])('replays from the large head when a later direct result triggers %s', async (trigger) => {+ // Cover both tail-triggered recovery and a lone large response with no tail to trigger it.+ it.each(['ack-timeout', 'send-failed', 'single-large'])('completes fragmented results through relay after %s', async (trigger) => {vi.useFakeTimers();const relay = new MemoryRelay();const host = makeRelayClient(relay, 'desktop', { transportRetryIntervalMs: 1_000, requestTimeoutMs: 30_000 });@@ -10591,19 +10591,27 @@ describe('直连优先、中继兜底(Device Link direct path)', () => {await pump(); await opening;const direct = connectDirect({ id: 'viewer-a', client: a }, { id: 'desktop', client: host });direct.drop.toLeft = true;- for (let index = 0; index < 2; index++) request(index);+ const requestCount = trigger === 'single-large' ? 1 : 2;+ for (let index = 0; index < requestCount; index++) request(index);await pump();- expect(executions).toBe(2);+ expect(executions).toBe(requestCount);expect(results).toHaveLength(0);if (trigger === 'send-failed') {direct.failSend.right = true;request(2);+ } else if (trigger === 'single-large') {+ // Keep the healthy relay pumping while the ordinary request deadline approaches.+ for (let second = 0; second < 35 && results.length === 0; second++) {+ await vi.advanceTimersByTimeAsync(1_000);+ await pump();+ }} else {await vi.advanceTimersByTimeAsync(1_100);}await pump();- const expectedCount = trigger === 'send-failed' ? 3 : 2;+ const expectedCount = trigger === 'send-failed' ? 3 : requestCount;expect(results).toHaveLength(expectedCount);+ expect(results[0]).toHaveProperty('ok', true);expect(results[0]).toEqual({ ok: true, result: large });for (const result of results.slice(1)) expect(result).toEqual({ ok: true, result: 'small' });expect(executions).toBe(expectedCount);diff --git a/packages/device-link/src/client.ts b/packages/device-link/src/client.tsindex 1222294cd1..e2dcae514d 100644--- a/packages/device-link/src/client.ts+++ b/packages/device-link/src/client.ts@@ -4681,13 +4681,17 @@ export class DeviceLinkClient {RELIABLE_RETRY_MAX_SIZE_INTERVALS,Math.ceil(pending.bytes / RELIABLE_RETRY_BYTES_PER_INTERVAL),);- const retryDelayMs = reliableRetryDelayMs(- peer.rtt,- this.timing.transportRetryIntervalMs,- sizeIntervals,- pending.attempts,- pending.bytes,- );+ // 直连无 ACK 时要及时换路:relay 的大消息字节退避可能长于调用方超时,+ // 不能让单条大结果在失效直连上等满退避期才尝试健康的 relay。+ const retryDelayMs = pending.path === 'direct'+ ? retransmitBaseMs(peer.rtt, this.timing.transportRetryIntervalMs)+ : reliableRetryDelayMs(+ peer.rtt,+ this.timing.transportRetryIntervalMs,+ sizeIntervals,+ pending.attempts,+ pending.bytes,+ );if (pending.sent && !opts.ignoreInterval && now - pending.lastSentAt < retryDelayMs) {// A large head frame may still be inside its byte-based cooldown while// a later small request is already eligible. Cumulative ACK cannot