fix(session): order messages across ID rollover - #40432
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
The following comment was made by an LLM, it may be inaccurate: Based on my search results, no duplicate PRs were found that are addressing the same issue as PR #40432. While there are some related PRs about session message ordering (like #38798 "order messages by time so the run loop can terminate" and #40099 "finish prompt loop by parent link"), none appear to be duplicates of this specific PR which focuses on fixing the ID rollover issue with 48-bit timestamp boundaries. No duplicate PRs found |
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
Summary
Why
Ascending IDs encode
Date.now() * 0x1000 + counterinto six bytes. The timestamp prefix wraps every2^36ms. At the next boundary, 2026-08-14T11:19:55.136Z, a newer ID sorts lexically before an older ID. Long-lived sessions can therefore select the wrong latest user/assistant and fail the loop-exit check.Verification
bun test test/session/message-v2.test.ts test/session/messages-pagination.test.ts(89 pass)bun run typecheck