From 3b476c07dff82869b2f90a0ddce60c1e56bb3bee Mon Sep 17 00:00:00 2001 From: MidoriKurage Date: Sun, 26 Jul 2026 14:41:21 +0800 Subject: [PATCH] fix(pipeline): deterministic merge output ordering Sort mergedChunks after groupAndMergeOverlapping concatenates results from different merge units. The unit order depends on Go map iteration in the grouping phase, which is non-deterministic. Uses the same tie-breakers as filter_top_k.go to restore consistent ordering at the merge source. --- internal/application/service/chat_pipeline/merge.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/application/service/chat_pipeline/merge.go b/internal/application/service/chat_pipeline/merge.go index 82a6506d..f1529deb 100644 --- a/internal/application/service/chat_pipeline/merge.go +++ b/internal/application/service/chat_pipeline/merge.go @@ -201,6 +201,10 @@ func (p *PluginMerge) groupAndMergeOverlapping(ctx context.Context, results []*t mergedChunks = append(mergedChunks, g...) } + // Global sort restores relevance order after map-based grouping. + // n is typically < 100, O(n log n) is negligible here. + sortSearchResultsDeterministically(mergedChunks) + pipelineInfo(ctx, "Merge", "output", map[string]interface{}{ "merged_total": len(mergedChunks), })