Commit 0c72f03
fix(core): keep part timestamps out of message ordering (#17598)
This keeps message part timestamps from affecting transcript ordering.
Part timestamps are still preserved as event metadata, but only the
message-level `createdAt` advances the ordering watermark used for later
messages/signals.
Before, a late part timestamp could push a later signal forward:
```ts
message.createdAt = 10:00:00
part.createdAt = 10:00:30
nextSignal.createdAt = 10:00:30.001
```
After, later messages/signals are ordered from the message-level
timestamp:
```ts
message.createdAt = 10:00:00
part.createdAt = 10:00:30
nextSignal.createdAt = 10:00:03
```
Also preserves the existing message-level `createdAt` when merging
response content into a memory-loaded assistant message, since OM uses
that timestamp to decide whether a message has already been observed.
Verified with the focused message-list regression test, `pnpm
build:core`, and `pnpm --filter ./packages/core check`.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## ELI5
Imagine you're organizing messages by time. This PR fixes a bug where a
late timestamp on a piece of a message (a "part") could reorder later
messages — now only the main message timestamp controls ordering, while
part timestamps are preserved as metadata and no longer affect
transcript ordering.
## Changes
**Changeset Entry** (.changeset/old-news-press.md)
- Adds a patch release note for `@mastra/core` describing the fix:
message-part timestamps no longer advance the transcript ordering
watermark.
**Message Merging**
(packages/core/src/agent/message-list/merge/MessageMerger.ts)
- Preserve an existing message's `createdAt` when merging incoming
content; removed logic that would update/advance `createdAt` from the
incoming message.
- Documentation updated to clarify that `createdAt` must remain
unchanged so previously observed messages are not reprocessed.
**Message List Ordering**
(packages/core/src/agent/message-list/message-list.ts)
- `MessageList.updateLastCreatedAt` now advances the ordering watermark
using only message-level `createdAt`.
- Removed prior logic that inspected part-level timestamps when updating
the watermark.
- Comments updated to reflect that `lastCreatedAt` is the message-level
ordering timestamp.
**Tests** (packages/core/src/agent/message-list/tests)
- message-list-om-multistep.test.ts:
- Updated OM multi-step test to ensure promoted (memory-loaded)
assistant responses retain the original `createdAt`.
- Added a regression test asserting that a tool-part with a later
timestamp does not advance subsequent signal timestamps.
- message-list-ordering.test.ts:
- Adjusted assertions so signals are normalized using the response
(message-level) timestamp rather than a later part timestamp.
## Verification
- Focused regression tests added/updated.
- Build and check commands referenced: `pnpm build:core` (runs turbo
build --filter ./packages/core) and `pnpm --filter ./packages/core
check` (typecheck/check step used in CI).
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Mastra Code (openai/gpt-5.5) <noreply@mastra.ai>1 parent b3e9781 commit 0c72f03
5 files changed
Lines changed: 92 additions & 23 deletions
File tree
- .changeset
- packages/core/src/agent/message-list
- merge
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 6 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
89 | 93 | | |
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
93 | 97 | | |
94 | | - | |
| 98 | + | |
95 | 99 | | |
96 | 100 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
| |||
208 | 209 | | |
209 | 210 | | |
210 | 211 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | 212 | | |
215 | 213 | | |
216 | 214 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1596 | 1596 | | |
1597 | 1597 | | |
1598 | 1598 | | |
1599 | | - | |
1600 | | - | |
1601 | | - | |
1602 | | - | |
1603 | | - | |
1604 | | - | |
1605 | | - | |
1606 | | - | |
1607 | | - | |
1608 | | - | |
1609 | | - | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
1610 | 1603 | | |
1611 | 1604 | | |
1612 | 1605 | | |
| |||
1632 | 1625 | | |
1633 | 1626 | | |
1634 | 1627 | | |
1635 | | - | |
1636 | 1628 | | |
1637 | 1629 | | |
1638 | | - | |
| 1630 | + | |
1639 | 1631 | | |
1640 | 1632 | | |
1641 | 1633 | | |
| |||
Lines changed: 74 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | | - | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
| 77 | + | |
75 | 78 | | |
76 | 79 | | |
77 | 80 | | |
| |||
81 | 84 | | |
82 | 85 | | |
83 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
84 | 157 | | |
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
520 | | - | |
| 520 | + | |
| 521 | + | |
521 | 522 | | |
522 | 523 | | |
523 | 524 | | |
| |||
0 commit comments