Repository navigation
feat(conversation): implement optimistic message handling for real-ti… - #710
Conversation
There was a problem hiding this comment.
Important
Two behavior bugs to fix before merge: an optimistic message with surrounding whitespace never clears (the server trims the persisted text, the client does not), and the floats' new-conversation branch never scopes the overlay to the conversation it was sent in, so starting a fresh conversation can inherit the old pending message.
Reviewed changes
- Optimistic overlay — new
useOptimisticUserMessagehook shows the sender's message and the running state immediately, then drops the overlay when the matching persisteduser_messagearrives (or on send failure). - Send flow —
conversation-view.tsxnow jumps to the latest event on send and re-scopes the overlay when the reply lands in a new conversation; both floating panels get the same hook. - Floating panels — switch from the plain events query to
useConversationEventWindow, so persisted events arrive through the live tail cache instead of going stale until a status change. - Window gap healing —
useConversationEventWindowrefetches once per distinct hole between the paged window and the first live event.
ℹ️ The new gap-healing refetch has no test
use-conversation-event-window.test.tsx covers paging, live merge, and pruning, but nothing exercises the new firstLiveIndex > lastPagedIndex + 1 branch or its healedGapRef dedupe. A case that signals an event at lastPagedIndex + 2 and asserts exactly one conversationEventWindowKey invalidation would lock in the intended "one refetch per distinct hole" behavior.
Technical details
# Missing test for the gap-healing effect
## Affected sites
- `apps/web/src/components/projects/agents/use-conversation-event-window.ts:136-145` — the new effect.
- `apps/web/src/components/projects/agents/use-conversation-event-window.test.tsx` — existing `signal`-driven harness.
## Required outcome
- A boundary gap (e.g. `signal` an event at `lastPagedIndex + 2`) triggers exactly one refetch.
- The same gap does not refetch again on the next render.deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run reviewed the follow-up commit on top of the prior pullfrog review.
- Whitespace normalization —
beginnow trims the message before storing it, so the optimistic bubble matches the server'sTrimSpace-persisted echo; a padded-text test was added. - Float new-conversation scoping — both floating panels now call
optimistic.follow(...)when a send starts a brand-new conversation, so the overlay is scoped and cleared when the user opens a new conversation.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Important
The 60s optimistic-message TTL can drop a message that is queued and still waiting to start, so the sender's own message disappears from the transcript while the conversation stays queued.
Reviewed changes
This run reviewed the delta since 81aebbd (0909d686).
- Added busy-dialog hooks —
useAgentBusyPrompt.sendnow takes optionalonAsk/onResume;conversation-viewhides the overlay while the dialog is open and restores it after queue/force. - Normalized echo matching — both the optimistic text and the persisted event are whitespace-collapsed before comparison;
beginreads the latest index through a ref. - Bounded the overlay — a 60s TTL drops an overlay whose echo never matches; the synthetic event uses a fractional
event_index. - Keyed gap healing by conversation —
healedGapRefnow includesconversationId. - Added tests — TTL expiry, cross-conversation
follow, foreign-conversation clearing, and inner-whitespace echo matching.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
…ueued conversations
There was a problem hiding this comment.
Important
The TTL hold is released as soon as the conversation leaves queued, but the persisted user_message does not exist yet at that point, so the overlay can still disappear before the echo arrives.
Reviewed changes
This run reviewed the delta since 0909d686 (c03b373f).
- Held the safety-net TTL while queued —
useOptimisticUserMessagenow takes aholdTimeoutflag that suspends the 60s expiry, and all three call sites passconversation?.status === "queued". - Covered the hold in tests — a new case advances two TTLs while held, asserts the overlay survives, then clears one tick after release.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run reviewed the delta since c03b373 (dd9fb18): the optimistic-message safety-net TTL now starts when the hold lifts.
- Restarted the TTL when the hold lifts —
useOptimisticUserMessagearms a full 60s timeout only onceholdTimeoutgoes false, so a long queue wait no longer leaves the timer already expired at thequeued → runningtransition, and the overlay survives until the echo is persisted. - Extended the hold test — the queued case now asserts the overlay survives
TTL - 1after release and clears one tick later.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Summary
Fixes three problems with continuing an existing conversation:
user_messageevent.Changes
use-optimistic-user-message.ts): the sent message is overlaid on the event list immediately and the thread is treated as running, so the "thinking" indicator shows right away. The overlay is dropped when the realuser_messageevent (same text, past the index seen at send time) arrives, so it never renders twice. It is also dropped if the send fails or the "agent is busy" dialog is cancelled, and it follows the reply if it starts a new conversation.ai-chat-float.tsx,ai-chat-float-global.tsx): they read a plain events query, but realtime persisted events only land in the live tail cache, so the query stayed stale until a status change. Both now useuseConversationEventWindow, plus the optimistic message. Note they now load only the newest page (200 events) and have no "load older" control.conversation-view.tsx,use-conversation-event-window.ts):jumpToLatest(). Previously a reader who had scrolled up keptfollowingoff and all new events, including their own message, were withheld.Testing
tsc -b, biome, andvitest run src/components/projectspass (426 tests), plus 2 new tests for the optimistic hook.followingcase is the more likely cause of the stale page.