[P0] Fix moderation infinite re-review loop #27
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
Problem
processPending()inartifacts/api-server/src/lib/moderation.tsruns every 30 seconds and queries all events withstatus = 'pending'. WhenautoReview()flags an event it setsreviewedByandreviewReasonbut leavesstatusas'pending'. This means every flagged event gets picked up and re-sent to Claude Haiku on every poll cycle — an infinite loop that burns real AI tokens.A stuck event (e.g. an XSS test payload that Claude reliably flags) will generate a new Haiku call every 30 seconds indefinitely.
Root cause (line 179–188 of moderation.ts)
Fix
Add a
'flagged'status value to the schema enum. After AI flags an event, transitionstatus → 'flagged'soprocessPending()'sWHERE status = 'pending'filter naturally excludes it. Admins then reviewstatus = 'flagged'events via the relay admin panel.Acceptance criteria
processPending()pollsstatus = 'flagged'eventsapproved/auto_approved/rejectedflows are unchanged'flagged'to the status enumPR #71 created.
Added
flaggedstatus to the schema enum. WhenautoReview()flags an event, status now transitions frompending→flagged, soprocessPending()naturally skips it on the next poll cycle. Also addedflaggedcount to admin stats and a DB migration with an index onstatus.4 files changed, 14 additions, 4 deletions.