langchain-ai / langchain-ai/langgraphjs
Studio Chat view crashes with 'Cannot read properties of null (reading messages)' when using @entrypoint graphs
- Dominant language
- TypeScript
- Stars
- 3.3k
- Forks
- 579
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 56
Description
## Summary
Studio's Chat view throws `TypeError: Cannot read properties of null (reading 'messages')` at the end of every AI response when the graph is built with LangGraph's `@entrypoint` functional API.
https://slack-files.com/T04F8K3FZB5-F0AL41ALS4U-3927ca6833
## Root Cause
`@entrypoint` graphs produce an initial checkpoint with `values: null` — the `END` channel hasn't been written yet before the first run. `StateGraph`-based graphs don't have this problem because their channels initialize to `{}`.
When `fetchStateHistory` retrieves the thread's checkpoint history, this null-valued initial state is included. Several code paths then call `getMessages(state.values)` (or equivalent) without guarding against `state.values` being null:
1. **`libs/sdk/src/react/stream.lgp.tsx`** — inline `messageMetadata` IIFE (line ~413): `getMessages(state.values)` where `state.values` can be null. This is the code path that causes the Studio bug.
2. **`libs/sdk/src/ui/branching.ts`** — `getMessagesMetadataMap` (line ~258): `options.getMessages(state.values)`. Used by `sdk-react`, `sdk-svelte`, `sdk-vue`, `sdk-angular`.
3. **`libs/sdk/src/ui/messages.ts`** — `ensureHistoryMessageInstances` (line ~182): `state.values[messagesKey]`. Same root cause.
## Reproduction
1. Create a graph using `@entrypoint` from `langgraph.func` (Python) or equivalent
2. Open Studio Chat view for the graph
3. Send any message
4. After the first AI response renders, the conversation view throws and shows "Failed to render conversation"
## Browser Console
```
ErrorBoundary caught TypeError: Cannot read properties of null (reading 'messages')
at M (BbjM7USCBlnc5J.js:1:21648)
at BbjM7USCBlnc5J.js:1:22732
at j (BbjM7USCBlnc5J.js:1:16853)
at BbjM7USCBlnc5J.js:1:22716
at Array.map ()
at BbjM7USCBlnc5J.js:1:22688
at R (BbjM7USCBlnc5J.js:1:23056)
at B (BbjM7USCBlnc5J.js:1:27682)
```
## Thread State
Confirmed via `GET /threads/{id}/history`: the second history entry (the initial checkpoint) has `values: null`:
```json
[
{ "values": { "messages": [...] } },
{ "values": null }
]
```
## Expected Behavior
Studio Chat renders correctly. Null-valued history states should be treated as "no messages in this checkpoint" and skipped.
Contributor guide
Research direction
Start by reproducing the issue with a LangGraph @entrypoint graph, then read libs/sdk/src/react/stream.lgp.tsx around the messageMetadata IIFE. Compare that path with getMessagesMetadataMap in libs/sdk/src/ui/branching.ts and ensureHistoryMessageInstances in libs/sdk/src/ui/messages.ts. Done means null-valued history states no longer crash Studio Chat or the listed SDK integrations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100