Count every duplicate group in the dedupe summary #5941
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 631 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.386
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #5941"
general
weight: 0.35
jaysbeekay
Closes #5548
Stacks on #5618, which rewrites the same group body. Its branch lives on my fork, so this PR targets
mainand, until #5618 merges, its diff also shows #5618's four commits; only 2847d6b91 belongs to this PR.Fork pre-flight: jaysbeekay/sure#1036 (pull/1036) (same branch, same commit 2847d6b91).
Problem
rake securities:deduplicateends with "Total duplicate sets: N", where N comes from the outerduplicateslocal. The ticker + MIC loop reassigns that local to each group's own duplicates (duplicates = securities[1..]), since a block shares its enclosing scope's locals, so the summary prints the duplicate count of whichever group ran last. "Found N sets" is printed before the loop and is right.Resulting behaviour
group_duplicateslocal at the assignment and every reader: the Duplicates line, the holdings, trades, prices, lots and reference counts, andSecurity::Merger.merge_group!. The outer list keeps its uses in "Found N sets", theeachand the summary.Not fixed here
Pre-existing, left for follow-ups:
dry_run = args[:dry_run].present?treats"false"as a dry run, sosecurities:deduplicate[false]changes nothing.Validation
a6f8cbcfc(#5618's head): three groups of 2, 2 and 5 securities in a dry run (invoke("true")) printedTotal duplicate sets: 1, the last group processed (pluckwithgrouphas no order), and the test expects/^ Total duplicate sets: 3$/.invoke) merges each group into its earliest security: its holding, trade and price re-point and only the others are deleted, and the summary reads 3 sets, 3 holdings, 3 trades, 3 prices.Total duplicate sets: 0, which also passes before the fix, since the loop never runs.merge_group!given the outer list; the Duplicates line reading it.ab631eaad(upstream main merged in): 19,799 runs, 0 failures, 8 errors, allReleaseNotesWorkflowTestneedingnode, which the test image lacks.<!-- This is an auto-generated description by cubic. -->
---
Summary by cubic
Rewrites both security-dedupe tasks to merge each duplicate group through
Security::Merger, and fixes the dedupe summary so "Total duplicate sets" counts every ticker + MIC group instead of echoing the last group's duplicate count.Security#move_taggings_to!is removed; its behavior is now covered in the merger tests.Closes #5548.
<sup>Written for commit ab631eaad4542531746f82c051edb18fe5d712b1. Summary will update on new commits.</sup>
<a href="https://cubic.dev/pr/we-promise/sure/pull/5941?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
Bug Fixes
Improved duplicate security cleanup by consolidating related holdings, lots, trades, prices, references, and tags into the retained security.
When duplicate securities have conflicting holdings, the most recently updated holding is retained.
Affected accounts are refreshed after merges, with repeated refreshes avoided when multiple duplicate groups affect the same account. Refreshes continue independently if one fails, including when cleanup is interrupted.
Improvements
Cleanup summaries now include counts for lots and references alongside other merged records.
* Duplicate groups are merged atomically, preventing partial changes within a group.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->