Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 修复撤销排队消息后误报历史消息不存在
Dashd7da2af350d1
diff --git a/apps/mobile/src/__tests__/durableOutbox.test.ts b/apps/mobile/src/__tests__/durableOutbox.test.tsindex 2df0ee9428..65c7922e59 100644--- a/apps/mobile/src/__tests__/durableOutbox.test.ts+++ b/apps/mobile/src/__tests__/durableOutbox.test.ts@@ -191,6 +191,53 @@ async function setup(storage = disk()) {}describe("durable mobile outbox ownership", () => {+ it.each([+ Object.assign(new Error('Message 不存在'), { code: 'NOT_FOUND' }),+ new Error('[NOT_FOUND] Message 不存在'),+ ])('waits for host receipts when pending history is missing (%s)', async (error) => {+ const { store, deps, runner } = await setup();+ await store.add({ ...message(), state: 'host-owned', retrySafe: true });+ deps.projection.mockResolvedValue(projection('id-1', 'pending'));+ deps.history.mockRejectedValue(error);+ await runner.run();+ expect(store.getSnapshot()[0]).toMatchObject({ state: 'host-owned' });+ expect(store.getSnapshot()[0].error).toBeUndefined();+ expect(deps.enqueue).not.toHaveBeenCalled();+ expect(deps.cleanup).not.toHaveBeenCalled();++ // Withdrawal can overtake the history lookup. Only the next host receipt+ // proves removal; missing history alone must never delete or resend the row.+ deps.projection.mockResolvedValue(projection('id-1', 'removed'));+ runner.wake();+ await runner.run();+ expect(store.getSnapshot()).toEqual([]);+ expect(deps.history).toHaveBeenCalledOnce();+ expect(deps.enqueue).not.toHaveBeenCalled();+ expect(deps.cleanup).toHaveBeenCalledOnce();+ });++ it('keeps a legacy send uncertain when its history is not found', async () => {+ const { store, deps, runner } = await setup();+ await store.add({ ...message(), state: 'confirming', prepared: { clientId: 'id-1' } as QueuedRemoteMessage });+ deps.projection.mockResolvedValue({ ...projection(), inputDeliveryVersion: undefined });+ deps.history.mockRejectedValue(new Error('[NOT_FOUND] Message 不存在'));+ await runner.run();+ expect(store.getSnapshot()[0]).toMatchObject({ state: 'failed', error: 'check receipt' });+ expect(deps.enqueue).not.toHaveBeenCalled();+ expect(deps.cleanup).not.toHaveBeenCalled();+ });++ it('still reports other history lookup failures', async () => {+ const { store, deps, runner } = await setup();+ await store.add({ ...message(), state: 'host-owned', retrySafe: true });+ deps.projection.mockResolvedValue(projection('id-1', 'pending'));+ deps.history.mockRejectedValue(new Error('permission denied'));+ await runner.run();+ expect(store.getSnapshot()[0].error).toBe('offline');+ expect(deps.cleanup).not.toHaveBeenCalled();+ expect(deps.enqueue).not.toHaveBeenCalled();+ });+it.each([[false, false, undefined, true],[true, false, 1, true],diff --git a/apps/mobile/src/session/durableOutboxDelivery.ts b/apps/mobile/src/session/durableOutboxDelivery.tsindex 9eefd894ee..7ebe4e892d 100644--- a/apps/mobile/src/session/durableOutboxDelivery.ts+++ b/apps/mobile/src/session/durableOutboxDelivery.ts@@ -59,6 +59,16 @@ export function createDurableOutboxDelivery(deps: DurableOutboxDeliveryDeps) {!stopped && deps.isCurrent() && deps.store.getSnapshot().includes(r);const hasDurableOwnership = (r: DurableOutboxRecord) =>r.state === "host-owned" && isDurableOutboxHandedOff(r);+ const hasHistory = async (record: DurableOutboxRecord): Promise<boolean> => {+ try {+ return await deps.history(record);+ } catch (error) {+ // Pending and withdrawn inputs need not have a history row. Absence is+ // not a delivery failure or proof of cancellation; host receipts decide.+ if (isExplicitRemoteNotFoundError(error)) return false;+ throw error;+ }+ };async function deliver(initial: DurableOutboxRecord) {let record = initial;due.set(id(record), Date.now() + 5_000);@@ -154,7 +164,7 @@ export function createDurableOutboxDelivery(deps: DurableOutboxDeliveryDeps) {} else if (state === "pending") {// Legacy hosts cannot seal a not-yet-arrived enqueue. Keep uncertain cancellation visible.await update({ state: "failed", error: deps.confirmationMessage });- } else if (await deps.history(record)) {+ } else if (await hasHistory(record)) {await finishHistory();} else if (current(record)) {await update({ state: "failed", error: deps.confirmationMessage });@@ -175,18 +185,18 @@ export function createDurableOutboxDelivery(deps: DurableOutboxDeliveryDeps) {if (durableOwnership) {if (record.state !== "host-owned") await deps.accepted?.(record);if (!current(record)) return;- if (await deps.history(record)) {+ if (await hasHistory(record)) {await finishHistory();return;}if (!current(record)) return;- if (!hasDurableOwnership(record))+ if (!hasDurableOwnership(record) || record.error)await update({ state: "host-owned", retrySafe: true, error: undefined });due.set(id(record), Date.now() + 5_000);return;}// Even old hosts may already have persisted a user row after the enqueue receipt was lost.- if ((record.prepared || state === "pending" || state === "accepted") && (await deps.history(record))) {+ if ((record.prepared || state === "pending" || state === "accepted") && (await hasHistory(record))) {await finishHistory();return;}