Commit 8a9092b
committed
fix(reconciler): global score-descending pairing prevents false-positive feature deactivations
The reconciler's matcher was per-write greedy first-fit: every
synthesised write picked the best candidate that no earlier write had
already claimed. With realistic inputs this routinely orphaned the
candidate that would have been a clean pair for a later write while a
borderline-match earlier write got the credit, then the orphaned
candidate was swept inactive.
Concrete prod evidence (ATOAPayment, 2026-06-01 PR-3220 merge): 28
features soft-deleted in one scan; at least 10 of them had a still-active
twin with embedding cosine >= 0.85, several with identical titles --
"Cache Service" <-> "Cache Service" (0.857), "Vendor Rollout Flags" <->
"Vendor Rollout Flags" (0.845), "Upload Analytics Events" <-> "Analytics
Upload Events" (0.853), "Pricing & Merchant Plans" <-> "Merchant Pricing
& Plans" (0.876), and more.
Replace _match_strategy (per-write greedy) with _resolve_pairings (global
within-tier resolution). Tier order is preserved: signature -> Jaccard
-> containment -> cosine. Within each tier the resolver collects every
qualifying (write, candidate) edge, sorts descending by score with a
stable tiebreak on (write_index, candidate_feature_id), and claims edges
in that order. The strongest pair always wins.
Sweep behavior, candidate_filter, deactivate_filter, audit-log contract,
and the conservative absorb path are all unchanged. The change is
algorithm-local; existing callers (synthesize.py full scan,
pr_narrow_synthesis.py narrow path) need no changes and benefit equally.
Validated locally by restoring the prod ATOAPayment snapshot and
replaying the PR-3220 webhook through the backend's Redis-stream worker
on the new matcher. High-confidence false-positives (cosine >= 0.85
twin) dropped from prod's 10+ to 4 on the local replay -- a meaningful
incremental fix. The residual 4 are a cross-tier ordering pattern (a
sibling write claims via signature/Jaccard while the better cosine pair
is starved); a fuller fix would need global cross-tier optimization
(Hungarian-style) and is out of scope for this change.
Tests:
- Updated test_feature_reconciler_containment.py's 4 unit tests to use
the new _resolve_pairings entry via a _pair_one helper. Integration
test untouched.
- New test_feature_reconciler_global_pairing.py pins the regression with
6 cases: strongest-Jaccard-pair-wins regardless of input order;
cosine score-descending claims correctly; signature tier still
pre-empts lower tiers; sibling write does not block; tier order
preserved when both Jaccard and cosine qualify for the same pair;
unmatched candidate left for sweep.
All 1818 backend tests pass; ruff and mypy --strict clean across 492
source files.
Signed-off-by: Arun Rajkumar <mickyarunr@gmail.com>1 parent cae1d83 commit 8a9092b
3 files changed
Lines changed: 419 additions & 120 deletions
File tree
- backend
- app/services
- tests/services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
31 | 38 | | |
32 | 39 | | |
33 | 40 | | |
| |||
122 | 129 | | |
123 | 130 | | |
124 | 131 | | |
125 | | - | |
126 | | - | |
127 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
128 | 136 | | |
129 | 137 | | |
130 | 138 | | |
| |||
160 | 168 | | |
161 | 169 | | |
162 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
163 | 179 | | |
164 | 180 | | |
165 | 181 | | |
166 | 182 | | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 183 | + | |
177 | 184 | | |
178 | 185 | | |
179 | 186 | | |
| |||
371 | 378 | | |
372 | 379 | | |
373 | 380 | | |
374 | | - | |
375 | | - | |
376 | | - | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
377 | 384 | | |
378 | 385 | | |
379 | | - | |
380 | 386 | | |
381 | 387 | | |
382 | 388 | | |
383 | 389 | | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
403 | 408 | | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
411 | 465 | | |
412 | | - | |
| 466 | + | |
413 | 467 | | |
414 | | - | |
415 | | - | |
| 468 | + | |
| 469 | + | |
416 | 470 | | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
424 | 486 | | |
425 | | - | |
| 487 | + | |
426 | 488 | | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
| 489 | + | |
| 490 | + | |
432 | 491 | | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
441 | 502 | | |
442 | | - | |
| 503 | + | |
443 | 504 | | |
444 | 505 | | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
449 | 509 | | |
450 | | - | |
| 510 | + | |
451 | 511 | | |
452 | 512 | | |
453 | 513 | | |
| |||
Lines changed: 29 additions & 47 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
55 | 77 | | |
56 | 78 | | |
57 | 79 | | |
| |||
104 | 126 | | |
105 | 127 | | |
106 | 128 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
| 129 | + | |
116 | 130 | | |
117 | 131 | | |
118 | 132 | | |
| |||
130 | 144 | | |
131 | 145 | | |
132 | 146 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
| 147 | + | |
142 | 148 | | |
143 | 149 | | |
144 | 150 | | |
| |||
149 | 155 | | |
150 | 156 | | |
151 | 157 | | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 158 | + | |
161 | 159 | | |
162 | 160 | | |
163 | 161 | | |
| |||
170 | 168 | | |
171 | 169 | | |
172 | 170 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 171 | + | |
182 | 172 | | |
183 | 173 | | |
184 | 174 | | |
| |||
195 | 185 | | |
196 | 186 | | |
197 | 187 | | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
| 188 | + | |
207 | 189 | | |
208 | 190 | | |
209 | 191 | | |
| |||
0 commit comments