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): 读取跨越后台时回前台立即补读共享目录
david21773f9221e8
diff --git a/packages/device-link/src/__tests__/sharedTaskListPoller.test.ts b/packages/device-link/src/__tests__/sharedTaskListPoller.test.tsindex 7e1ece6795..d3a21d26f0 100644--- a/packages/device-link/src/__tests__/sharedTaskListPoller.test.ts+++ b/packages/device-link/src/__tests__/sharedTaskListPoller.test.ts@@ -101,3 +101,18 @@ it('defers a refresh owed by an in-flight read until the app returns to the foreexpect(poll.mock.calls[1][0]).toEqual({ fresh: true });poller.dispose();});++it('rereads right after a read that was still in flight across a background period', async () => {+ let finish!: (count: number) => void;+ poll.mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }));+ const poller = startSharedTaskListPoller({ poll, isVisible: () => visible });+ visible = false; poller.visibilityChanged();+ await vi.advanceTimersByTimeAsync(30_000);+ visible = true; poller.visibilityChanged();+ expect(reads()).toBe(1);+ finish(0);+ await vi.advanceTimersByTimeAsync(0);+ // The pre-background snapshot is not trusted; the return is paid at once.+ expect(reads()).toBe(2);+ poller.dispose();+});diff --git a/packages/device-link/src/sharedTaskListPoller.ts b/packages/device-link/src/sharedTaskListPoller.tsindex 3b33397e21..1cf6ef49aa 100644--- a/packages/device-link/src/sharedTaskListPoller.ts+++ b/packages/device-link/src/sharedTaskListPoller.ts@@ -65,8 +65,12 @@ export function startSharedTaskListPoller(options: {if (!options.isVisible()) { cancel(); return; }const elapsed = Date.now() - lastReadAt;// A negative interval means the clock moved backwards; read rather than trust it.- if (refreshPending || elapsed < 0 || elapsed >= SHARED_TASK_LIST_RESUME_MIN_MS) void run();- else schedule();+ if (refreshPending || elapsed < 0 || elapsed >= SHARED_TASK_LIST_RESUME_MIN_MS) {+ // A read still in flight began before the background period and may+ // return an old snapshot; owe one more read right after it.+ if (busy) refreshPending = true;+ void run();+ } else schedule();},dispose() { disposed = true; cancel(); },};