Skip to content

fix(langgraph): restore conversation on reconnect to existing thread#219

Merged
blove merged 4 commits into
mainfrom
claude/langgraph-thread-restoration
May 9, 2026
Merged

fix(langgraph): restore conversation on reconnect to existing thread#219
blove merged 4 commits into
mainfrom
claude/langgraph-thread-restoration

Conversation

@blove

@blove blove commented May 9, 2026

Copy link
Copy Markdown
Contributor

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() populates subjects.history$ from the transport's checkpoint history but does not project the latest checkpoint's values.messages into subjects.messages$. The chat composition reads messages$ (not history$), 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 into messages$ and values$. Guarded by messages$.value.length === 0 so an optimistic local submit that beats the history fetch is preserved.

const latest = history[0];
if (latest?.values && subjects.messages$.value.length === 0) {
  const restoredMessages = latest.values.messages ?? [];
  const restoredValues = { ...latest.values };
  delete restoredValues.messages;
  subjects.messages$.next(restoredMessages);
  subjects.values$.next(restoredValues);
}

The messages field is stripped from values$ so consumers reading both subjects don't see duplicates — messages$ is the canonical surface.

Test plan

Verified locally

  • nx run langgraph:lint — 0 errors
  • nx run langgraph:test — 55 tests pass (53 existing + 2 new)
  • New test 1: populates messages$ and values$ from latest checkpoint on initial connect
  • New test 2: does not clobber local optimistic messages if a submit beats the history fetch

Pending visual verification

  • After merge: live smoke against the workspace examples/chat demo. 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.md
Plan: docs/superpowers/plans/2026-05-08-langgraph-thread-restoration.md

blove and others added 4 commits May 8, 2026 18:28
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>
@vercel

vercel Bot commented May 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
cacheplane Ready Ready Preview, Comment May 9, 2026 1:31am

Request Review

@blove blove merged commit 72cf239 into main May 9, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant