Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 记下真实失败的图片槽,时间分隔沿用发送时刻
zqchrisbe67e289b2a0
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsxindex ad8599ddc9..5b99426db9 100644--- a/apps/mobile/app/sessions/[sessionId].tsx+++ b/apps/mobile/app/sessions/[sessionId].tsx@@ -6058,6 +6058,7 @@ function SessionScreenContent() {const record = findDurableOutboxRecord(item.clientId);return {...outboxDisplayItem(item),+ ...(record ? { sentAt: record.createdAt } : {}),canCancel: !(record?.creation && !record.prepared && !record.template),};}), [outboxItems, deviceId, sessionId]);diff --git a/apps/mobile/src/__tests__/durableOutbox.test.ts b/apps/mobile/src/__tests__/durableOutbox.test.tsindex bb6eace70a..927a579383 100644--- a/apps/mobile/src/__tests__/durableOutbox.test.ts+++ b/apps/mobile/src/__tests__/durableOutbox.test.ts@@ -1176,6 +1176,23 @@ describe("app-owned delivery and reconciliation", () => {expect(deps.discardUploads).toHaveBeenCalledWith(expect.anything(), [old]);expect(store.getSnapshot()[0]?.item.attachmentSlots[1]).toEqual(unchanged);});+ it('records the slot whose upload failed, even when uploads run out of slot order, and clears it once that slot lands', async () => {+ const { store, deps, runner } = await setup();+ const uploads = [+ { slot: 1, fileName: 'b.png', name: 'b.png', kind: 'image' as const, size: 1 },+ { slot: 0, fileName: 'a.png', name: 'a.png', kind: 'image' as const, size: 1 },+ ];+ await store.add({ ...message(), uploads, item: { ...message().item, attachmentSlots: [null, null] } });+ const retryable = vi.fn(() => false);+ const failing = createDurableOutboxDelivery({ ...deps, retryable });+ deps.upload.mockRejectedValueOnce(new Error('upload failed'));+ await failing.run();+ expect(store.getSnapshot()[0]).toMatchObject({ state: 'failed', failedUploadSlot: 1 });+ expect(deps.enqueue).not.toHaveBeenCalled();+ await store.update(store.getSnapshot()[0]!, { state: 'queued', error: undefined });+ await runner.run();+ expect(store.getSnapshot()[0]?.failedUploadSlot).toBeUndefined();+ });it("persists the first creation message as the FIFO barrier across restart", async () => {const first = await setup();await first.store.add({ ...message("first"), suspended: true });diff --git a/apps/mobile/src/__tests__/pendingSendItems.test.ts b/apps/mobile/src/__tests__/pendingSendItems.test.tsindex 9c1dcda5dc..678208b8b4 100644--- a/apps/mobile/src/__tests__/pendingSendItems.test.ts+++ b/apps/mobile/src/__tests__/pendingSendItems.test.ts@@ -357,7 +357,7 @@ describe('buildPendingSendItems', () => {outboxItem('ready'),outboxItem('uploading', { attachmentCount: 1, uploadedCount: 0, thumbnails: [{ key: 'uploading-slot-0', uri: 'file:///a.jpg', ossRef: null, uploading: true }] }),outboxItem('failed', { failed: true }),- outboxItem('handed', { dispatching: true }),+ outboxItem('handed', { dispatching: true, sentAt: 1_700_000_000_000 }),],});expect(ready).toMatchObject({ phase: 'waiting', waitingFor: 'computer' });@@ -368,6 +368,8 @@ describe('buildPendingSendItems', () => {expect(failed.phase).toBe('failed');// 已交给电脑的条目在等对账,不是在等着发。expect(handed.phase).toBe('sending');+ // 发件箱的发送时刻带进气泡,伙伴对话按它分组。+ expect(handed.sentAt).toBe(1_700_000_000_000);expect(build({ outbox: [outboxItem('ready')] })[0].phase).toBe('sending');});diff --git a/apps/mobile/src/__tests__/sessionOutbox.test.ts b/apps/mobile/src/__tests__/sessionOutbox.test.tsindex 5b3b8020ed..277dc33e2e 100644--- a/apps/mobile/src/__tests__/sessionOutbox.test.ts+++ b/apps/mobile/src/__tests__/sessionOutbox.test.ts@@ -475,24 +475,21 @@ describe('outboxDisplayItem', () => {expect(enqueueFailed.errorText).toBe('RPC boom');});- it('发件箱整条上传失败时,只在没传上去的那张图上标失败,其后未开始的图不再转圈', () => {- // 与 durableOutboxDisplayItem 的真实输出同形:失败只记在整条 phase / enqueueError 上,failedIds 为空。- const item = { ...buildOutboxItem({- clientId: 'c-1', sessionId: 's-1', text: 'hi', permissionModeAtSend: 'ask', readyAttachments: [attachmentFor('ok.jpg')],- readyPreviews: ['file:///tmp/ok.jpg'],+ it('发件箱整条失败时只在投递记下的那张图上标失败,其余图不再转圈;入队失败不标图片', () => {+ // 与 durableOutboxDisplayItem 的真实输出同形:失败只记在 phase / failedUploadSlot 上,failedIds 为空。+ const base = buildOutboxItem({+ clientId: 'c-1', sessionId: 's-1', text: 'hi', permissionModeAtSend: 'ask', readyAttachments: [],claimedUploads: [{ localId: 'u-a', failed: false, kind: 'image', previewUri: 'file:///tmp/a.jpg' },{ localId: 'u-b', failed: false, kind: 'image', previewUri: 'file:///tmp/b.jpg' },],- }), phase: 'failed' as const, enqueueError: 'upload failed' };- expect(item.failedIds).toEqual([]);- expect(outboxDisplayItem(item).thumbnails.map(({ key, uploading, failed }) => ({ key, uploading, failed }))).toEqual([+ });+ const failed = { ...base, phase: 'failed' as const, enqueueError: 'upload failed', failedUploadSlot: 1 };+ expect(outboxDisplayItem(failed).thumbnails.map(({ key, uploading, failed: bad }) => ({ key, uploading, failed: bad }))).toEqual([{ key: 'c-1-slot-0', uploading: false, failed: undefined },{ key: 'c-1-slot-1', uploading: false, failed: true },- { key: 'c-1-slot-2', uploading: false, failed: undefined },]);- // 入队失败(附件都已落定)不标任何图片。- const enqueueFailed = { ...itemWith(), phase: 'failed' as const, enqueueError: 'RPC boom' };+ const enqueueFailed = { ...base, phase: 'failed' as const, enqueueError: 'RPC boom' };expect(outboxDisplayItem(enqueueFailed).thumbnails.some((thumb) => thumb.failed)).toBe(false);});diff --git a/apps/mobile/src/session/MessageRenderer.tsx b/apps/mobile/src/session/MessageRenderer.tsxindex e4beb96e65..44b4518bab 100644--- a/apps/mobile/src/session/MessageRenderer.tsx+++ b/apps/mobile/src/session/MessageRenderer.tsx@@ -1748,14 +1748,19 @@ export function MessageRenderer({}, []);const companionPluginWork = useMemo(() => companion ? companionPluginWorkEntries(items, companionPluginInvocations) : undefined, [companion, items, companionPluginInvocations]);// Desktop MessageStream groups the visible teammate conversation (not hidden work) into five-minute stamps.- // A local send joins at its send time, so its stamp is in place before the echo arrives.+ // Your own send is grouped by its send time from the moment its bubble appears, and its echo+ // (same key) keeps that time, so a phone/computer clock skew cannot add or move a stamp on+ // confirmation. Outbox rows carry the time across restarts.+ const pendingSentAtRef = useRef(new Map<string, number>());const companionTimeGroups = useMemo(() => companion ? collectBotMessageTimeGroups(items.flatMap((item): BotTimelineMessage[] => {if (item.type === 'pending_send') {- const sentAt = localSendStartedAt(item.key);- return sentAt === null ? [] : [{ clientId: item.key, createdAt: sentAt }];+ const sentAt = item.sentAt ?? localSendStartedAt(item.key);+ if (sentAt === null) return [];+ pendingSentAtRef.current.set(item.key, sentAt);+ return [{ clientId: item.key, createdAt: sentAt }];}return item.type === 'message' && (item.message.kind === 'user' || item.message.kind === 'assistant' || item.message.companion)- ? [{ clientId: item.key, createdAt: item.message.createdAt }] : [];+ ? [{ clientId: item.key, createdAt: pendingSentAtRef.current.get(item.key) ?? localSendStartedAt(item.key) ?? item.message.createdAt }] : [];})) : undefined, [companion, items]);const actions: MessageActions & { firstUserMessageClientId?: string } = useMemo(() => ({companion,diff --git a/apps/mobile/src/session/durableOutbox.ts b/apps/mobile/src/session/durableOutbox.tsindex 83b01053fe..1da3f6c715 100644--- a/apps/mobile/src/session/durableOutbox.ts+++ b/apps/mobile/src/session/durableOutbox.ts@@ -46,6 +46,8 @@ export interface DurableOutboxRecord {suspended?: boolean;template?: QueuedRemoteMessage;refreshUploads?: boolean;+ /** Slot whose upload threw on the last attempt; the bubble offers a re-upload on that image only. */+ failedUploadSlot?: number;creation?: {draft: NewSessionDraft;originalWorkingDir?: string;diff --git a/apps/mobile/src/session/durableOutboxDelivery.ts b/apps/mobile/src/session/durableOutboxDelivery.tsindex a9b46a1eb7..4b0c0a97ad 100644--- a/apps/mobile/src/session/durableOutboxDelivery.ts+++ b/apps/mobile/src/session/durableOutboxDelivery.ts@@ -101,6 +101,8 @@ export function createDurableOutboxDelivery(deps: DurableOutboxDeliveryDeps) {};async function deliver(initial: DurableOutboxRecord) {let record = initial;+ // The upload in progress when an attempt throws is the image that did not get through.+ let uploadingSlot: number | undefined;due.set(id(record), Date.now() + 5_000);const startedAt = Date.now();let markAt = startedAt;@@ -300,7 +302,9 @@ export function createDurableOutboxDelivery(deps: DurableOutboxDeliveryDeps) {if (!record.prepared) {for (const upload of record.uploads) {if (record.item.attachmentSlots[upload.slot]) continue;+ uploadingSlot = upload.slot;const attachment = await deps.upload(record, upload);+ uploadingSlot = undefined;let retained = false;try {if (!current(record)) return;@@ -317,6 +321,7 @@ export function createDurableOutboxDelivery(deps: DurableOutboxDeliveryDeps) {(localId) => record.item.slotByLocalId[localId] !== upload.slot,),},+ failedUploadSlot: undefined,});retained = true;} finally {@@ -411,6 +416,7 @@ export function createDurableOutboxDelivery(deps: DurableOutboxDeliveryDeps) {? record.state: "failed",error: deps.describe(error),+ failedUploadSlot: uploadingSlot,...(!isDurableOutboxSettled(record) && deps.mediaFailed?.(error) && record.uploads.length? { refreshUploads: true }: {}),diff --git a/apps/mobile/src/session/mobileDurableOutbox.ts b/apps/mobile/src/session/mobileDurableOutbox.tsindex 7b08141c84..3ba6d07bea 100644--- a/apps/mobile/src/session/mobileDurableOutbox.ts+++ b/apps/mobile/src/session/mobileDurableOutbox.ts@@ -117,6 +117,7 @@ export function durableOutboxDisplayItem(? "dispatching": "uploading",enqueueError: record.error ?? null,+ ...(record.failedUploadSlot !== undefined ? { failedUploadSlot: record.failedUploadSlot } : {}),slotMeta: record.item.slotMeta.map((meta, slot) => {const upload = record.uploads.find((u) => u.slot === slot);return uploaddiff --git a/apps/mobile/src/session/pendingSendItems.ts b/apps/mobile/src/session/pendingSendItems.tsindex 5beffd96a6..6a182bd1d6 100644--- a/apps/mobile/src/session/pendingSendItems.ts+++ b/apps/mobile/src/session/pendingSendItems.ts@@ -111,6 +111,8 @@ export interface MobilePendingSendItem {sourceDevice?: MessageSourceDevice;/** phase 为 waiting 时在等什么。 */waitingFor?: MobilePendingSendWaitingFor;+ /** 本机发出的时刻(手机时钟),伙伴对话的时间分隔按它分组,回流后同 key 沿用。 */+ sentAt?: number;}export interface MobileMessageListExtraData {@@ -460,6 +462,7 @@ export function buildPendingSendItems(input: BuildPendingSendItemsInput): MobilesentInlineTokens: buildPendingSentInlineTokens(item),phase: item.failed ? 'failed' : waitingFor ? 'waiting' : uploadsPending ? 'uploading' : 'sending',...(waitingFor ? { waitingFor } : {}),+ ...(item.sentAt !== undefined ? { sentAt: item.sentAt } : {}),queueIndex: null,thumbs: waitingFor ? item.thumbnails.map((thumb) => ({ ...thumb, uploading: false })) : item.thumbnails,fileCount: item.fileCount,diff --git a/apps/mobile/src/session/sessionOutbox.ts b/apps/mobile/src/session/sessionOutbox.tsindex b49f95dab1..217b777546 100644--- a/apps/mobile/src/session/sessionOutbox.ts+++ b/apps/mobile/src/session/sessionOutbox.ts@@ -169,6 +169,8 @@ export interface MobileOutboxItem {waitingIds: readonly string[];/** 已失败的上传任务(可经 controller.retry 重跑)。 */failedIds: readonly string[];+ /** 持久发件箱:上次尝试中上传抛错的槽(只用于展示单图重传)。 */+ failedUploadSlot?: number;/** enqueue RPC 失败的错误文案(附件失败时为 null,错误看 failedIds)。 */enqueueError: string | null;phase: MobileOutboxPhase;@@ -206,6 +208,8 @@ export interface MobileOutboxDisplayItem {failed: boolean;/** 已交给电脑(发送中 / 待确认 / 电脑已接手):断线时不是「等着发」,而是在等对账。 */dispatching?: boolean;+ /** 本机写入发件箱的时刻(手机时钟),跨重启稳定,用于伙伴对话的时间分隔。 */+ sentAt?: number;/** False while a first-message creation record still owns recovery of the draft. */canCancel?: boolean;/** 失败原因(附件失败给统一文案,enqueue 失败给 RPC 错误)。 */@@ -471,13 +475,9 @@ export function outboxDisplayItem(item: MobileOutboxItem): MobileOutboxDisplayItlet fileCount = 0;const fileNames: string[] = [];const failedSlots = new Set(item.failedIds.map((localId) => item.slotByLocalId[localId]));- // 发件箱按槽序逐个上传、遇错即停,失败只记在整条上:还没落定的第一个槽就是没传上去的那个,- // 其后的槽还没开始传。失败后没有槽在上传。+ // 失败后没有槽在上传;只有投递记下的那个槽(上传时抛错)才标失败,入队失败等不标任何图片。const failed = item.phase === 'failed';- if (failed && failedSlots.size === 0) {- const firstMissing = item.attachmentSlots.findIndex((slot) => slot === null);- if (firstMissing >= 0) failedSlots.add(firstMissing);- }+ if (failed && item.failedUploadSlot !== undefined) failedSlots.add(item.failedUploadSlot);item.attachmentSlots.forEach((slot, index) => {const meta = item.slotMeta[index];if (meta?.kind !== 'image') {