fix(reviewer): GC orphaned PR-review state files (state/pr_reviews) - #285
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
state/pr_reviews/<repo>-<n>.jsonis 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 manualgh 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_onceright after a successfullist_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:
list_open_prsexception the loop alreadycontinues before the sweep.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;ruffclean.This is the third "should self-clean but doesn't" fix in the series (after #283 campaign-projection GC and the filed
.consolelog GCa4dd5274).🤖 Generated with Claude Code