Skip to content

feat: Phase 1 Production Validation Infrastructure - #67

Draft
clduab11 with Copilot wants to merge 3 commits into
mainfrom
copilot/validate-smoke-testing-phase-1
Draft

feat: Phase 1 Production Validation Infrastructure#67
clduab11 with Copilot wants to merge 3 commits into
mainfrom
copilot/validate-smoke-testing-phase-1

Conversation

Copilot AI commented Jan 20, 2026

Copy link
Copy Markdown
Contributor

Implements production readiness infrastructure for the anomaly detection pipeline: connection pooling, job queue persistence, health checks, graceful shutdown, metrics export, and operational documentation.

Infrastructure

  • PostgreSQL pool: min=10, max=30 connections via DATABASE_POOL_MIN/MAX env vars
  • Redis AOF: appendonly yes, appendfsync everysec, allkeys-lru eviction
  • Docker health checks: All 7 workers + postgres + redis with proper depends_on conditions
  • Graceful shutdown: 30s timeout, in-flight job completion, SIGTERM/SIGINT handling

Monitoring

  • Enhanced metrics service with Prometheus export (/api/internal/metrics?format=prometheus)
  • Health endpoint now checks Redis connectivity
  • Sentry stub implementation ready for SDK integration

New Files

scripts/validate-env.ts          # Run: npm run validate:env
railway.toml                     # Railway deployment config
src/lib/workers/graceful-shutdown.ts
src/lib/monitoring/sentry.ts
docs/architecture/detection-algorithms.md
docs/guides/troubleshooting-workers.md

Worker Updates

  • anomaly-validator.ts: integrated graceful shutdown, Sentry, worker metrics
  • Docker Compose: added worker-newsletter, worker-telegram services

Documentation

  • Detection algorithms: all 5 methods documented with thresholds
  • Troubleshooting runbook: diagnostics, common issues, recovery procedures
  • Monitoring guide: Grafana panels, Prometheus queries, alert rules
  • Production checklist: pre-flight, deployment, go/no-go criteria

Testing

  • 8 new tests for graceful shutdown utility
  • 184 tests passing
Original prompt

This section details on the original issue you should resolve

<issue_title>task: Production Test Launch: Phase 1 Validation & Smoke Testing</issue_title>
<issue_description>## Production Test Launch: Phase 1 Validation & Smoke Testing

Epic Context

This issue implements the critical path toward PriceHawk's first production test launch, focusing on validating core detection accuracy, worker reliability, and notification delivery across the multi-channel architecture. [github](https://github.com/clduab11/pricehawk)

Objectives

  • Validate end-to-end anomaly detection pipeline with real retailer data
  • Confirm BullMQ worker stability under production-like load
  • Verify notification delivery across all 8 channels (Discord, Email, SMS, Telegram, WhatsApp, Twitter/X, Facebook, Webhooks)
  • Establish baseline KPIs for detection latency, false positive rate, and affiliate conversion tracking
  • Deploy containerized stack to Railway staging environment

Technical Scope

1. Pre-Flight Infrastructure Validation

Acceptance Criteria:

  • PostgreSQL connection pooling configured for concurrent workers (min 10, max 30 connections)
  • Redis persistence enabled with AOF for BullMQ job recovery
  • Docker Compose health checks passing for all 6 workers (anomaly-validator, notification-sender, deal-verifier, social-poster, newsletter-digest, telegram-bot)
  • Railway deployment smoke test: verify app + worker containers start successfully
  • Environment variable validation: all required API keys present in .env (OpenRouter, Clerk, Stripe, Twilio, Resend, Telegram)

2. Detection Algorithm Calibration

Acceptance Criteria:

  • Test all 5 anomaly detection methods (Decimal Error, Z-Score, Double MAD, Adjusted IQR, Category Thresholds) against historical pricing dataset
  • Validate category-specific sensitivity tuning:
    • Grocery: 30% threshold
    • Electronics/Computers: 40%
    • Fashion: 60%
    • Home/Toys: 50-55%
  • Measure false positive rate < 15% on test corpus of 100 "normal sale" prices
  • Confirm DeepSeek V3 AI validation reduces false positives by ≥50% in secondary filtering
  • Document detection latency: target <30 seconds from price scrape to anomaly flag

3. Scraping Reliability & Rate Limiting

Acceptance Criteria:

  • Playwright scraper handles JavaScript-heavy sites (Amazon, Best Buy, Walmart) without timeouts
  • Jina Reader API fallback triggers correctly when Playwright fails (timeout >15s or 403 response)
  • Implement exponential backoff for rate-limited endpoints (max 3 retries, base delay 2s)
  • Verify scraper respects robots.txt and avoids triggering bot detection (User-Agent rotation enabled)
  • Test concurrent scraping: 20 products across 5 retailers simultaneously without failures

4. Worker Queue Stability

Acceptance Criteria:

  • BullMQ workers process jobs in FIFO order with <5% queue backlog during peak load
  • Dead letter queue (DLQ) configured for failed jobs after 3 retry attempts
  • Monitor job completion times:
    • Anomaly Validator: <10s median
    • Deal Verifier: <15s median
    • Notification Sender: <5s median
  • Confirm workers auto-scale: test with 50 simultaneous anomalies, verify no job starvation
  • Implement graceful shutdown: workers finish in-flight jobs before terminating (max 30s timeout)

5. Notification Channel Integration Tests

Acceptance Criteria:

  • Discord webhook delivers rich embeds with price charts, affiliate links, and expiration countdown
  • Email via Resend renders HTML template correctly (test in Gmail, Outlook, Apple Mail)
  • SMS via Twilio includes shortened link and retailer name (test with ≤160 characters)
  • Telegram bot /deals command returns last 5 active anomalies with inline buttons
  • WhatsApp template message approved and delivered without delays
  • Twitter/X OAuth posts deals with #PricingError hashtag and affiliate link
  • Facebook Graph API posts to designated page with image attachment
  • Webhook endpoint accepts JSON payload and returns 200 status within 3s

6. Affiliate Monetization Validation

Acceptance Criteria:

  • Amazon affiliate tags correctly injected into product URLs (format: tag=pricehawk-20)
  • Verify click tracking via Stripe Payment Links for subscription tiers (Free, Pro, Elite)
  • Test affiliate link expiration: confirm 24-hour validity window enforced
  • Implement revenue attribution: associate affiliate clicks with user IDs for commission tracking
  • Document conversion funnel: anomaly detected → notification sent → link clicked → purchase attributed

7. Deal Lifecycle & Expiration Logic

Acceptance Criteria:

  • Deal Verifier worker re-scrapes active deals every 30 minutes
  • Auto-expire deals when price returns to within 10% of historical average
  • Send "Deal Expired" notifications to users who subscribed to sp...

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 20, 2026 20:12
- Configure PostgreSQL connection pooling (min: 10, max: 30)
- Enable Redis AOF persistence in docker-compose
- Add Docker health checks for all 7 workers
- Add graceful shutdown handling with 30s timeout
- Create environment validation script (npm run validate:env)
- Create Railway deployment configuration
- Enhance metrics service for Prometheus/Grafana export
- Add Sentry integration module for error tracking
- Create detection algorithms documentation
- Create worker troubleshooting runbook
- Update monitoring guide with Grafana dashboards
- Add production deployment checklist to core-flow-prod.md
- Update package.json with new worker scripts

Co-authored-by: clduab11 <185000089+clduab11@users.noreply.github.com>
- Change Redis eviction policy to allkeys-lru for job queue reliability
- Import alertService statically instead of dynamic import
- Clarify Sentry stub implementation in documentation
- Use void keyword for fire-and-forget shutdown call in tests

Co-authored-by: clduab11 <185000089+clduab11@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement validation and smoke testing for production launch feat: Phase 1 Production Validation Infrastructure Jan 20, 2026
Copilot AI requested a review from clduab11 January 20, 2026 20:22
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.

task: Production Test Launch: Phase 1 Validation & Smoke Testing

2 participants