Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 路径采样不依赖调试记录开关
Dash73815e197655
diff --git a/apps/mobile/src/__tests__/peerFileLifecycle.test.tsx b/apps/mobile/src/__tests__/peerFileLifecycle.test.tsxindex f53bab8b7a..b124041f9a 100644--- a/apps/mobile/src/__tests__/peerFileLifecycle.test.tsx+++ b/apps/mobile/src/__tests__/peerFileLifecycle.test.tsx@@ -19,6 +19,14 @@ const state = vi.hoisted(() => ({commands: [] as any[],rpc: vi.fn(),open: vi.fn(),+ stats: vi.fn(),+ holdReceive: false,+ debug: false,+ log: vi.fn(),+}));+vi.mock("@/debug/mobileDebugLog", () => ({+ mobileDebugEnabled: () => state.debug,+ mobileDebugLog: state.log,}));vi.mock("react-native", () => ({View: ({ children }: any) => children,@@ -43,12 +51,14 @@ vi.mock("react-native-webview", async () => {if (!match) return;const message = JSON.parse(match[1]);state.commands.push(message);+ if (message.action === "receive" && state.holdReceive) return;const result =message.action === "invoke"? JSON.stringify({ ok: true, result: "preview" }): message.action === "stats"- ? JSON.stringify({ path: "relay" })+ ? state.stats(): "v=0";+ if (result === undefined) return;props.onMessage({nativeEvent: {data: JSON.stringify({@@ -74,7 +84,7 @@ vi.mock("expo-file-system", () => ({uri = "/staging";exists = true;create() {}- open() { return { close() {} }; }+ open() { return { close() {}, writeBytes() {} }; }delete() { this.exists = false; state.deleted(); }},Paths: { cache: "/cache", availableDiskSpace: 10 * 1024 ** 3 },@@ -150,6 +160,10 @@ beforeEach(() => {state.sessionBound = true;state.app = "active";state.commands = [];+ state.holdReceive = false;+ state.debug = false;+ state.log.mockClear();+ state.stats.mockReset().mockReturnValue(JSON.stringify({ path: "relay" }));state.deleted.mockClear();state.cache.read.mockReset().mockResolvedValue(null);state.cache.store.mockReset().mockResolvedValue(undefined);@@ -297,3 +311,51 @@ it("releases a cache hit invalidated just before its promise resumes", async ()expect(dispose).toHaveBeenCalledOnce();expect(state.open).not.toHaveBeenCalled();});++it.each(["unknown", "timeout", "route-change", "debug-enabled"])("samples paths after %s and falls back despite steady progress", async (initial) => {+ state.holdReceive = true;+ state.debug = initial === "debug-enabled";+ const started = Date.now();+ if (initial === "route-change") {+ state.stats.mockImplementation(() => JSON.stringify({+ path: Date.now() - started < 8000 ? "direct" : "relay",+ }));+ } else {+ state.stats.mockReturnValueOnce(initial === "timeout" ? undefined : JSON.stringify({ path: "unknown" }));+ }+ const normal = state.rpc.getMockImplementation()!;+ state.rpc.mockImplementation((...args) => args[2][0].action === "open"+ ? Promise.resolve({ ticket: "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", size: 100_000, mimeType: "text/html" })+ : normal(...args));+ const controller = new AbortController();+ let settled = false;+ const transfer = state.download("device", "url", controller.signal).then((result: unknown) => {+ settled = true;+ return result;+ });+ // Cleanup can reject the intentionally unfinished old implementation.+ void transfer.catch(() => {});+ try {+ await vi.advanceTimersByTimeAsync(0);+ const receive = state.commands.find((c) => c.action === "receive");+ expect(receive).toBeDefined();+ for (let offset = 0; offset < 26 && !settled; offset++) {+ act(() => message({ type: "write", id: `write-${offset}`, args: [receive.args[0], offset, "YQ=="] }));+ await vi.advanceTimersByTimeAsync(1000);+ // A route change must restart the rate sample instead of using old-path throughput.+ if (initial === "route-change" && offset === 15) expect(settled).toBe(false);+ }+ expect(settled).toBe(true);+ expect(await transfer).toBeNull();+ expect(state.stats.mock.calls.length).toBeGreaterThan(1);+ expect(state.log).toHaveBeenCalledWith("debug", "files", "slow transfer fallback", expect.objectContaining({ reason: "slow-relay", path: "relay" }));+ expect(state.log.mock.calls.some((c) => c[2] === "direct transfer progress")).toBe(state.debug);+ expect(state.deleted).toHaveBeenCalledOnce();+ const samples = state.stats.mock.calls.length;+ await vi.advanceTimersByTimeAsync(5000);+ expect(state.stats).toHaveBeenCalledTimes(samples);+ } finally {+ controller.abort();+ await transfer.catch(() => {});+ }+});diff --git a/apps/mobile/src/device-link/peerFileTransport.tsx b/apps/mobile/src/device-link/peerFileTransport.tsxindex 37ec4e9331..38fce72e73 100644--- a/apps/mobile/src/device-link/peerFileTransport.tsx+++ b/apps/mobile/src/device-link/peerFileTransport.tsx@@ -53,10 +53,10 @@ import {let swept = false;const origin = "https://cindy-file-peer.invalid";-/** Transfers slower than one sample interval record runtime stats once per interval. */+/** Active transfers refresh route information once per interval. */const PROGRESS_SAMPLE_MS = FILE_PEER_PROGRESS_SAMPLE_MS;/**- * Diagnostics probe budget, independent of the generic 15s command timeout: a stalled+ * Route/diagnostics probe budget, independent of the generic 15s command timeout: a stalled* runtime.stats() voids one sample only and never blocks later sampling ticks.*/const PROBE_BUDGET_MS = 5000;@@ -436,8 +436,8 @@ export function PeerFileTransport() {target.create();const handle = target.open();sinks.current.set(id, { handle, size: file.size, offset: 0 });- // Network arrival (runtime/WebRTC counters) vs. disk writes, once per interval.- // Only while Debug recording is on: otherwise nothing would consume the sample.+ // The watchdog needs current route information even with Debug recording off.+ // Detailed network/disk progress is recorded only when diagnostics are enabled.let sampling = false;// Set when the receive settles: an already-issued stats reply must not append// a progress line behind the outcome log with a dropped sink offset.@@ -454,7 +454,7 @@ export function PeerFileTransport() {rejectReceive(id, 'FILE_PEER_SLOW');void command('close', [id]).catch(() => {});}- if (slow || sampling || !mobileDebugEnabled()) return;+ if (slow || sampling) return;sampling = true;// 诊断探针独立短预算:runtime.stats() 卡死只作废本样本(迟到回包同样丢弃),// 不让 15s 通用超时占住采样节拍,否则恰好在异常链路上拿不到任何样本。@@ -468,6 +468,7 @@ export function PeerFileTransport() {.then((raw) => {if (settled || ended) return;if (connection?.id === id) connection.path = fileTransferPath(raw);+ if (!mobileDebugEnabled()) return;lastProgress = {elapsedMs: Date.now() - transferStartedAt,written: sinks.current.get(id)?.offset ?? null,diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.mdindex 91939849f5..5b1f2d4f02 100644--- a/docs/dev-rules/protocol-compatibility.md+++ b/docs/dev-rules/protocol-compatibility.md@@ -785,6 +785,8 @@ link-accept 双向声明,不改 relay)。Desktop 控制端在本机没有订仅在 Host 明确声明后,于 `offer` 携带 `sessionBound: true`,双方取消空闲倒计时,按远程会话生命周期释放独立文件连接。不主动预热:普通读取只复用已建立的文件通道,首次需要传文件时才建立。运行时断开通知宿主回收,下次取件按需重建,不新增应用层心跳。+传输期间的路径采样独立于调试记录开关,供慢链路回退使用;关闭调试只省略详细进度日志。+采样随传输结束停止,不在空闲文件连接上循环探测。Desktop 显式断链、账号变化、共享连接离线,以及 Mobile 退后台、设备切换、断链时释放。取消同时覆盖排队与尚未拿到连接 ID 的请求;迟到的协商结果不能重新建立连接或触发 OSS。