Skip to content

fix(pipeline): deduplicate opportunities in auto-sync - #2

Open
SabaTech-dev wants to merge 3 commits into
mainfrom
fix/pipeline-dedup-opportunities
Open

fix(pipeline): deduplicate opportunities in auto-sync#2
SabaTech-dev wants to merge 3 commits into
mainfrom
fix/pipeline-dedup-opportunities

Conversation

@SabaTech-dev

Copy link
Copy Markdown
Owner

What

  • Fix auto-sync dedup: use findOpportunityByCompany() instead of getOpportunity(reportId)
  • Add cleanup script to remove 960 existing duplicates from kanban.db

Root Cause

auto-sync/route.ts called getOpportunity(parsed.reportId) for dedup check, but createOpportunity() generates random UUIDs as IDs. The lookup NEVER matched and created duplicates on every GET call.

Fix

  1. Replace getOpportunity(reportId) with findOpportunityByCompany(target)
  2. UPDATE with max value when match found instead of CREATE

Cleanup

Run: ./scripts/cleanup-duplicate-opportunities.sh
Dry-run first: ./scripts/cleanup-duplicate-opportunities.sh --dry-run

Joker added 3 commits June 11, 2026 00:10
Root cause: auto-sync/route.ts used getOpportunity(parsed.reportId) for
dedup, but createOpportunity generates random UUIDs, so the lookup never
matched and created duplicates on every GET /api/pipeline/auto-sync call.

Fix: use findOpportunityByCompany() for dedup (same as reports-scanner.ts).
When match found, UPDATE with max value instead of CREATE.

Also adds cleanup script to remove 960 existing duplicates from kanban.db.

Bug: 1015 total opportunities, only 55 unique companies (960 duplicates).
LawnStarter had 320 identical entries.
- Add POST /api/journal/auto-generate endpoint
  - Aggregates activities for a given date
  - Generates narrative summary with success rate, agent activity, errors
  - Builds highlights array automatically
  - Skips if entry already exists for date
- Add 'Auto-Generar Hoy' button to Journal UI with Sparkles icon
- Implements deferred roadmap item 14.7 sub-task
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