Skip to content

feat(langgraph): create the thread on the first message in the React session - #1646

Open
blove wants to merge 1 commit into
mainfrom
blove/langgraph-session-lazy-thread
Open

blove wants to merge 1 commit into
mainfrom
blove/langgraph-session-lazy-thread

Conversation

@blove

@blove blove commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Angular agent() accepts threadId as null, creates the thread on the first submit and reports it via onThreadId (libs/langgraph/src/lib/agent.types.ts, FetchStreamTransport.stream calls client.threads.create()). The React LangGraph runtime createSession required threadId: string, so an app had to create a thread before the user typed anything, and an unsent "New chat" left an empty thread behind.

  • SessionOptions.threadId is now optional (string | null); a string behaves exactly as before.
  • New onThreadId?(threadId) option and a read-only session.threadId getter (string | undefined). The id is not added to the snapshot, so existing snapshot shapes are unchanged.
  • New optional AgentTransport.createThread(signal); FetchStreamTransport implements it with client.threads.create({ signal }) (same call Angular makes, no metadata/graph options), under the owned maxRetries policy (0 by default). A supplied transport without it makes a thread-less construction throw TypeError.
  • Without a thread the session sends no request until the first submit, which creates the thread before the run starts.
  • Concurrency: a replacing submit shares the pending creation (one thread). Stop leaves the request running and keeps the thread; dispose aborts it and reports nothing.
  • Failure: the submit settles error with the generic The LangGraph request failed. message; only an unprotected SDK error's numeric status is read (401/403 -> auth), never its message/body. No run started, so it is recovery: 'retry' when retry() exists, otherwise none; the next submit or retry() makes a new request.
  • Before the thread exists: load()/checkStatus() resolve with no request; fork()/regenerate() reject; reconnect()/resume() reject as they already do with nothing to join/answer. No switchThread (one session per thread stays the React model).
  • Runtime README ("Thread creation", retry notes) and the React LangGraph persistence guide updated.

Verification

  • NX_DAEMON=false npx nx run-many -t runtime-quality runtime-type-tests type-tests lint test -p langgraph — pass (new lazy-thread.spec.ts: 14 tests; lazy-thread.type-test.ts).
  • TMPDIR=... node scripts/react-parity/verify-langgraph-candidate.mjs (after its documented prerequisite build) — pass, 31 modules, React 30 / Angular 27 scenarios; no module count change needed.
  • NX_DAEMON=false npx nx run-many -t test lint type-tests -p react — pass (100 files).
  • node --test scripts/react-parity/verify-packages.spec.mjs — 103 pass.
  • node scripts/react-parity/inventory.mjs --check --drift warn — valid.
  • apps/website npx vitest run — docs rules pass; 4 environment failures (missing posthog-node and api-docs fixture path from the symlinked node_modules; two 5s timeouts under machine load that pass alone with --testTimeout=60000).

🤖 Generated with Claude Code

…session

Angular agent() accepts a null threadId, creates the thread on the first
submit and reports it through onThreadId. The React runtime createSession
required a threadId, so apps had to create a thread before the user typed
anything, and a "New chat" that was never sent left an empty thread behind.

threadId is now optional (string | null). Without it the session sends no
request until the first submit, which calls the new optional
transport.createThread() once before the run (the owned SDK transport uses
client.threads.create() under the owned maxRetries policy, 0 by default).
The id is reported through onThreadId and read from session.threadId. A
replacing submit shares the pending request, stop keeps a thread it
creates, and dispose aborts it. A failed creation settles the submit with
the generic request error (status only, never the body) and is retryable,
since no run started. Before the thread exists, load and checkStatus
resolve without a request and fork/regenerate reject. A string threadId
behaves exactly as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@blove
blove enabled auto-merge November 18, 2026 01:14

This branch has not been deployed

No deployments
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