Skip to content

fix(findings): offer no Mark as Duplicate under a cluster root that is itself a duplicate - #16988

Open
blakeaowens wants to merge 2 commits into
devfrom
fix/similar-findings-duplicate-root-actions
Open

blakeaowens wants to merge 2 commits into
devfrom
fix/similar-findings-duplicate-root-actions

Conversation

@blakeaowens

@blakeaowens blakeaowens commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

On the classic View Finding page, the similar findings menu offered Mark as Duplicate on rows that the mark_finding_duplicate route then refused, whenever the page finding's cluster root is itself a duplicate:

  • Chain: finding 2 (the root of finding 3) is itself a duplicate of another finding. On finding 3's page, the row for finding 7 offered Mark as Duplicate and Set as Original; posting the mark was refused with "Finding 2 is itself a duplicate, so finding 7 cannot be marked as its duplicate."
  • Orphan: finding 3 has duplicate=True and no duplicate_finding. Its rows offered the same two actions, and the mark was refused the same way.

A row that is a duplicate in another cluster offered Reset Duplicate Status and Mark as Duplicate under such a root, with the same refusal.

calculate_possible_related_actions_for_similar_finding now adds mark_finding_duplicate to its blocked set (introduced in #16980) when the page finding's cluster root is itself a duplicate, as the route refuses it there. Set as Original stays offered: its route accepts it under such a root and leaves the cluster one level deep (a test posts it to confirm). Reset Duplicate Status stays offered as before.

Test results

New tests in unittests/test_mark_finding_duplicate_self_reference.py, each checking the menu and then posting the route:

  • chain and orphan, plain row: the menu offers ["set_finding_as_original"], and the posted mark is refused;
  • chain and orphan, a row that is a duplicate in another cluster: the menu offers ["reset_finding_duplicate_status"], and the posted mark is refused;
  • Set as Original posted under a chained root is accepted, and the old root and its members end up under the new original;
  • the rendered View Finding page under a chained root carries the row's Set as Original link and no Mark as Duplicate link;
  • Set as Original posted under an orphaned page finding is accepted;
  • the cluster root's own row keeps its "root of the cluster" reason when the page finding sits in another engagement with deduplication on engagement, with and without a chained root;
  • control: under an ordinary root the menu keeps both actions and the route accepts the mark.

The mark route's refusal for this case now names the remedies the UI offers (Set as Original on the similar finding, or unchecking Duplicate on the original's Edit Finding page) instead of Reset Duplicate Status, which is never offered on such a root's row. Unchecking Duplicate there was measured: the root ends with duplicate=False, duplicate_finding=None, and keeps its members.

On dev five of them fail (['mark_finding_duplicate', 'set_finding_as_original'] != ['set_finding_as_original'], ['reset_finding_duplicate_status', 'mark_finding_duplicate'] != ['reset_finding_duplicate_status'], and '/finding/7/duplicate/3' unexpectedly found on the page); with this change all pass.

test_mark_finding_duplicate_self_reference and test_similar_finding_related_actions together: 40 tests, all pass with the change; on dev the five menu and page tests fail. Neighbouring suites (test_bulk_finding_authorization, test_finding_model, test_finding_view_followups, test_manual_duplicate_onto_mitigated, test_permissions_audit, test_post_handler_permissions, test_prepare_duplicates_for_delete, test_read_only_mode) plus both modules: 308 tests at the current head. On dev 16 failed (305 tests at the time); with this change 11 fail; the 11 left are file upload and image token tests that fail identically on dev because the media directory was not writable in the test container (PermissionError: [Errno 13] Permission denied: '/media/uploaded_files'). ruff check (0.16.10) passes on the changed files.

Performance, View Finding for a duplicate under a chained root with 50 extra similar findings, two interleaved rounds each: 134 queries before and after (the check reads the root the function already loads). Wall time medians 452 and 439 ms on dev, 421 and 412 ms with the change, within run-to-run noise. The rendered page drops from 12 Mark as Duplicate links to 0 and keeps all 19 Set as Original links.

Documentation

OS__similar_findings.md: the Mark as duplicate entry now says it is not offered while the cluster's original is itself marked as a duplicate, and names the remedies: Set as original on the similar Finding, or unchecking Duplicate on that original's Edit Finding page.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GLL1WcuDZt6EY4UraiB5hr

…s itself a duplicate

The similar findings menu on the classic View Finding page offered Mark as
Duplicate when the page finding's cluster root is itself a duplicate (a chain,
or an orphan whose original is gone), and the mark route refused it. The menu
now blocks the mark wherever the route refuses it: a root that is a duplicate,
and the page finding or its root as the row. Set as Original and Reset
Duplicate Status stay offered, since their routes accept them.

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

Copy link
Copy Markdown
Contributor Author

Adversarial review (full tier): no blockers; R1 and R2 to fix before merge

Reviewed at 0288996155. I did not write this change and got no summary from the author.

CI: all 49 checks pass (Rest Framework unit tests on both matrices, UI, k8s, performance, ruff). Not re-run.

Fails without the fix: the new tests and test_similar_finding_related_actions (37 tests) with the base views.py from dev at e12fd1f3da: 5 fail, the same five the description names (['mark_finding_duplicate', 'set_finding_as_original'] != ['set_finding_as_original'], ['reset_finding_duplicate_status', 'mark_finding_duplicate'] != [...], and the rendered-page assertion). At the PR head all 37 pass. I ran them under plain OSS settings, on Postgres.

Pro consumer: the Pro similar-findings suites that call this function (50 tests) pass with this head mounted.

Break attempts (realistic cluster data from dojo_testdata.json, posting to the real routes)

  1. The page finding is the chained root itself (2 is a duplicate of another finding, viewed on 2's page). The menu and the route agree: the mark lands under the outer original, or both refuse under engagement deduplication. Held.
  2. Mitigated root. The menu still offers Mark as Duplicate and the route refuses it ("Finding 2 is mitigated..."). The same thing happens on dev, so it is pre-existing (R3).
  3. Row that is a duplicate in the root's own outer cluster (both 2 and 7 point at X). The menu offers only Reset Duplicate Status, and the posted reset is accepted. The row for X shows None. Held.
  4. Orphaned root with members (2 has duplicate=True, no original, and 3 to 6 still point at it). On 3's page, row 7 offers only Set as Original. Posting it is accepted and leaves 2 to 6 one level under 7. Held.
  5. Can the remedy the new docs line names actually be reached? No, see R1. I rendered every page in the cluster and the outer original's page, for both the chain and the orphan, at head and on dev.

I also checked the Pro Vue similar-findings path, which reuses this function. It still offers the mark under a chained root in one engagement case (R4).

Findings

  • R1 (suggestion, this-pr): the docs line points to an action the UI never offers for this case. The new sentence in OS__similar_findings.md says "use Reset duplicate status on that original first". A chained root always has members, because the page finding is one of them. So everywhere it shows up as a row, it hits the similar_finding.original_finding.all() branch: "None: already an original in a different cluster". That includes the duplicate cluster on its own original's page. An orphan never gets a Reset row anywhere. I confirmed both by rendering the pages, at head and on dev. Two routes actually work. In the menu, Set as original on another row (which this PR keeps). Outside it, unchecking Duplicate on the original's Edit Finding page. Reword the docs line to name those. The route refusal text from fix(findings): gate the similar findings Mark as Duplicate on the cluster root #16980 ("Use Reset Duplicate Status on finding N first") has the same problem and could be reworded in the same pass.
  • R2 (nit, this-pr): root.id in the new clause changes the root row's tooltip. similar_finding.id in {finding.id, root.id} can only matter for the page finding (whose own row include is commented out in view_finding.html) and for the root row. The root row is already answered by the first branch ("This finding is the root of the cluster..."). Now take a page finding whose root is in another engagement, with deduplication on engagement. set_finding_as_original is blocked by page_separated, and the new clause blocks mark_finding_duplicate. The root row then takes the early len(blocked) == 2 return and shows the engagement-mismatch reason instead of the root-of-cluster reason. I confirmed this with the fixture, moving 3 to test 4 with deduplication on for engagements 1 and 4: head gives "This finding is in a different engagement...", dev gives "This finding is the root of the cluster...". That row renders first in the Duplicate Cluster table. None of the new tests exercises this part of the clause. Drop the id check (the branches below already handle both rows), or keep it and add a test that pins the root row's reason.
  • R3 (suggestion, pre-existing): the menu offers Mark as Duplicate under a mitigated root that the route refuses. This is the same menu/route mismatch this PR closes, for another refusal. It reproduces on dev. Filed as Similar Findings menu offers Mark as Duplicate under a mitigated cluster root that the route refuses #16990, assigned to the author.
  • R4 (suggestion, pre-existing, Pro consumer): the Pro Vue similar-findings wrapper's engagement fallback asks this function from the root's point of view and keeps its mark. Under a chained root it therefore still offers Mark as Duplicate, which the Pro route refuses. This happens when the page finding sits in another engagement with deduplication on. Not caused by this PR, which cannot reach that code. It is tracked as an issue in the Pro repo, assigned to the author.

Verdict: correct for the cases it targets, with no regressions found in OSS or the Pro consumer. Fix R1 and R2 before merge. R3 and R4 are tracked separately.

… itself a duplicate

Drop the page-finding and root id check from the Mark as Duplicate block: the
branches below already answer both rows, and the check made the root row show
the engagement reason instead of the root-of-cluster reason when the page
finding sits in another engagement. A test pins the root row's reason.

The docs and the mark route's refusal now point at what the UI offers in this
case: Set as Original on the similar finding, or unchecking Duplicate on the
original's Edit Finding page. Reset Duplicate Status is never offered on such
a root's row.

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

Copy link
Copy Markdown
Contributor Author

Review resolution, answering the verdict at #16988 (comment)

  • R1 fixed in b555f86: the docs line no longer points at Reset duplicate status. It names the remedies the UI offers when the cluster's original is itself a duplicate: Set as original on the similar Finding, or unchecking Duplicate on that original's Edit Finding page. The mark route's refusal for this case now names the same two. Both were measured: Set as Original is accepted under a chained root and under an orphaned page finding (tests for each), and posting the original's Edit Finding form with Duplicate unchecked leaves it at duplicate=False, duplicate_finding=None with its members kept. Unchecking does not re-run deduplication (it saves with dedupe_option=False), so the docs say nothing about that.
  • R2 fixed in b555f86: the similar_finding.id in {finding.id, root.id} clause is gone; the branches below already answer the root row and the page finding's own row. New tests pin the root row's "root of the cluster" reason when the page finding sits in another engagement with deduplication on engagement, with and without a chained root. The first fails on 0288996 with ['This finding is in a different engagement, ...'] and passes now.
  • R3 issue Similar Findings menu offers Mark as Duplicate under a mitigated cluster root that the route refuses #16990
  • R4 issue filed in the private Pro repository, assigned to the PR's author (not linked from this public PR).

Test run at b555f86, OSS settings on Postgres: test_mark_finding_duplicate_self_reference and test_similar_finding_related_actions 40 of 40 pass; with the neighbouring duplicate and finding view suites, 308 tests, the only failures are the 11 file upload and image token tests that fail identically on dev (media directory not writable in the test container). ruff check 0.16.10 passes.

This branch has not been deployed

No deployments
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.

1 participant