Skip to content

monitor: a closed finding is reopened when its only occurrences predate the close (364 false reopens on one run) #3615

Backlog

Description

@clabonte

Summary

record_finding reopens a closed finding whenever its fingerprint appears in the harvested rows. It never checks whether any of those occurrences happened after the issue was closed. On a run that harvests a window reaching back before the close, every finding closed in the meantime is reopened, even though nothing recurred. The reopen comment then reports last seen <run time>, which reads as a fresh occurrence.

What happened

specfuse-loop 0.33.0, specfuse monitor run against RestoManagerApp/Backend (production environment). The monitor had not run since about 2026-11-17. Its first run was at 2026-11-26 14:09Z.

  • The run reopened 378 closed monitoring-finding issues.
  • For 364 of them, the issue's own regenerated body shows the latest occurrence (**Seen this run:** N, first X, last Y) before the issue's last closed event:
    • 335 had been closed on 2026-11-17.
    • 29 had been closed earlier on 2026-11-26, a few hours before the run.
  • Example: Backend#1344. Body after the run: Seen this run: 8, first 2026-11-06T23:47:04Z, last 2026-11-06T23:47:09Z. Closed 2026-11-26T14:10:35Z, reopened 2026-11-26T14:24:46Z with Recurred after close: occurrence 3, first seen 2026-11-06T23:47:04Z, last seen 2026-11-26T14:09:21Z. The "last seen" is the run timestamp, and the real last occurrence is 19 days before the close.
  • Only 14 of the 378 were genuine recurrences, with an occurrence after the close.
  • The open finding count went from 72 to 405 in one run, and all 364 had to be closed again by hand.

Where

specfuse/monitor/issues.py, record_finding, the state == "CLOSED" branch (0.33.0):

if str(existing.get("state", "OPEN")).upper() == "CLOSED":
    if ids and not unseen:
        return number
    occurrences = meta.occurrences + 1 if meta is not None else 1
    runner(["gh", "issue", "reopen", number, "--repo", repo], check=True)
    ... f"Recurred after close: occurrence {occurrences}, "
        f"first seen {_iso(first_seen)}, last seen {_iso(now)}."
  • Except for dlq message ids, nothing compares the occurrences in seen with the issue's closedAt. find_finding_issue already fetches closedAt, but only to apply the 90-day lookup window.
  • last_seen=now is written both into the comment and into the finding-meta marker, so the run time stands in for the latest occurrence.

Expected

A closed finding is reopened only when at least one harvested occurrence is later than the issue's closedAt. Otherwise it stays closed with no gh write, as a fully covered dlq issue already does.

Suggested fix

  1. In the closed branch, compute the latest occurrence from seen (for example _seen_epoch(seen.last)). Compare it with the matched issue's closedAt from the same gh issue list row, and return without writing when the occurrence is not later. When seen carries no timestamps, keep today's behaviour.
  2. Write the latest occurrence, not now, into the comment's "last seen" and into finding-meta last_seen, keeping the harvest time out of it.
  3. Add a regression test: a closed issue whose fingerprint shows up only in rows older than closedAt stays closed with zero gh calls, and the same fingerprint with one row newer than closedAt reopens it.

Contributing factor

The run harvested rows from 2026-11-06 although the previous run was around 11-17. The window question is separate, but it is what turned a latent bug into a mass reopen. Any run after a gap, or after a watermark is lost, will do the same.

🤖 Generated with Claude Code

Activity

  1. added
    bug
    on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions