ensure_message_ids(
value: Any,
) -> NoneCoerce message-like write values to typed BaseMessages with stable IDs.
Called in put_writes() before DeltaChannel writes are submitted to the checkpointer. Without this the checkpoint may store raw dicts or id=None BaseMessages; every get_state() replay then produces a different UUID and the same message appears with a different ID in each LangSmith trace.
Handles three input shapes:
Mutating synchronously here (before the background thread is submitted) is safe: the serialised bytes always reflect the post-coercion state.