Commit 1783672
authored
Preserve input weight ordering when no weighers are configured (#918)
filterWeigherPipeline.Run always applied math.Tanh to the
requester-supplied input weights via normalizeInputWeights. With high
Nova-style values (e.g. 50, 55, 60) the tanh output saturates to ~1.0
within machine epsilon for every input — already at tanh(20) the result
is indistinguishable from 1.0 in float64. When the pipeline has no
weighers configured, those saturated values flowed straight into
sortHostsByWeights, whose comparator is not stable under ties, so Go's
sort.Slice returned an order driven by randomized map iteration and the
requester's original host ordering was lost.
The fix gates normalizeInputWeights on len(p.weighers) > 0 inside Run.
When weighers are configured the behavior is unchanged: input weights
are tanh-normalized so they live on a comparable scale with the (also
tanh-bounded) weigher contributions. When no weighers are configured
there is nothing on the other side of the scale to combine with, so we
clone the raw request weights and keep the original ordering intact.
Filters do not contribute weights — they only remove hosts — so they are
deliberately not part of the condition.
Covered by TestPipeline_Run_NoWeighers_PreservesInputOrdering, which
runs the empty pipeline 50 times against weights {host1: 50, host2: 55,
host3: 60} and asserts the descending order [host3, host2, host1] holds
every iteration; without the fix this test fails intermittently due to
map iteration order.
Assisted-by: Claude Code:claude-opus-4-5 [Bash] [Read]1 parent 41096b8 commit 1783672
2 files changed
Lines changed: 45 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
277 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
278 | 287 | | |
279 | 288 | | |
280 | 289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
91 | 126 | | |
92 | 127 | | |
93 | 128 | | |
| |||
0 commit comments