openclaw - ✅(Solved) Fix Bug: User messages not displayed immediately in Control UI (optimistic update lost after history reload) [1 pull requests, 4 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#67961Fetched 2026-04-18 05:54:31
View on GitHub
Comments
4
Participants
3
Timeline
5
Reactions
0
Author
Timeline (top)
commented ×4cross-referenced ×1

Fix Action

Fixed

PR fix notes

PR #68014: fix(ui): preserve optimistically-added user messages during loadChatHistory

Description (problem / solution / changelog)

Summary

When a user sends a message, it is optimistically added to chatMessages before the server confirms it. However, loadChatHistory() would later replace the entire chatMessages with the server history, causing the optimistic message to be lost (or appear as compressed metadata if context compaction had occurred).

Root Cause

The sendChatMessage function adds the user message to chatMessages optimistically:

state.chatMessages = [...state.chatMessages, userMessage];

But loadChatHistory unconditionally replaces chatMessages with the server response:

state.chatMessages = messages.filter((message) => !shouldHideHistoryMessage(message));

If the context was compacted before the message was committed to history, the message appears as a metadata block instead of the original text.

Fix

  1. Track pending messages: Add a _tempId field to optimistically-added messages and track them in a pendingChatMessagesById Map in ChatState

  2. Merge in loadChatHistory: After receiving server history, remove optimistic messages from current chatMessages (those with _tempId), use server history as the base, then re-add pending messages that are not already in server history

  3. Error handling: Preserve pending messages even when loadChatHistory fails to ensure no user messages are lost

Files Changed

  • ui/src/ui/controllers/chat.ts

Testing

Manual testing shows:

  • User messages now appear immediately in the Control UI chat
  • No duplicate messages
  • No metadata blocks replacing original text
  • Works correctly when AI responds with tools used

Related Issues

  • Fixes #67961
  • Related to #67699 (similar root cause)

Changed files

  • ui/src/ui/controllers/chat.ts (modified, +59/-9)
RAW_BUFFERClick to expand / collapse

Bug: User messages not displayed immediately in Control UI

Description:
When a user sends a message in the Control UI (webchat), the message is optimistically added to the local chatMessages state. However, the subsequent WebSocket event triggers loadChatHistory() which replaces the entire local chatMessages with the server response. Since the context has been compacted, the user's message appears as a metadata block instead of the original text.

Steps to reproduce:

  1. Open Control UI webchat
  2. Type and send a message
  3. Message does not appear immediately in the chat window
  4. After AI responds, the user's message appears as compressed metadata

Expected behavior:
User's message should appear immediately in the chat window (optimistic update) without waiting for the AI response.

File: ui/src/ui/controllers/chat.ts
Function: loadChatHistory() and message sending flow

Suggested fix:
When reloading chat history after sending a message, preserve locally pending/unconfirmed user messages rather than replacing them entirely with the server response. One approach would be to track locally sent messages (by their client-generated ID or content hash) and merge them with the server history instead of replacing.

extent analysis

TL;DR

Preserve locally pending user messages when reloading chat history to ensure immediate display of sent messages in the Control UI.

Guidance

  • Identify the loadChatHistory() function in ui/src/ui/controllers/chat.ts and modify it to merge locally sent messages with the server response instead of replacing them.
  • Track locally sent messages using a unique identifier such as a client-generated ID or content hash to distinguish them from server responses.
  • Update the message sending flow to preserve locally pending messages when reloading chat history.
  • Verify the fix by sending a message and checking if it appears immediately in the chat window without waiting for the AI response.

Example

// Example of how to merge locally sent messages with server response
const locallySentMessages = []; // Store locally sent messages with unique IDs
const serverResponse = []; // Server response with chat history

const mergedMessages = serverResponse.concat(locallySentMessages.filter(message => {
  // Filter out messages that are already included in the server response
  return !serverResponse.find(serverMessage => serverMessage.id === message.id);
}));

Notes

This fix assumes that the loadChatHistory() function is responsible for updating the local chatMessages state. The implementation details may vary depending on the specific requirements and constraints of the application.

Recommendation

Apply workaround: Modify the loadChatHistory() function to preserve locally pending user messages when reloading chat history, as this approach allows for immediate display of sent messages without waiting for the AI response.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix Bug: User messages not displayed immediately in Control UI (optimistic update lost after history reload) [1 pull requests, 4 comments, 3 participants]