Preventing Duplicate “Sin commits hoy” Alerts in the ClickUp Notifier
TL;DR: I added a deduplication guard to the ClickUp notifier and closed stale “Sin commits hoy” alerts per‑repo. This stops the bot from spamming ClickUp with multiple identical tasks when a repository has no commits for a day.
The Problem
Our content-automation pipeline creates a ClickUp task named “Sin commits hoy” for any repository that didn’t push a commit on the current day. After a few weeks of running the workflow, the ClickUp list started filling with dozens of identical alerts for the same repo. The symptom was obvious in the UI, but the real issue surfaced in the logs:
ERROR clickup_notifier.py:45 _create_task – Task already exists for repo xyz, creating duplicate.
The duplication wasn’t just noisy; it also exhausted our ClickUp API rate limits and made it harder to spot truly inactive repos.
What I Tried First
My first attempt was to add a simple if task_already_created: return check right before calling notify_inactive_repos. I used a global set to store repo identifiers that had already triggered an alert during the current run:
# src/clickup_notifier.py (initial attempt)
_created_repos = set()
def notify_inactive_repos(repo):
if repo.id in _created_repos:
logger.info("Alert already sent for %s", repo.name)
return
_create_task(repo)
_created_repos.add(repo.id)
The idea was straightforward, but it failed on two fronts:
- Process Isolation: Each workflow execution runs in a fresh container, so the in‑memory set never persisted across runs. The bot still emitted duplicate alerts on subsequent days.
- Race Conditions: When the pipeline processed multiple repos in parallel, two workers could read the empty set simultaneously and both create a task before either added its entry.
Both problems pointed to the need for a persistent, atomic guard that lives inside ClickUp itself.
The Implementation
1. Deduplication Inside ClickUp (_task_exists)
I rewrote the private helper _task_exists to query ClickUp for existing open tasks with the exact title “Sin commits hoy” and matching repo metadata. If such a task exists, we skip creation. The new guard lives in src/clickup_notifier.py and adds ~130 lines of logic (see diff excerpt).
# src/clickup_notifier.py
import logging
from clickup_api import ClickUpClient
logger = logging.getLogger(__name__)
class ClickUpNotifier:
def __init__(self, api_key: str, list_id: str):
self.client = ClickUpClient(api_key)
self.list_id = list_id
# NEW: guard that checks for an existing open alert
def _task_exists(self, repo_name: str) -> bool:
"""
Returns True if an open task with title
"Sin commits hoy – {repo_name}" already exists in the list.
"""
try:
tasks = self.client.get_tasks(self.list_id, status="open")
for task in tasks:
if task["name"] == f"Sin commits hoy – {repo_name}":
logger.debug("Duplicate alert found for %s", repo_name)
return True
return False
except Exception as exc:
logger.error("Failed to query ClickUp tasks: %s", exc)
# Fail‑open: assume no duplicate so we don’t silently miss an alert
return False
def notify_inactive_repos(self, repo):
"""
Creates a ClickUp task if the repo has no commits today.
"""
if self._task_exists(repo.name):
logger.info("Alert already open for %s, skipping.", repo.name)
return
task_payload = {
"name": f"Sin commits hoy – {repo.name}",
"description": f"No commits detected on {repo.branch} today.",
"status": "open",
}
self.client.create_task(self.list_id, task_payload)
logger.info("Created alert for %s", repo.name)
Key points:
- Atomicity: The check runs against ClickUp’s current state, guaranteeing that even parallel workers see the same view.
-
Idempotence: If the API call fails, we log and return
Falseto avoid blocking the alert entirely. - Performance: We only request open tasks (the default filter) to keep the response lightweight.
2. Closing Stale Alerts When Activity Returns
The original code only opened alerts; it never closed them when a repo became active again. I added logic in src/main.py to close any open “Sin commits hoy” tasks once a commit is detected.
# src/main.py (excerpt)
def main() -> None:
# ... existing loop over repos ...
for repo in repos:
if repo.has_commits_today():
# Close any open “Sin commits hoy” alerts for this repo
clickup.close_alerts_for_repo(repo.name)
continue
# Repo inactive → notify
clickup.notify_inactive_repos(repo)
The new method close_alerts_for_repo lives in ClickUpNotifier:
# src/clickup_notifier.py (new method)
def close_alerts_for_repo(self, repo_name: str) -> None:
"""
Finds and closes any open “Sin commits hoy” tasks for the given repo.
"""
try:
tasks = self.client.get_tasks(self.list_id, status="open")
for task in tasks:
if task["name"] == f"Sin commits hoy – {repo_name}":
self.client.update_task(task["id"], {"status": "closed"})
logger.info("Closed stale alert for %s", repo_name)
except Exception as exc:
logger.error("Failed to close alerts for %s: %s", repo_name, exc)
Now the pipeline behaves symmetrically: open on inactivity, close on activity.
3. Tests Updated
I expanded the test suite to cover both the deduplication guard and the closing logic. The diff in tests/test_clickup_notifier.py adds 274 lines, including mocks for the ClickUp client.
# tests/test_clickup_notifier.py (simplified)
def test_prevent_duplicate_alert(monkeypatch):
mock_client = MagicMock()
mock_client.get_tasks.return_value = [
{"id": "123", "name": "Sin commits hoy – repo-a"},
]
notifier = ClickUpNotifier(api_key="test", list_id="list123")
notifier.client = mock_client
# First call should detect duplicate and skip creation
notifier.notify_inactive_repos(MockRepo(name="repo-a"))
mock_client.create_task.assert_not_called()
def test_close_stale_alert(monkeypatch):
mock_client = MagicMock()
mock_client.get_tasks.return_value = [
{"id": "123", "name": "Sin commits hoy – repo-b"},
]
notifier = ClickUpNotifier(api_key="test", list_id="list123")
notifier.client = mock_client
notifier.close_alerts_for_repo("repo-b")
mock_client.update_task.assert_called_once_with(
"123", {"status": "closed"}
)
The tests now verify that:
- Duplicate alerts are not created.
- Stale alerts are closed correctly.
- Errors in the ClickUp API are logged without crashing the pipeline.
Key Takeaway
Persisted, source‑of‑truth checks (in this case, querying ClickUp) are essential for idempotent automation. Relying on in‑memory flags works only within a single process; once you scale to distributed workers or scheduled runs, you need a shared state that all instances can query atomically.
What's Next
- Rate‑limit back‑off: Wrap ClickUp calls with exponential back‑off to handle occasional 429 responses gracefully.
-
Batch closure: When many repos become active at once, batch the
update_taskcalls to reduce API overhead. - Alert enrichment: Add a link to the repo’s latest commit SHA in the task description for quicker triage
Part of my Build in Public series — sharing the real process of building SaaS projects from Playa del Carmen, México.
Repo: zaerohell/content-automation · 2026-11-30
#playadev #buildinpublic
Top comments (1)
The honest part is the first attempt failing for exactly the reasons in-memory flags always fail in scheduled workflows — a fresh container every run, and parallel workers reading the same empty set. One thing I'd flag: the check-then-create against ClickUp is still a race, just a narrower one. Two workers can both query, both see no open task, and both create — ClickUp has no unique constraint on task titles to save you. If duplicates still show up rarely, a single-writer step or a short lock (even a lock key with a TTL) would close it. Also, the fail-open choice on API errors is the right call — a duplicate alert is annoying, a missed one is silent — but it's a real trade-off worth naming. Which part surprised you more: the race, or that the stale alerts were never getting closed at all?