Skip to content

fix: restore workflow execution details order read from the database - #7229

Open
Jackkp0t wants to merge 1 commit into
1Panel-dev:v2from
Jackkp0t:fix/chat-log-execution-details-order
Open

Jackkp0t wants to merge 1 commit into
1Panel-dev:v2from
Jackkp0t:fix/chat-log-execution-details-order

Conversation

@Jackkp0t

@Jackkp0t Jackkp0t commented Oct 2, 2026

Copy link
Copy Markdown

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.details is a JSONField. On PostgreSQL this is a jsonb column, 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_record builds execution_details by iterating the dict directly, so the conversation log gets a scrambled order. The debug window is unaffected because get_chat_record prefers the in-memory ChatInfo cache, where insertion order still equals execution order.

Change

  • Sort execution_details by the per-node execution sequence: every node type already records its execution index in details[...]["index"] (all 36 get_details implementations include it). Entries without an index (auxiliary records such as problem_padding) keep their stored order at the end via a stable sort.
  • Apply the same ordering to the per-iteration dicts inside a loop node's loop_node_data, which are keyed by runtime_node_id and 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:

  • before the fix, a details dict read back in jsonb order produces a scrambled execution_details list, while the same dict in insertion order (cache path) is correct — matching the issue's screenshots;
  • after the fix, both the top-level order and the inner loop-iteration order match execution order, auxiliary entries keep their relative order at the end, and the cache path output is unchanged.

Also passing: ruff check (only pre-existing finding on line 25, untouched), ruff format clean for all added lines, python -m py_compile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 工作流工具执行详情顺序异常

1 participant