perf(mobile): sends respond instantly, thread opens stop freezing #4882
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 3 commits into
main fromrefs/pull/4882/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/mobile/src/state/thread-outbox-manager.ts lines 104 to 106OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -88,8 +88,19 @@8888 return loadPromise;8989 };909091- const enqueue = (message: QueuedThreadMessage): Promise<void> =>92- serialize(async () => {91+ // The queued atom drives the composer's immediate "queued" feedback, so it92+ // is published synchronously; the durable write happens behind it and rolls93+ // the message back out if it fails (durability only matters for crash94+ // recovery, not for the in-session queue).95+ const enqueue = (message: QueuedThreadMessage): Promise<void> => {96+ setMessages([97+ ...currentMessages().filter((candidate) => candidate.messageId !== message.messageId),98+ message,99+ ]);100+ return serialize(async () => {93101 try {94102 await options.storage.write(message);95103 } catch (cause) {104+ setMessages(105+ currentMessages().filter((candidate) => candidate.messageId !== message.messageId),106+ );apps/mobile/src/state/use-thread-composer-state.ts line 170Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -165,2 +152,19 @@165- return messageId;166- } catch (error) {152+ // Enqueue publishes the queued atom synchronously (the durable write153+ // happens behind it), so clearing the draft here gives send feedback on154+ // the tap frame instead of after file I/O. If the write fails the message155+ // is rolled out of the queue and the content is merged back into the156+ // draft, preserving anything typed since.157+ const enqueuePromise = enqueueThreadOutboxMessage({158+ environmentId: selectedThreadShell.environmentId,159+ threadId: selectedThreadShell.id,160+ messageId,161+ commandId: CommandId.make(metadata.commandId),162+ text,163+ attachments,164+ modelSelection: draft.modelSelection ?? thread.modelSelection,165+ runtimeMode: draft.runtimeMode ?? thread.runtimeMode,166+ interactionMode: draft.interactionMode ?? thread.interactionMode,167+ createdAt: metadata.createdAt,168+ });169+ clearComposerDraftContent(threadKey);170+ enqueuePromise.catch((error: unknown) => {
- apps/mobile/src/state/use-thread-composer-state.ts line 180Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -167,5 +157,19 @@157+ const enqueuePromise = enqueueThreadOutboxMessage({158+ environmentId: selectedThreadShell.environmentId,159+ threadId: selectedThreadShell.id,160+ messageId,161+ commandId: CommandId.make(metadata.commandId),162+ text,163+ attachments,164+ modelSelection: draft.modelSelection ?? thread.modelSelection,165+ runtimeMode: draft.runtimeMode ?? thread.runtimeMode,166+ interactionMode: draft.interactionMode ?? thread.interactionMode,167+ createdAt: metadata.createdAt,168+ });169+ clearComposerDraftContent(threadKey);170+ enqueuePromise.catch((error: unknown) => {171+ void mergeComposerDraftContent(threadKey, { text, attachments });167172 setPendingConnectionError(168173 error instanceof Error ? error.message : "Failed to save the queued message.",169174 );170- return null;171- }175+ });
- apps/mobile/src/state/use-thread-outbox-drain.ts line 359Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -349,5 +353,7 @@349353 return false;350354 },351355 );352- const delivery =353- deliveryAction === "remove"356+ // Enqueues publish optimistically before their durable write settles.357+ // Confirm the write landed (and the message wasn't rolled back) before358+ // sending, so a failed write can never chase an already-delivered turn.359+ const delivery = confirmThreadOutboxMessageQueued(nextQueuedMessage).then((queued) => {
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
aeb7de55-944c-4d9f-8f69-5f29340ccb5fYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share