Servers reading checkpoints key messages by id, so messages need ids
before saving. On `add_messages` channels and `StateGraph` input only
the reducer assigns them: `updates` shows `id=None`, `Overwrite` saves
none, and replays mint new ones. Fixes#9757.
## Changes
- `add_messages` writes, `Overwrite` and `format=` partials included,
get ids before saving; only `None` counts as missing.
- `StateGraph` input gets ids by channel, saved with the input
checkpoint (uuid4, not run-derived). Input is copied; only message
fields change.
- DeltaChannels: `id=""` message objects get ids; in an `Overwrite`, a
pair stays one message, and on `_messages_delta_reducer` channels a lone
one becomes a list.
## Reviewer notes
- Message dicts in `updates`, history and saved writes gain an `"id"`;
two langgraph-api exact-match tests break.
- Strings, `(role, content)` tuples and JSON pair lists can't carry an
id, so become messages there, and in an `Overwrite`'s state.
- JS needs the same change; langgraphjs#3412 covers input.
## Where message ids are set
Before: the reducer mints the id after the write is saved.
```mermaid
sequenceDiagram
participant W as Node return or client input
participant C as Checkpoint (saved write, input)
participant S as updates and history
participant R as add_messages
W->>C: role/content dict, no id
W->>S: no id
C->>R: apply saved write
R-->>C: state gets id A
Note over C,R: Replay, fork or resume applies the write again: id B
```
After: the id is set before the write is saved.
```mermaid
sequenceDiagram
participant W as Node return or client input
participant E as ensure_message_ids
participant C as Checkpoint (saved write, input)
participant S as updates and history
participant R as add_messages
W->>E: role/content dict
E->>C: same dict + id A
E->>S: same dict + id A
C->>R: apply saved write
R-->>C: state keeps id A
Note over C,R: Replay, fork or resume applies the write again: still id A
```
| Written | Saved and streamed as |
|---|---|
| Message dict | Same dict, plus `"id"` |
| Message object | Same object, `id` set |
| String, `(role, content)`, `["user", "hi"]` | Message object |
| `Overwrite` in any form | Same form, items get ids |
## Test Plan
- [x] `updates` ids equal saved ids for dict, tuple and string node
outputs
- [x] `Overwrite` ids stable across `get_state` and a fork
- [x] Replay from the first checkpoint keeps input ids (sync, async,
exit; dict, Pydantic, dataclass and root-channel input)
- [x] `add_messages` keeps `id=""`; a DeltaChannel message with `id=""`
gets an id
- [x] Dict input keeps its keys and order; dataclass input (frozen too)
isn't re-initialized
- [x] Saved ids match applied ids after resume, `Command.update`,
`update_state` and async runs, on every checkpointer
- [x] In an `Overwrite`, a pair stays one message and a lone message
survives the next write (#9757 repro)
- [x] langchain v1 and deepagents unit tests unchanged