langgraph/libs
Sera f96105368f
fix(langgraph): give add_messages writes and StateGraph input message ids before they are saved (#9772)
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
2026-11-24 15:11:23 -05:00
..
checkpoint release(checkpoint): 4.3.2 (#9699) 2026-11-13 20:21:07 -05:00
checkpoint-conformance release(checkpoint): 4.3.2 (#9699) 2026-11-13 20:21:07 -05:00
checkpoint-postgres chore(deps): bump the minor-and-patch group in /libs/checkpoint-postgres with 6 updates (#9524) 2026-11-18 07:15:55 +00:00
checkpoint-sqlite release(checkpoint): 4.3.2 (#9699) 2026-11-13 20:21:07 -05:00
cli fix(cli): omit an empty secrets list when updating a deployment (#9737) 2026-11-20 10:33:23 -08:00
langgraph fix(langgraph): give add_messages writes and StateGraph input message ids before they are saved (#9772) 2026-11-24 15:11:23 -05:00
prebuilt chore(deps): bump the minor-and-patch group across 1 directory with 8 updates (#9533) 2026-11-20 09:19:05 -08:00
sdk-js docs: standardize package README.md structure (#8064) 2026-06-12 19:32:10 -04:00
sdk-py chore(deps): bump the minor-and-patch group across 1 directory with 8 updates (#9533) 2026-11-20 09:19:05 -08:00