-
Notifications
You must be signed in to change notification settings - Fork 478
Description
Description
When using the edit feature on a human message to branch/time-travel, the current implementation causes:
- Duplicate messages appearing in the conversation
- Anthropic validation error: tool_use ids were found without tool_result blocks
Current Implementation (Broken)
In components/thread/messages/human.tsx, handleSubmitEdit passes the new message as input alongside a checkpoint:
thread.submit(
{ messages: [newMessage] }, // ← Problem: passing message as input
{
checkpoint: parentCheckpoint,
// ...
}
);
Expected Behavior (Per LangGraph Docs)
The correct time-travel pattern per https://langchain-ai.github.io/langgraph/how-tos/time-travel/ is:
// Step 1: Update state at checkpoint to add the new message
const newConfig = await client.threads.updateState(threadId, {
values: { messages: [...checkpointMessages, newMessage] },
checkpoint: parentCheckpoint,
});
// Step 2: Resume with null input from the NEW checkpoint
thread.submit(null, { config: newConfig });
Why This Matters
- updateState creates a NEW checkpoint with valid message history
- Passing null as input means no conflicting message injection
- The checkpoint state already contains the new message, so the backend processes it correctly
- Tool use/result pairing is preserved from the parent checkpoint
Steps to Reproduce
- Start a conversation that triggers tool calls (e.g., search, code execution)
- After receiving an AI response, hover over an earlier human message
- Click the Edit (pencil) icon
- Modify the message and submit
- Observe duplicate messages and/or tool_use validation error
Environment
- @langchain/langgraph-sdk version: (check your package.json)
- Browser: Chrome/Firefox/etc.
Additional Context
This works correctly in LangSmith Studio's chat interface, suggesting the issue is specific to the useStream hook's submit implementation or how the checkpoint option is handled.