fix(pipeline): deduplicate opportunities in auto-sync - #2
Open
SabaTech-dev wants to merge 3 commits into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
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
Cleanup
Run: ./scripts/cleanup-duplicate-opportunities.sh
Dry-run first: ./scripts/cleanup-duplicate-opportunities.sh --dry-run