Conversation
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.
Fixes #7221
Problem
In the agent conversation log, the execution details of a workflow tool appear in a wrong, seemingly random order, while the debug window shows them in the correct order.
Root cause:
ChatRecord.detailsis aJSONField. On PostgreSQL this is ajsonbcolumn, and jsonb does not preserve object key order (keys are stored sorted by length, then bytewise). The details dict is written in node execution order, but every read from the database returns jsonb key order.reset_chat_recordbuildsexecution_detailsby iterating the dict directly, so the conversation log gets a scrambled order. The debug window is unaffected becauseget_chat_recordprefers the in-memoryChatInfocache, where insertion order still equals execution order.Change
execution_detailsby the per-node execution sequence: every node type already records its execution index indetails[...]["index"](all 36get_detailsimplementations include it). Entries without anindex(auxiliary records such asproblem_padding) keep their stored order at the end via a stable sort.loop_node_data, which are keyed byruntime_node_idand suffer from the same jsonb key-order loss.The in-memory (debug) path is unchanged: the sort is stable and idempotent there because index order already equals insertion order.
Verification
The repository has no runnable unit-test harness for this serializer module (no test runner in CI), so I verified the logic with a standalone red/green script that simulates the documented PostgreSQL jsonb key-order rule:
execution_detailslist, while the same dict in insertion order (cache path) is correct — matching the issue's screenshots;Also passing:
ruff check(only pre-existing finding on line 25, untouched),ruff formatclean for all added lines,python -m py_compile.