5.2 KiB
5.2 KiB
Gmail Push Notifications Revisit — Summary
Date: 2026-02-13
Status: Planned
Implementation Plan: 2026-02-13-gmail-push-revisit-implementation-plan.md
Overview
Enhance Gmail notification reliability through better deployment pattern support, improved configuration surface, actionable error messages, and comprehensive diagnostics.
Problems Addressed
- Deployment ambiguity: No clear guidance on supported patterns (push vs pull vs hybrid)
- GCP setup confusion: Topic/subscription/IAM relationships not documented
- Network constraints: Tailscale-only gateways cannot receive push webhooks
- Poor error messages: Failures lack actionable guidance
- Config gaps: No explicit disable, no pull subscription support
- Diagnostics gap: Doctor doesn't validate Pub/Sub setup
Solution
Supported Deployment Patterns
| Pattern | Config | Network | Reliability |
|---|---|---|---|
| Push only | pubsub_topic |
Public IP or Tailscale funnel | High (when reachable) |
| Pull only | pubsub_subscription_id |
Any | High |
| Hybrid ⭐ | Both | Any | Highest |
| Polling only | Neither | Any | Medium (5min latency) |
New Config Fields
automation:
gmail:
# Push notifications (watch API)
pubsub_topic: projects/<project>/topics/gmail-push
disable_push: false # Explicit disable
# Pull subscription (new)
pubsub_subscription_id: projects/<project>/subscriptions/gmail-pull
pubsub_pull_interval: "60s"
pubsub_max_messages: 10
# History API fallback
poll_interval: "300s"
Enhanced Doctor Check
$ flynn doctor
✓ Gmail configured (push + pull + poll-fallback → telegram/123456789)
⚠ Gmail configured (push + poll-fallback ⚠️ push requires public endpoint or Tailscale funnel)
✓ Gmail configured (poll → telegram/123456789)
Improved Error Messages
Before:
GmailWatcher: Watch setup failed (will use polling only) — Invalid topicName
After:
GmailWatcher: Watch setup failed (push disabled) — Invalid topicName
Tip: Set automation.gmail.pubsub_topic to "projects/your-project/topics/gmail-push"
Ensure the topic exists in GCP and the subscription is configured to POST to /gmail/push
Or set automation.gmail.pubsub_subscription_id for pull-based mode (no webhook required)
Files Modified
Core (4 files)
src/config/schema.ts— Add new fieldssrc/automation/gmail.ts— Add pull support, error hintssrc/cli/doctor.ts— Enhanced validationpackage.json— Add@google-cloud/pubsub
Docs (3 files)
README.md— Rewrite Gmail sectionconfig/default.yaml— Update examplesdocs/plans/state.json— Mark completed
Tests (2 files)
src/automation/gmail.test.ts— +7 test casessrc/cli/doctor.test.ts— +5 test cases
Implementation Checklist
- Add config schema fields (
pubsub_subscription_id,pubsub_pull_interval,pubsub_max_messages,disable_push) - Implement
setupPullSubscription()method - Implement
pullSubscriptionMessages()method - Implement
buildWatchErrorHint()method - Update
connect()to handledisable_pushand call pull setup - Update
disconnect()to clear pull timer - Enhance
checkGmaildoctor check with mode detection - Add
@google-cloud/pubsubdependency - Write unit tests for pull mode
- Write unit tests for
disable_push - Write unit tests for error hints
- Write doctor check tests
- Update README Gmail section
- Update
config/default.yamlexample - Manual integration testing (4 modes)
- Update
state.json
Test Plan
Unit Tests (12 new tests)
- Pull subscription setup (full path)
- Pull subscription setup (shorthand with project_id)
- Skip pull when not configured
- Invalid subscription path warning
disable_pushskips watch setupdisable_pushlogs message- Error hints (Invalid topicName)
- Error hints (Permission denied)
- Error hints (Not found)
- Connection logging shows modes
- Doctor: push mode detection
- Doctor: pull mode detection
- Doctor: hybrid mode detection
- Doctor: Tailscale reachability warning
Integration Tests (Manual)
- Push only deployment
- Pull only deployment
- Hybrid deployment
- Polling only deployment
- Disable push with topic set
- Doctor check output for each mode
- Error message hints for common failures
- Tailscale warning validation
Recommended Default
Hybrid mode (push + pull + polling):
- Push: ~Real-time when endpoint is reachable
- Pull: 60s latency, always works
- Poll: 300s latency, final fallback
Estimated Effort
Total: 1-2 days
- Implementation: 4-6 hours
- Testing: 2-4 hours
- Documentation: 2-3 hours
Breaking Changes
None — existing pubsub_topic-only configs continue to work.
Benefits
- ✅ Clarity: Explicit deployment patterns with setup instructions
- ✅ Flexibility: Pull mode supports private deployments (no inbound connections)
- ✅ Reliability: Hybrid mode ensures delivery across all network configs
- ✅ Debuggability: Error hints + doctor checks catch misconfigurations
- ✅ Documentation: Comprehensive README with GCP setup, troubleshooting