openclaw - ✅(Solved) Fix Control UI and TUI chat crash with TypeError: Cannot read properties of undefined (reading 'map') after sending a message [1 pull requests, 3 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#51440Fetched 2026-04-08 01:11:10
View on GitHub
Comments
3
Participants
3
Timeline
9
Reactions
0
Author
Timeline (top)
commented ×3mentioned ×2subscribed ×2cross-referenced ×1

Both Control UI chat and openclaw tui crash with the same error after sending a message:

TypeError: Cannot read properties of undefined (reading 'map')

This is reproducible from the chat flow itself (not just page load / initial render).

Error Message

TypeError: Cannot read properties of undefined (reading 'map')

Root Cause

Both Control UI chat and openclaw tui crash with the same error after sending a message:

TypeError: Cannot read properties of undefined (reading 'map')

This is reproducible from the chat flow itself (not just page load / initial render).

Fix Action

Fixed

PR fix notes

PR #52455: fix(ui): prevent chat crash when group.messages is undefined (fixes #51440)

Description (problem / solution / changelog)

Problem

Both Control UI chat and openclaw TUI crash with the same error after sending a message:

TypeError: Cannot read properties of undefined (reading "map")

This is reproducible from the chat flow itself (not just page load / initial render).

Root Cause

In ui/src/ui/chat/grouped-render.ts line 164, the code calls:

group.messages.map(...)

However, group.messages can be undefined at runtime despite the MessageGroup type definition showing it as Array<...>. This happens when the chat event payload creates a MessageGroup with an undefined messages field.

The crash occurs after message submission during response/event/render handling, affecting both Control UI and TUI since they share the same chat rendering code.

Solution

Added null coalescing operator to safely handle undefined messages:

-${group.messages.map((item, index) =>
+${(group.messages ?? []).map((item, index) =>

Also updated the isStreaming check to use optional chaining:

-isStreaming: group.isStreaming && index === group.messages.length - 1,
+isStreaming: group.isStreaming && index === (group.messages?.length ?? 0) - 1,

Impact

Prevents crash in both Control UI and TUI chat
Gracefully renders empty message groups instead of crashing
Backward compatible (no breaking changes)
Minimal change (2 lines modified)

Testing

✅ TypeScript type check passes
✅ Syntax validation passes
✅ Handles undefined messages gracefully (renders empty list)
✅ Existing messages continue to render normally

Reproduction (Before Fix)

Control UI

  1. Open Control UI chat page
  2. Select a valid session/agent (e.g. main)
  3. Type any message
  4. Press send → CRASH

TUI

  1. Run: openclaw tui
  2. Enter any message in chat
  3. Submit → CRASH

After Fix

Chat renders normally without crashing, even when group.messages is undefined.

Fixes #51440

Changed files

  • ui/src/ui/chat/grouped-render.ts (modified, +4/-4)

Code Example

TypeError: Cannot read properties of undefined (reading 'map')

---

openclaw tui
RAW_BUFFERClick to expand / collapse

Summary

Both Control UI chat and openclaw tui crash with the same error after sending a message:

TypeError: Cannot read properties of undefined (reading 'map')

This is reproducible from the chat flow itself (not just page load / initial render).

Reproduction

Control UI

  1. Open Control UI chat page
  2. Select a valid session/agent (e.g. main)
  3. Type any message
  4. Press send

TUI

  1. Run:
    openclaw tui
  2. Enter any message in chat
  3. Submit

Actual result

  • Control UI shows:
    • TypeError: Cannot read properties of undefined (reading 'map')
  • TUI also throws the same map error
  • The user message itself is usually recorded in the chat/session, but the reply/render chain crashes

Expected result

Sending a chat message in Control UI / TUI should either:

  • render the assistant response normally, or
  • show a structured backend/model error without crashing the UI

What I already ruled out

I tested a few likely suspects locally:

  • Not browser-specific
    • Reproduces in Control UI and TUI
  • Not caused only by default model = glm-5-turbo
    • Switching default model back to openai/gpt-5.4 still reproduces
  • Not caused only by memory-lancedb-pro
    • Temporarily disabled memory-lancedb-pro, restarted gateway, issue still reproduced
  • Not just page-load related
    • Control UI loads fine, other areas work
    • Error appears specifically after sending a message in chat

Notes / observations

  • The crash seems to happen after submission, during response/event/render handling
  • The message often appears in chat history first, then the UI shows the map error
  • Since both Control UI and TUI reproduce, this feels like a shared chat/session payload shape issue rather than only a browser rendering issue

Environment

  • OpenClaw version: v2026.3.13
  • Surface(s):
    • Control UI
    • openclaw tui
  • Reproduced on macOS

Possibly relevant area

I suspect some shared chat/session/reply payload contains a field that is expected to be an array but is occasionally undefined, and both UI/TUI eventually call .map() on it without a guard.

I don't yet have the exact field name, but the repro is stable.

extent analysis

Fix Plan

To fix the TypeError: Cannot read properties of undefined (reading 'map') issue, we need to identify the shared chat/session/reply payload that contains a field expected to be an array but is occasionally undefined. We will add a guard to check for undefined before calling .map() on it.

Steps:

  • Identify the payload field causing the issue
  • Add a null check before calling .map()
  • Update the code to handle the case when the field is undefined

Example Code:

// Before
const messages = payload.messages.map((message) => {
  // Process message
});

// After
const messages = payload.messages ? payload.messages.map((message) => {
  // Process message
}) : [];

Alternatively, you can use the Optional Chaining Operator (?.) to simplify the code:

const messages = payload.messages?.map((message) => {
  // Process message
}) || [];

Verification

To verify that the fix worked, follow the reproduction steps and check that the UI no longer crashes with the TypeError. The chat message should be sent and rendered correctly, or a structured backend/model error should be displayed without crashing the UI.

Extra Tips

  • Make sure to test the fix thoroughly to ensure it doesn't introduce any new issues.
  • Consider adding additional logging or error handling to help diagnose similar issues in the future.
  • Review the code to ensure that all potential undefined values are handled properly to prevent similar errors.

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 Control UI and TUI chat crash with TypeError: Cannot read properties of undefined (reading 'map') after sending a message [1 pull requests, 3 comments, 3 participants]