Skip to content

fix(findings): gate the similar findings Mark as Duplicate on the cluster root - #16980

Merged
blakeaowens merged 3 commits into
devfrom
fix/similar-findings-mark-duplicate-root-gate
Nov 18, 2026
Merged

blakeaowens merged 3 commits into
devfrom
fix/similar-findings-mark-duplicate-root-gate

Conversation

@blakeaowens

@blakeaowens blakeaowens commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

The classic View Finding page builds the similar findings row actions with calculate_possible_related_actions_for_similar_finding. Its engagement deduplication check compared the similar finding with the finding on the page. Since #16921 the Mark as Duplicate route compares the similar finding with the page finding's cluster root instead (the finding the mark lands under).

On a duplicate's page, when the root and the page finding sit in different engagements and deduplication_on_engagement is on, the menu therefore:

  • offered Mark as Duplicate on a row in the page finding's engagement, which the route refuses with the engagement mismatch message;
  • hid it on a row in the root's engagement, which the route accepts.

The calculator now offers each action where its route accepts it. Mark as Duplicate is checked against the cluster root (the page finding's duplicate_finding when it is a duplicate, otherwise the page finding), as the mark route does. Set as Original keeps the page-finding check, as its route does. Reset Duplicate Status is offered on any duplicate row, since its route compares no engagements. A row shows None when no action is left, and that reason now reads in plain words.

The cluster root lookup is one cluster_root() helper in dojo/finding/deduplication.py, shared by the mark route, manual_duplicate_hides_open_finding and the calculator, and the calculator reuses is_deduplication_on_engagement_mismatch, so the menu and the routes read the same rules.

With #16963 now on dev, the mark route keeps its product check on top of cluster_root(). #16963 also offered a reset on a duplicate row in another engagement as ["None", "reset_finding_duplicate_status"], but the row template shows None alone when the first action is None, so that reset never rendered. Here the reset comes first and renders; its test expects ["reset_finding_duplicate_status"] and checks the rendered link.

Test results

New unittests/test_similar_finding_related_actions.py (8 tests) builds a duplicate whose root sits in another engagement of the same product:

  • a row in the page finding's engagement no longer offers the mark, and posting it is refused by the route;
  • a row in the root's engagement now offers the mark, and posting it lands the finding under the root;
  • a duplicate from another cluster in the root's engagement offers Reset Duplicate Status and the mark; in an engagement shared by neither, it offers only the reset, and posting it goes through;
  • the rendered View Finding page carries Set as Original only on the page-engagement row and Mark as Duplicate only on the root-engagement row;
  • controls: no engagement deduplication (both actions on both rows), the root's own page, and the root's row (None).

On dev five of them fail ('mark_finding_duplicate' unexpectedly found in [...], ['None'] != ['mark_finding_duplicate'], and the page and reset cases); with this change all eight pass. The neighbouring suites (test_mark_finding_duplicate_self_reference, test_manual_duplicate_onto_mitigated, test_permissions_audit, test_finding_view_followups, test_finding_model, test_post_handler_permissions, test_bulk_finding_authorization, test_prepare_duplicates_for_delete, test_read_only_mode) pass too: 298 tests, 0 failures. ruff check passes on the changed files.

Performance, View Finding for a duplicate with 50 similar rows split across the two engagements (a third of them duplicates of another cluster): 133 queries before and after, since the rows' relations are already prefetched. Wall time is unchanged within run-to-run noise (two interleaved rounds each: medians 362 and 449 ms on dev, 345 and 427 ms with the change).

Documentation

OS__similar_findings.md: the Mark as duplicate entry now says the mark lands under the cluster's original and, with Engagement-level deduplication, is offered only for a similar finding in that original's Engagement. The action list uses colons after each label.

🤖 Generated with Claude Code

https://claude.ai/code/session_0143hYTGieXXrTHYeTDhwri2

…ster root

The classic View Finding page offered Mark as Duplicate on a similar finding
after comparing its engagement with the finding on the page, but the mark
route compares it with the page finding's cluster root, the finding it lands
under. On a duplicate's page whose root sits in another engagement with
engagement deduplication on, the menu offered a mark the route refuses and
hid one it accepts.

The menu now checks Mark as Duplicate against the cluster root and keeps the
page-finding check for Set as Original and Reset Duplicate Status, as their
routes do. A row shows None when no action survives.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0143hYTGieXXrTHYeTDhwri2
@blakeaowens

Copy link
Copy Markdown
Contributor Author

Adversarial review: changes required

Tier: full (backend change to which write actions the classic View Finding page offers), confirmed from the diff. Model: Opus. Fresh session, no author context.

CI read, not re-run: every check green on 05cc979 (ruff, Migration Graph Check, Rest Framework Unit Tests both variants, every User Interface Tests shard, k8s, performance).

Regression test: the new file's 6 tests run against the PR head's calculator: 6 pass. The same 6 run against origin/dev's calculate_possible_related_actions_for_similar_finding (bac85f9, routes unchanged): 3 fail, for the reason the PR states (['None'] != ['mark_finding_duplicate'] twice, 'mark_finding_duplicate' unexpectedly found in [...]). The test can fail. (Run in the Pro container with a watson-free copy of dojo_testdata.json, and the mark route called directly, because the Pro middleware 403s/redirects the classic URLs; assertions unchanged.)

What I drove: the classic ViewFinding view rendered directly (Pro redirects /finding/3 to /ui/), finding 3 being a duplicate of root 2, root moved to engagement 3, engagement deduplication on. Row action URLs in the HTML: Mark as Duplicate on 234 (a standalone finding in the root's engagement) and on 23 and 24 (duplicates of another cluster in the root's engagement); no Mark on 7 (the page's engagement), which keeps Set as Original. That matches what the route accepts.

Break attempts

  1. Engagement deduplication on one side only (root's engagement only, then the page's only): the menu and the route agree in all four cells (row in page's engagement: no Mark, route refuses; row in root's engagement: Mark, route lands it under 2). Base disagreed in all four. Holds.
  2. Rendered page, not the function: see above. Holds.
  3. A sibling (duplicate of the same root) moved into the root's engagement, and other-cluster duplicates in the root's engagement: the sibling's row shows None and the other-cluster rows show Mark only, yet reset_finding_duplicate_status has no engagement check and accepts Reset on both (verified: the sibling's reset succeeded). The menu hides an action the route accepts, which the new comment says it does not. R1.
  4. Odd cluster data (root itself a duplicate; orphan duplicate with no duplicate_finding): the menu offers Mark and Set as Original, the route refuses the Mark ("Finding 2 is itself a duplicate..."). Identical on base, so pre-existing. R6.
  5. Query count: 50 prefetched similar rows split across the two engagements: 5 queries on head vs 3 on base, constant in the row count (the root's test and engagement, once). No N+1. Holds.
  6. The tests themselves: they fail on base (above). They assert on the calculator's return value and the route; nothing asserts the rendered row. R3.

No screenshot pair: the classic page is not reachable in a Pro stack, so the check was on rendered HTML, listed above.

Findings

  • R1 suggestion this-pr dojo/finding/ui/views.py:3459: Reset Duplicate Status is blocked whenever the row is in another engagement than the page finding, but reset_finding_duplicate_status (views.py:3204) compares no engagements at all. The new comment at :3451 and the PR body say the gate matches "what those routes compare"; for Reset it does not, and :3483 still says "reset duplicate status is always possible". Drop reset_finding_duplicate_status from blocked (so a duplicate row always offers it, as the route allows), and flip test_hides_reset_on_a_duplicate_row_outside_the_page_engagement (unittests/test_similar_finding_related_actions.py:92) to expect ["reset_finding_duplicate_status", "mark_finding_duplicate"]. If hiding it is a deliberate menu policy, say so in the comment and PR body instead of claiming route parity.
  • R2 suggestion this-pr dojo/finding/ui/views.py:3435: _engagement_deduplication_separates re-implements is_deduplication_on_engagement_mismatch (dojo/finding/deduplication.py:244), and :3454 is a third inline copy of the cluster-root resolution (the route at views.py:3110, manual_duplicate_hides_open_finding at deduplication.py:232). The bug being fixed was exactly the menu and route drifting apart: reuse the existing mismatch helper and extract one cluster_root(finding) in deduplication.py that the route, the helper and the calculator all call.
  • R3 suggestion this-pr unittests/test_similar_finding_related_actions.py:64: the regression is in what the View Finding page offers, but no test renders it. Add one test that GETs the page (OSS has no redirect) and asserts the row for 7 has no /finding/7/duplicate/3 link while the root-engagement row has its mark link.
  • R4 nit this-pr dojo/finding/ui/views.py:3448: the moved reason string, now shown in more cases, still reads "deduplication_inside_engagment" (typo, and a field name a user never sees). Plain words, e.g. "This finding is in a different engagement, and deduplication on engagement is enabled for one of them."
  • R5 nit this-pr docs/content/triage_findings/finding_deduplication/OS__similar_findings.md:63: the rewritten line keeps an en dash after the label; use a colon (and the same on the two sibling bullets so the list stays consistent).
  • R6 nit pre-existing dojo/finding/ui/views.py:3513: the menu offers Mark as Duplicate when the page's root is itself a duplicate, or the page is an orphan duplicate, and the route refuses it; reproduces on dev bac85f9. Issue: DefectDojo-Inc/dojo-pro#8184

Recommendation

Changes required: 5 this-pr findings open (0 blockers, 3 suggestions, 2 nits); R6 goes to its issue.

Checked only statically or not at all: the OSS-only classic page in a browser (rendered the view's HTML instead); a production-sized cluster (the extra cost is two queries per page, independent of row count).

…pts it

Review follow-up. Reset Duplicate Status is offered on any duplicate row
again, since its route compares no engagements. The cluster root lookup is one
cluster_root() helper shared by the mark route, the mitigated-original check
and the menu, and the menu reuses is_deduplication_on_engagement_mismatch, so
the menu and the routes cannot drift apart again. The engagement mismatch
reason reads in plain words, the docs list uses colons, and a test renders the
View Finding page and checks the row links.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0143hYTGieXXrTHYeTDhwri2
@blakeaowens

Copy link
Copy Markdown
Contributor Author

Resolution of the review verdict:

  • R1 fixed in 04016f6: Reset Duplicate Status is no longer hidden by the engagement check, since its route compares none; a duplicate row always offers it. test_offers_reset_on_a_duplicate_row_outside_the_page_engagement now expects ["reset_finding_duplicate_status", "mark_finding_duplicate"], and test_offers_only_reset_on_a_duplicate_row_outside_both_engagements covers a row neither the page finding nor the root shares (only the reset, and posting it goes through). The code comment says each action is offered where its route accepts it.
  • R2 fixed in 04016f6: one cluster_root() in dojo/finding/deduplication.py is now called by mark_finding_duplicate, manual_duplicate_hides_open_finding and the calculator, and the calculator uses is_deduplication_on_engagement_mismatch in place of its own copy.
  • R3 fixed in 04016f6: test_the_view_finding_page_offers_the_mark_where_the_route_accepts_it GETs /finding/3 and checks the row for 7 has its Set as Original link and no /finding/7/duplicate/3, while the root-engagement row has its mark link and no Set as Original link. It fails on dev.
  • R4 fixed in 04016f6: the reason reads "This finding is in a different engagement, and deduplication on engagement is enabled for one of them."
  • R5 fixed in 04016f6: the three action bullets in OS__similar_findings.md use a colon after the label.
  • R6 pre-existing: tracked in a separate issue.

Verification: the new file has 8 tests; 5 fail on dev and 2 on 05cc979, and all 8 pass on 04016f6. With the neighbouring suites, 289 tests ran with 0 failures. View Finding stays at 133 queries with 50 similar rows (a third of them duplicates of another cluster), with wall time unchanged within noise. ruff check passes.

@blakeaowens
blakeaowens added this pull request to the merge queue Nov 18, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 18, 2026
#16963 added a product check to the mark route and a reset on duplicate rows
in another engagement to the menu. The route keeps its product check on top of
cluster_root(). The menu keeps this branch's version, which already offers the
reset on any duplicate row; it returns the reset first, so the row renders it
(the row template shows None alone when the first action is None, so the
["None", "reset"] list on dev never rendered the reset). The #16963 test now
expects ["reset_finding_duplicate_status"] and checks the rendered link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0143hYTGieXXrTHYeTDhwri2
@blakeaowens
blakeaowens added this pull request to the merge queue Nov 18, 2026
Merged via the queue into dev with commit b90971b Nov 18, 2026
50 checks passed
@blakeaowens
blakeaowens deleted the fix/similar-findings-mark-duplicate-root-gate branch November 18, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants