Skip to content

Relax email self-loop guard to only block comment loops#65

Merged
MathurAditya724 merged 2 commits into
mainfrom
relax-email-self-loop-guard
May 8, 2026
Merged

Relax email self-loop guard to only block comment loops#65
MathurAditya724 merged 2 commits into
mainfrom
relax-email-self-loop-guard

Conversation

@MathurAditya724
Copy link
Copy Markdown
Member

Flip the email self-loop guard from a safelist (block everything except ci_activity, security_alert) to a denylist (block only comment, your_activity).

Problem

The previous guard dropped ALL email notifications from the bot's own GitHub account except CI and security alerts. This blocked legitimate notifications like issue assignments, PR creation, state changes, and review requests — preventing the agent from acting on its own work.

What changed

packages/opentower/src/handlers/email.ts

  • Renamed SELF_LOOP_SAFE_REASONS (safelist) → SELF_LOOP_RISK_REASONS (denylist)
  • Now only blocks comment and your_activity reasons from the bot
  • All other reasons (assign, ci_activity, security_alert, state_change, review_requested, push, mention, etc.) pass through

webhooks.json

  • Removed ignore_authors: ["$BOT_LOGIN"] from the email-event trigger
  • The email.ts handler's reason-based guard is more precise than a blanket author filter
  • github-comment trigger still has ignore_authors (needed for webhook-based comment loop prevention)

Why this is safe

The only real feedback loop is: bot comments → email notification → agent responds → bot comments again. That requires x_github_reason to be comment or your_activity.

All other notification types produce a different action than what triggered them:

  • Assignment → bot works on the issue (doesn't reassign)
  • PR creation → bot reviews (doesn't create another PR)
  • CI result → bot fixes code (doesn't re-trigger same CI email)
  • Push → bot checks status (doesn't push again from the same notification)

Testing

  • bun run --filter opentower typecheck passes

Flip the email self-loop guard from a safelist to a denylist. Previously,
ALL emails from the bot were dropped except ci_activity and security_alert.
Now only 'comment' and 'your_activity' reasons are blocked — these are
the only reasons that can cause feedback loops (bot comments → email →
agent responds → bot comments again).

Assignments, PR creation, state changes, review requests, pushes, and
all other notification types are now allowed through, even when the
sender matches the bot. This is safe because responding to those
events performs a different action than what triggered the notification.

Also removes the redundant ignore_authors from the email-event trigger
in webhooks.json — the email.ts handler's reason-based guard is more
precise.
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 8, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
opencode-email-worker f0de6e0 Commit Preview URL

Branch Preview URL
May 08 2026, 02:57 AM

@MathurAditya724 MathurAditya724 marked this pull request as ready for review May 8, 2026 03:32
@MathurAditya724 MathurAditya724 merged commit 4bd1f8c into main May 8, 2026
2 checks passed
@MathurAditya724 MathurAditya724 deleted the relax-email-self-loop-guard branch May 8, 2026 03:32
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