The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(chat): coalesce delta updates before applying to state
Steven Enamakel4183fb3d03f0
diff --git a/app/src/providers/ChatRuntimeProvider.tsx b/app/src/providers/ChatRuntimeProvider.tsxindex 46179a80b1..68fce1ebe6 100644--- a/app/src/providers/ChatRuntimeProvider.tsx+++ b/app/src/providers/ChatRuntimeProvider.tsx@@ -602,7 +602,9 @@ const ChatRuntimeProvider = ({ children }: { children: React.ReactNode }) => {};rtLog('subscribe_chat_events', { socket: socketStatus });- const cleanup = subscribeChatEvents({+ // Deltas are coalesced per frame; every other event flushes them first so+ // ordering holds. See `chatDeltaCoalescer`.+ const coalesced = withCoalescedDeltas<ChatTextDeltaEvent, ChatEventListeners>({onInferenceStart: (event: ChatInferenceStartEvent) => {rtLog('inference_start', { thread: event.thread_id, request: event.request_id });// Fresh turn: drop the previous turn's live processing transcript so a@@ -1587,9 +1589,11 @@ const ChatRuntimeProvider = ({ children }: { children: React.ReactNode }) => {dispatch(clearThreadInferenceActive(event.thread_id));},});+ const cleanup = subscribeChatEvents(coalesced.listeners);return () => {rtLog('unsubscribe_chat_events');+ coalesced.dispose();cleanup();};}, [dispatch, resolveVisibleThreadForProactive, socketStatus, refetchSnapshot]);diff --git a/app/src/services/chatDeltaCoalescer.ts b/app/src/services/chatDeltaCoalescer.tsindex 2fbf712f57..90ba2dc28f 100644--- a/app/src/services/chatDeltaCoalescer.ts+++ b/app/src/services/chatDeltaCoalescer.ts@@ -99,13 +99,7 @@ export function createChatDeltaCoalescer<E extends CoalescibleDelta>(cancel ??= schedule(flush);};- return {- push,- flush,- dispose: () => {- flush();- },- };+ return { push, flush, dispose: flush };}type DeltaListeners<E extends CoalescibleDelta> = {@@ -118,16 +112,16 @@ type DeltaListeners<E extends CoalescibleDelta> = {* every other listener flushes them first (see the ordering note above).* `dispose` delivers anything still queued and stops the scheduled flush.*/-export function withCoalescedDeltas<- E extends CoalescibleDelta,- L extends DeltaListeners<E> & Record<string, unknown>,->(listeners: L, schedule: FlushScheduler = frameScheduler): { listeners: L; dispose: () => void } {+export function withCoalescedDeltas<E extends CoalescibleDelta, L extends DeltaListeners<E>>(+ listeners: L,+ schedule: FlushScheduler = frameScheduler+): { listeners: L; dispose: () => void } {const coalescer = createChatDeltaCoalescer<E>((channel, event) => {if (channel === 'content') listeners.onTextDelta?.(event);else listeners.onThinkingDelta?.(event);}, schedule);const wrapped: Record<string, unknown> = {};- for (const [name, listener] of Object.entries(listeners)) {+ for (const [name, listener] of Object.entries(listeners as Record<string, unknown>)) {if (typeof listener !== 'function') {wrapped[name] = listener;continue;