Batch AI events during conversation restoration.#12597
Draft
vorporeal wants to merge 1 commit into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Viewing a large cloud agent conversation could beachball the UI for ~30s. When a viewer joins a shared session, the event loop replays the entire event backlog on the main thread, and every replayed message delta emits a
BlocklistAIHistoryModelevent that fans out to ~22 subscriber types viaflush_effects. Profiling showed ~92% of the freeze was this per-delta subscriber fanout. This got much more noticeable recently because opening a running cloud conversation now attaches to the live session (#11097) and orchestrated sessions are shareable (#11465), so the replay path runs far more often.This PR coalesces history-model events during viewer catch-up so subscribers see one fanout for the whole backlog instead of one per replayed delta:
warpui_core: addsModelContext::capture_emitted_events_for_model, which runs a closure and extracts events queued for a target model instead of leaving them for delivery.BlocklistAIController: while a coalescing window is active (event-backlog catch-up or an existing-conversation replay), shared-session response handling captures history events into a buffer with last-write-wins dedupe for high-volume events (UpdatedStreamingExchangeper exchange, todo list, conversation status/metadata/usage, active conversation). All other events are preserved in order. The buffer is flushed as one batch when the window ends.EventLoop: begins coalescing when joining with a backlog, tracksAgentConversationReplayStarted/Endedbrackets, and flushes at catch-up completion.Deferring is safe because events are already delivered asynchronously via
flush_effects, payloads carry IDs that handlers use to re-read current model state, and the deduped variants' snapshot fields keep the latest payload.The behavior is gated behind
FeatureFlag::CoalesceSharedSessionCatchUpEvents(dogfood-only for now) so we can validate internally before rolling it out.Plan: https://staging.warp.dev/drive/notebook/k3sdmZpC3ZnRo0SJz6iLAT
Conversation: https://staging.warp.dev/conversation/f0493bea-7990-4f61-9e46-bb9cb3f559ce
Testing
./script/runcargo check,./script/format, andcargo clippy --workspace --all-targets --all-features --tests -- -D warningspass.cargo nextest run -p warp -E 'test(event_loop) or test(shared_session)': 175 tests pass.Agent Mode
Co-Authored-By: Oz oz-agent@warp.dev