fix(session): make message ordering robust to ID wrap - #39806
Conversation
|
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. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
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