fix: update DB when ignored events were previously persisted as queued #4
No reviewers
Labels
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
brooktrails/pr-reviewer!4
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/stuck-queued-events"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When _maybe_re_review decides to skip, it sets status to "ignored" and
calls record(). But record() routed ignored events to in-memory only,
leaving the DB row stuck as "queued" forever.
Now record() checks if an ignored event already exists in the DB and
updates it there instead. Also cleans up existing stuck rows on startup.
Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com
Automated review by pr-reviewer v0.8.0 | Full Review | anthropic | tracking id
r-bd7856-8469d6Status: ✅ Completed
Looking at this pull request, I can see it addresses a specific bug where events that were previously persisted to the database as "queued" would get stuck in that state when later marked as "ignored".
Code Review
Positive Aspects
Clear Problem Definition: The PR description clearly explains the issue - when
_maybe_re_reviewdecides to skip an event and sets status to "ignored", the database row remained stuck as "queued" while only the in-memory store was updated.Two-Part Solution: The fix appropriately handles both existing stuck events (via migration) and prevents future occurrences (via the logic change).
Migration Strategy: The migration in
MIGRATE_COLUMNSprovides a clean way to fix existing stuck rows with a descriptive error message.Issues and Concerns
Database Connection Handling (tracker.py:98-119)
There's a problematic pattern in the connection handling:
Problems:
withblocks, which is confusing and potentially error-proneconn.close()calls within try blocks bypass the finally block's cleanupconn.closedproperty might not be reliable across all database driversSuggested fix:
Missing Field in get_events() (tracker.py:381)
The
get_events()function doesn't include therequest_idfield when constructingReviewEventobjects from database rows, even though it selects it. This could cause issues if the field is accessed later.Logic Consideration
The current logic adds ignored events to
_ignored_eventseven when they're successfully updated in the database. This could lead to duplicate tracking. Consider whether ignored events that are successfully persisted to the database should still be added to the in-memory list.Minor Issues
Error Field Usage: Using
event.ignore_reason or event.erroris clever but could be confusing. Consider being more explicit about which field should be used when.Migration Message: The migration message "stuck queued event (fixed in 0.8.2)" hardcodes a version number, which might become outdated.
Security and Performance
Test Coverage
The changes would benefit from tests covering:
Summary
The core logic of the fix is sound and addresses the described problem effectively. However, there are implementation issues with database connection handling and a missing field in the
get_events()function that should be addressed before merging.Verdict: Request Changes
The connection handling pattern needs to be fixed to avoid potential resource leaks and the missing
request_idfield inget_events()should be added. These are straightforward fixes that don't affect the core solution.Automated review by pr-reviewer v0.8.0 | Full Review | anthropic | tracking id
r-bd7851-446375Status: ✅ Completed
I'll provide a detailed review of this pull request that fixes stuck "queued" events in the database.
Overall Assessment
This is a well-targeted bug fix that addresses a legitimate issue where events marked as "ignored" during re-review decisions weren't being properly updated in the database, leaving them stuck with "queued" status. The solution is conceptually sound and includes both a fix for the ongoing issue and cleanup of existing problematic data.
Issues to Address
1. Database Connection Resource Management (tracker.py:97-119)
The connection handling in the new ignored event logic has several issues:
conn.close()but then thefinallyblock on line 118 checksif not conn.closed:and closes again. This creates redundant calls.try/finallywith a single close in the finally block. This new code deviates from that pattern.with conn:blocks (lines 101 and 107) which is unnecessary and potentially confusing.Recommendation: Refactor to match the existing pattern:
2. Logic Flow Issue (tracker.py:113-119)
The early
returnon line 113 bypasses thefinallyblock, which means the connection gets closed there, but then execution continues to the in-memory storage logic (lines 121-124). This creates a subtle bug where ignored events that were updated in the database also get added to the in-memory store.Expected behavior: If an ignored event exists in DB and gets updated there, it should NOT also be added to
_ignored_events.Current behavior: Due to the early return, the in-memory storage code is unreachable for DB-updated events, which is actually correct but makes the code structure confusing.
3. Missing Field in get_events() (tracker.py:346)
The
get_events()function doesn't populate therequest_idfield when creatingReviewEventobjects from database rows, even though it selects it. Line 346 shows only 13 fields being passed to the constructor, butrequest_idis the 14th field (row[13]).Bug: This will cause
request_idto always be empty string for events loaded from the database.4. Data Migration Concerns (tracker.py:66)
The migration SQL
UPDATE review_events SET status = 'ignored', error = 'stuck queued event (fixed in 0.8.2)' WHERE status = 'queued';is aggressive - it updates ALL queued events to ignored status. This could potentially affect legitimately queued events that happen to be in the database when the migration runs.Risk: If there are any genuinely queued events during deployment, they'll be incorrectly marked as ignored.
Positive Aspects
Clear problem identification: The PR correctly identifies that
record()was routing ignored events to in-memory only storage even when they already existed in the database.Comprehensive solution: Addresses both the ongoing issue and cleans up existing problematic data.
Good error handling: Includes proper exception logging for database operations.
Maintains backward compatibility: The fix doesn't break existing functionality.
Appropriate use of database features: Uses a simple SELECT to check existence before UPDATE, which is a reasonable approach for this use case.
Minor Issues
Code readability: The nested database operations make the
record()function more complex. Consider extracting the ignored event update logic into a separate helper function.Performance consideration: The solution adds an extra database query for every ignored event. Given that ignored events are likely common, this could have a minor performance impact. However, this is probably acceptable given the correctness benefit.
Recommendations
request_idfield inget_events()Verdict: Request Changes
While this addresses a real bug and the approach is sound, the connection management issues and missing field bug should be addressed before merging.
@pr-reviewer-bot help
pr-reviewer v0.8.0 | tracking id
r-bd7938-f5ecb4I'm pr-reviewer, an automated code review bot.
Commands (use in a PR comment):
@pr-reviewer-bot review@pr-reviewer-bot carefully review@pr-reviewer-bot helpModifiers like
careful,carefully,full,fully,thorough, orthoroughlycan appear before or afterreviewto request a more thorough review.What happens automatically:
@pr-reviewer-bot full review