Skip to content

[integrations] Fix Slack Capture duplicate entries from webhook retries#104

Merged
justfinethanku merged 1 commit intoNateBJones-Projects:mainfrom
demarant:contrib/demarant/slack-capture-dedup-fix
Mar 24, 2026
Merged

[integrations] Fix Slack Capture duplicate entries from webhook retries#104
justfinethanku merged 1 commit intoNateBJones-Projects:mainfrom
demarant:contrib/demarant/slack-capture-dedup-fix

Conversation

@demarant
Copy link
Copy Markdown
Contributor

Contribution Type

  • Integration (/integrations)

What does this do?

Adds deduplication to the Slack Capture Edge Function. Slack retries webhook delivery if it doesn't get a response within 3 seconds, and the function (embedding + metadata extraction) typically takes 4-5 seconds, causing duplicate rows in the database. The fix checks if a row with the same slack_ts already exists before processing, and returns early if found. Also updates the troubleshooting section to reflect the fix.

Requirements

None new. Uses the same services as the existing Slack Capture integration:

  • Supabase (Edge Functions + database)
  • OpenRouter API (for embeddings and metadata extraction)
  • Slack workspace + app

Checklist

  • I've read CONTRIBUTING.md
  • My contribution has a README.md with prerequisites, step-by-step instructions, and expected outcome
  • My metadata.json has all required fields
  • I tested this on my own Open Brain instance
  • No credentials, API keys, or secrets are included

@papaechosierra
Copy link
Copy Markdown

I solved this on my version with an await() for the embedding+metadata call, and just immediately reply to slack with
ok:200. That fixes the no reply issue without needing to make further duplication checks.

Copy link
Copy Markdown
Collaborator

@justfinethanku justfinethanku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution, Antonio! This is a well-executed bug fix that addresses a real issue with webhook retries.

What's Good

Solid technical solution — The deduplication logic is correct: checking for existing rows with the same slack_ts before processing prevents duplicates caused by Slack's 3-second timeout retry behavior.

Proper placement — The check happens early (right after validation, before the expensive embedding/metadata calls), which is efficient and prevents wasted API calls.

Documentation updated — The troubleshooting section now accurately reflects that the issue is fixed rather than telling users to manually delete duplicates.

Clean code — Uses .contains() on the metadata JSONB column appropriately, limits to 1 row for efficiency, and returns the same 200 ok response that Slack expects.

PR format — Title follows [integrations] convention, description is clear about what was changed and why.

No new dependencies — Uses existing Supabase query patterns, no new services or tools required.

Technical Review

The deduplication implementation:

const { data: existing } = await supabase
  .from("thoughts")
  .select("id")
  .contains("metadata", { slack_ts: messageTs })
  .limit(1);
if (existing && existing.length > 0) return new Response("ok", { status: 200 });

This is correct and idiomatic for Supabase JSONB queries. The .contains() method checks if the metadata column contains the specified key-value pair, which is exactly what's needed here.

One observation: The query could be slightly more defensive by checking for existing !== null explicitly, but the current implementation (existing && existing.length > 0) works because Supabase returns null for errors and an empty array [] for no matches — and both correctly fail the condition.

Metadata Check

The metadata.json hasn't changed, which is correct — this is a patch-level fix to existing functionality, not a version bump scenario (unless the maintainers want to bump to 1.0.1).

Verdict: Ready to merge

This is a clean, targeted fix for a documented edge case. The code change is minimal, safe, and solves the problem without side effects. The troubleshooting documentation now reflects reality.

Nice work on your first contribution to OB1!

@justfinethanku justfinethanku merged commit 2b4d550 into NateBJones-Projects:main Mar 24, 2026
@demarant demarant deleted the contrib/demarant/slack-capture-dedup-fix branch April 13, 2026 18:51
@demarant demarant restored the contrib/demarant/slack-capture-dedup-fix branch April 13, 2026 18:52
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.

3 participants