feat(web): sort session messages by time-ordered ID in admin traces - #5029
Merged
eshurakov merged 1 commit intoAug 5, 2026
Merged
Conversation
Implement message and part re-ordering in the admin session traces router to ensure the display order matches the cloud-agent-next UI. This fixes issues where messages ingested out of order (e.g., assistant turns arriving before user prompts) would appear incorrectly in the admin trace view. - Add `sortSessionMessagesForDisplay` utility to handle message and part ordering based on IDs. - Update `adminRouter.sessionTraces.getMessages` to use the new sorting logic. - Add unit tests for message ordering logic and integration tests for the admin router. Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryReviewed the admin session-trace message ordering fix (new Files Reviewed (4 files)
Reviewed by kimi-k3 · Input: 100.4K · Output: 6.5K · Cached: 359.6K Review guidance: REVIEW.md from base branch |
pandemicsyn
approved these changes
Aug 5, 2026
eshurakov
deleted the
session/agent_f256aba5-c67b-4c97-83a4-84aa74900d05
branch
August 5, 2026 14:28
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.
Summary
The admin session trace viewer (
/admin/session-traces) rendered V2 session messages in the raw order returned by the session-ingest worker's/api/session/:id/exportendpoint. That endpoint streams messages and parts in ingest order (ORDER BY ingested_at, id), which diverges from conversation order when a session is re-ingested (e.g., assistant turns ingested before their user prompt) — producing traces where agent replies appear before the user message they answer.The cloud-agent-next UI avoids this by hydrating messages into SDK storage via
insertSorted/insertPartSorted— binary insertion by message/part ID. Since IDs are time-ordered (msg_/part_+ big-endian hex timestamp + random suffix), lexicographic ascending order equals chronological order.This PR applies the same ordering in the admin path:
sortSessionMessagesForDisplay(apps/web/src/lib/cloud-agent-next/message-ordering.ts) — sorts messages byinfo.idand parts bypart.id, mirroring the SDK's storage ordering; non-mutating.admin.sessionTraces.getMessages(V2 branch) returns the snapshot through the helper, so both the viewer and the "Download JSON" payload match the cloud-agent-next display order.