Skip to content

fix(reviewer): GC orphaned PR-review state files (state/pr_reviews) - #285

Merged
ProtocolWarden merged 1 commit into
mainfrom
fix/prune-orphan-review-state
Jun 14, 2026
Merged

fix(reviewer): GC orphaned PR-review state files (state/pr_reviews)#285
ProtocolWarden merged 1 commit into
mainfrom
fix/prune-orphan-review-state

Conversation

@ProtocolWarden

Copy link
Copy Markdown
Owner

What

state/pr_reviews/<repo>-<n>.json is unlinked by _merge_and_done / _close_and_requeue — but only when this watcher is the one that terminates the PR. PRs merged or closed by any other means (a manual gh pr merge, another host, or while the watcher was down/stale) leave their state file behind, forever.

Observed live: 73 state files, ~41 for already-merged/closed OperationsCenter PRs going back to May — only 1 was for an open PR.

Fix

_prune_orphan_state_files, called from _poll_once right after a successful list_open_prs: any state file for that repo whose PR number isn't in the open set is for a terminated PR and gets deleted.

Safety:

  • The successful fetch is the guard — on a list_open_prs exception the loop already continues before the sweep.
  • A false prune (PR open but missing from a partial fetch) is self-healing: the next poll re-discovers the PR and re-creates its state.
  • Other repos' files and non-numeric filenames are left untouched.

Tests

+2: mixed open/terminal/other-repo/non-numeric files → only this repo's terminal numeric files pruned; empty open set (all merged) → all of that repo's files pruned. Full reviewer suite passes (97); audit clean; ruff clean.

This is the third "should self-clean but doesn't" fix in the series (after #283 campaign-projection GC and the filed .console log GC a4dd5274).

🤖 Generated with Claude Code

state/pr_reviews/<repo>-<n>.json is unlinked by _merge_and_done and
_close_and_requeue — but only when THIS watcher is the one that terminates the PR.
PRs merged or closed by any other means (a manual `gh pr merge`, another host, or
while the watcher was down/stale) leave their state file behind, and they
accumulate indefinitely (observed: 73 files, ~41 for already-merged/closed
OperationsCenter PRs going back to May).

Add _prune_orphan_state_files, called from _poll_once right after a SUCCESSFUL
list_open_prs: any state file for that repo whose PR number is not in the open set
is for a terminated PR and is deleted. The fetch having succeeded is the guard —
on a list_open_prs exception the loop already `continue`s before the sweep. A
false prune (PR open but missing from a partial fetch) is self-healing: the next
poll re-discovers the PR and re-creates its state. Other repos' files and
non-numeric filenames are left untouched.

+2 tests: mixed open/terminal/other-repo/non-numeric files → only this repo's
terminal numeric files pruned; empty open set → all of that repo's files pruned.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ProtocolWarden
ProtocolWarden merged commit c5ec468 into main Jun 14, 2026
14 of 17 checks passed
@ProtocolWarden
ProtocolWarden deleted the fix/prune-orphan-review-state branch June 14, 2026 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant