Diagnose stale body values sent with useChat requests
Guide Diagnose stale body values sent with useChat requests: Symptom: you pass dynamic values (selected model, toggle state, user id) via the transport body, but the server keeps receiving the values from page load. Use this when you hit exactly this in Diagnose. Not for different errors or different tools.
TL;DR: Symptom: you pass dynamic values (selected model, toggle state, user id) via the transport body, but the server keeps receiving the values from page load. Cause: the body was computed once when the transport was constructed. useChat does not re-read a static body object per request. Confirmation: 1.
Fix
Symptom: you pass dynamic values (selected model, toggle state, user id) via the transport body, but the server keeps receiving the values from page load. Expected: this specific failure stops.
The transport accepts functions for per-request values; otherwise rebuild the transport when the values change, or pass the fresh values in the sendMessage options arg: sendMessage({ text }, { body: { model: currentModel } }). Expected: this specific failure stops.
Verification: change the UI control, send, and confirm the server log shows the new value on the first try. Expected: this specific failure stops.
Details
Cause: the body was computed once when the transport was constructed. useChat does not re-read a static body object per request. Confirmation: 1. Find new DefaultChatTransport({ body: { ... } }). If the values come from component state but the object literal was built once, that is the bug. 2. Log the received body server-side across two sends with different UI state. Identical bodies confirm staleness. Fix: make the body dynamic. Rules: 1. Per-request overrides belong in the sendMessage second argument, not in transport construction. 2. If the value changes rarely (user id), constructing the transport inside a memo keyed on it is fine. 3. Never put secrets in body. Body crosses to the client by definition; keys stay server-side.
When to use
You hit exactly this: Diagnose stale body values sent with useChat requests in Diagnose.
When not to use
A different error, or the same symptom in a different tool. This page only covers the failure above.
Compatibility
Diagnose.