fix(session): make message ordering robust to ID wrap - #39806
Open
quanzhuo wants to merge 1 commit into
Open
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: I found two related PRs that address similar session and message ordering issues:
Both PRs appear to be earlier attempts or related work addressing the same message ordering and session turn termination issues that PR #39806 is fixing. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Fixes #39624
Type of change
What does this PR do?
Message IDs currently encode
Date.now() * 0x1000into 6 bytes. That timestamp field wraps on2026-08-14T11:19:55.136Z, so newer message IDs can sort before older ones. Some session code uses raw ID ordering to decide the latest turn or when a response loop should stop, which can make sessions repeat responses indefinitely.This PR widens the native timestamp encoding to 8 bytes and removes the fragile ID-order dependency from session turn handling. Session ordering now uses persisted
time.createdwhere chronological ordering is needed, and the run loop uses the assistantparentIDrelationship to identify whether it already replied to the latest user message.It also keeps old 6-byte ID timestamp decoding for compatibility and adds regression tests for the wrap boundary and mixed/client-supplied message IDs.
How did you verify your code works?
From
packages/opencode:bun test test/session/id.test.ts test/session/message-v2.test.ts test/session/prompt.test.ts test/tool/truncation.test.ts --timeout 30000 --only-failuresResult: 102 pass, 14 skip, 0 fail
Result: passed
Also ran git diff --check; it passed with only local LF/CRLF warnings on Windows.
Screenshots / recordings
N/A. This is session ordering and ID generation behavior, not a UI change.
Checklist