mirror of
https://ghfast.top/https://github.com/aeroxw/easy_tdx_max.git
synced 2026-09-12 14:34:18 +08:00
fix: 热点相关性矩阵行列顺序跨重启随机互换 — set 迭代序非确定性
board-mac/hotspot-correlation 的入阵板块来自 set 的并集, sorted(days_in, key=-days_in) 在上榜次数并列时保持 set 迭代序, 而字符串哈希随机化(PYTHONHASHSEED)使该顺序跨进程不稳定—— 服务每次重启矩阵的行/列都可能互换(全量单测中按哈希种子复现)。 排序加 code 兜底使其确定性;热点矩阵 rows_out 的多级排序同样 补 code 兜底(全并列时此前也受 set 序影响)。
This commit is contained in:
@@ -491,6 +491,7 @@ async def board_hotspot(
|
||||
-r["days_in"],
|
||||
-(r["sum_pct"] or 0.0),
|
||||
r["best_rank"] if r["best_rank"] else 9999,
|
||||
r["code"], # 全并列时按代码兜底:candidates 来自 set,迭代序跨进程不稳定
|
||||
)
|
||||
)
|
||||
rows_out = rows_out[:_HOTSPOT_MAX_ROWS]
|
||||
@@ -552,7 +553,9 @@ async def board_hotspot_correlation(
|
||||
for c in s:
|
||||
days_in[c] = days_in.get(c, 0) + 1
|
||||
|
||||
chosen = sorted(days_in, key=lambda c: -days_in[c])[:top]
|
||||
# 排序必须确定性:days_in 并列时按代码兜底——set 迭代序受哈希随机化影响,
|
||||
# 跨进程不稳定,会导致相关矩阵行列顺序在服务重启后随机互换
|
||||
chosen = sorted(days_in, key=lambda c: (-days_in[c], c))[:top]
|
||||
if len(chosen) < 2:
|
||||
return DictResponse.from_dict(
|
||||
{"status": "ready", "boards": [], "matrix": [], "days": len(window)}
|
||||
|
||||
Reference in New Issue
Block a user