Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): recover history while presence is unknown
DavidShen7d4f4bde6a39
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsxindex 786756cb9f..6e6bbb8430 100644--- a/apps/mobile/app/sessions/[sessionId].tsx+++ b/apps/mobile/app/sessions/[sessionId].tsx@@ -1060,7 +1060,10 @@ export default function SessionScreen() {const revokedDevices = useRevokedDevices();const unresponsiveDevices = useUnresponsiveDevices();const maker = useMobileMakerTransport(deviceId);- const remoteHistoryAvailable = status === 'online' && getPresenceAvailability(deviceId) === true;+ // A failed roster read leaves presence unknown after reconnect. Allow the+ // existing link/subscription path to establish reachability instead of+ // blocking both history and sync until a presence change happens to arrive.+ const remoteHistoryAvailable = status === 'online' && getPresenceAvailability(deviceId) !== false;// Unknown presence while connecting is loading, not evidence of a lost computer.const showCachedHistoryNotice = status !== 'connecting'&& (status !== 'online' || getPresenceAvailability(deviceId) === false);diff --git a/apps/mobile/src/__tests__/sessionSyncProductionCallbacks.test.ts b/apps/mobile/src/__tests__/sessionSyncProductionCallbacks.test.tsindex f784c209e1..70ba0596cc 100644--- a/apps/mobile/src/__tests__/sessionSyncProductionCallbacks.test.ts+++ b/apps/mobile/src/__tests__/sessionSyncProductionCallbacks.test.ts@@ -36,6 +36,20 @@ function deferred<T>() {const promise = new Promise<T>((yes, no) => { resolve = yes; reject = no; });return { promise, resolve, reject };}++function historyAvailable(status: string, presence: boolean | null): boolean {+ let expression: ts.Expression | undefined;+ const visit = (node: ts.Node) => {+ if (ts.isVariableDeclaration(node) && node.name.getText(source) === 'remoteHistoryAvailable') {+ expression = node.initializer;+ }+ ts.forEachChild(node, visit);+ };+ visit(source);+ if (!expression) throw new Error('Missing production history availability gate');+ return new Function('status', 'getPresenceAvailability', 'deviceId',+ `return ${expression.getText(source)};`)(status, () => presence, 'd1');+}const tick = () => new Promise((done) => setTimeout(done, 0));const session = { id: 's1', updatedAt: '2026-09-06T00:00:00Z', _count: { messages: 100 } };const page = { messages: [{ id: 'm1' }], limit: 1, reducedByPayloadTooLarge: false };@@ -128,6 +142,31 @@ function fixture(reopen = false, remoteHistoryAvailable = true) {}describe('production session recovery callbacks', () => {+ it.each([null, true])('recovers cached history with an online relay and presence=%s', async (presence) => {+ // A failed roster request leaves presence unknown even after link/subscription+ // recovery. Evaluate the real page gate and then execute its real sync callback.+ const f = fixture(true, historyAvailable('online', presence));+ await f.sync();+ expect(f.maker.getSession).toHaveBeenCalledTimes(1);+ expect(f.maker.listMessages).toHaveBeenCalledTimes(1);+ expect(f.state.rows).toEqual(page.messages);+ expect(f.state.readAck).not.toBeNull();+ });++ it.each([+ ['online', false], ['connecting', null], ['connecting', true],+ ['stopped', null], ['stopped', true],+ ] as const)('preserves cached history without remote reads when status=%s presence=%s', async (status, presence) => {+ const f = fixture(true, historyAvailable(status, presence));+ const rows = f.state.rows;+ await f.sync();+ await f.earlier();+ expect(f.state.rows).toBe(rows);+ expect(f.maker.getSession).not.toHaveBeenCalled();+ expect(f.maker.listMessages).not.toHaveBeenCalled();+ expect(f.state.readAck).toBeNull();+ });+it('keeps cached rows offline without fetching metadata, projection, history or earlier pages', async () => {const f = fixture(true, false);const rows = f.state.rows;diff --git a/docs/dev-rules/remote-and-mobile-adaptation.md b/docs/dev-rules/remote-and-mobile-adaptation.mdindex 6c5e513646..855a3e46f7 100644--- a/docs/dev-rules/remote-and-mobile-adaptation.md+++ b/docs/dev-rules/remote-and-mobile-adaptation.md@@ -80,6 +80,11 @@ Desktop 清理某设备的熔断状态不等于该设备已恢复。停用、离刷新同样受设备生命周期代次约束,迟到的失败不得重启已取消的恢复。周期对账复用在途读取,新增内容等事件仍可合并成一次后续刷新;不得为了限制整轮等待而缩短弱网请求预算。+Mobile 历史读取在 relay 已在线且目标 presence 不是明确不可用时,可以沿既有建链和订阅+流程尝试恢复。新连接会清空 presence,设备列表读取失败后的「未知」不等于离线,不能阻断+历史控制器与页面同步;也不能为了放行读取伪造在线快照。明确离线/停用或 relay 未在线时+仍只展示缓存,授权、撤权和旧代结果拦截继续由原链路处理。+`packages/device-link/src/invokePolicy.ts` 集中维护请求策略,三个边界独立判断:- 通道执行预算:保留 Desktop / Mobile 的超时差异,超时不代表主机操作未执行。