fix(langgraph): restore conversation on reconnect to existing thread#219
Merged
Conversation
Targets Finding D from the live smoke pass: after a page reload, the
conversation is NOT restored even though the threadId is persisted in
localStorage and passed to agent({threadId}).
Root cause: refreshHistory() populates history$ but does not project
the latest checkpoint into messages$ or values$. The chat composition
reads messages$, so the user sees the welcome state.
Fix: extend refreshHistory to project history[0].values into messages$
and values$ on first connect. Guarded by a "messages$ is empty" check
so an optimistic local submit that beats history fetch is preserved.
12 LOC change in the bridge plus 2 unit tests pinning the restore
path and the race-guard.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Five-phase plan: branch, TDD failing restore test, implementation (extend refreshHistory to project latest checkpoint into messages$ + values$, guarded by messages$ empty check), race-guard test, verification + PR. ~92 LOC, 2-3 commits. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
Targets Finding D from the live smoke pass: after a page reload, the conversation is NOT restored even though the threadId is persisted in localStorage and passed to
agent({ threadId }).Root cause
refreshHistory()populatessubjects.history$from the transport's checkpoint history but does not project the latest checkpoint'svalues.messagesintosubjects.messages$. The chat composition readsmessages$(nothistory$), so the user sees the welcome state instead of their prior conversation.Fix
After the existing
subjects.history$.next(history)line, project the most recent checkpoint intomessages$andvalues$. Guarded bymessages$.value.length === 0so an optimistic local submit that beats the history fetch is preserved.The
messagesfield is stripped fromvalues$so consumers reading both subjects don't see duplicates —messages$is the canonical surface.Test plan
Verified locally
nx run langgraph:lint— 0 errorsnx run langgraph:test— 55 tests pass (53 existing + 2 new)messages$andvalues$from latest checkpoint on initial connectPending visual verification
examples/chatdemo. Send a message → reload → conversation reappears with prior user/assistant exchange visible. No flash of welcome state.Spec:
docs/superpowers/specs/2026-05-08-langgraph-thread-restoration-design.mdPlan:
docs/superpowers/plans/2026-05-08-langgraph-thread-restoration.md