mirror of
https://github.com/Comfy-Org/Comfy-PR.git
synced 2026-11-04 23:37:33 +00:00
[PR #205] feat(webhook): Vercel receiver + MongoDB queue (changeStream consumer) #205
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/Comfy-PR#205
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Comfy-Org/Comfy-PR/pull/205
Author: @snomiao
Created: 4/28/2026
Status: 🔄 Open
Base:
main← Head:sno-bot📝 Commits (7)
07eec2afeat(webhook): MongoDB-backed webhook queue + changeStream consumerf905926feat(webhook): Vercel Slack receiver → MongoDB webhook_queuef502258feat(webhook): extend queue to github + notion sourcesa0eab6cfix: corrupt .claude.json crashed every agent spawn (no useful log)79bc584fix(agent-spawn): three bugs that all surfaced as "exit code 1"5b711e4fix(bot): stop 3000+ restart loop from poison-pill task resumeea73861chore(daemon): migrate comfy-pr-bot from pm2 to oxmgr📊 Changes
12 files changed (+1457 additions, -54 deletions)
View changed files
📝
CLAUDE.md(+20 -7)📝
app/api/webhook/github/route.ts(+25 -1)➕
app/api/webhook/notion/route.ts(+142 -0)➕
app/api/webhook/slack/route.ts(+137 -0)📝
bot/error-collector.ts(+8 -0)📝
bot/index.ts(+99 -0)📝
bot/slack-bot.ts(+163 -22)📝
bot/spawn-as-user.ts(+39 -2)📝
bot/task-user.ts(+33 -0)📝
bot/up.sh(+25 -22)➕
bot/webhook-queue.ts(+224 -0)➕
docs/cloudrun-vs-gke-vs-hybrid.md(+542 -0)📄 Description
Summary
Move the Slack webhook ingest off the local VM bot and onto a serverless Vercel Function backed by a MongoDB queue. The bot tails the queue via changeStream, so Slack retries no longer get dropped while the bot is restarting/down.
What's new
bot/webhook-queue.ts— MongoDB-backed queueenqueueWebhook()inserts a doc intowebhook_queue(Atlas, replica set ⇒ changeStream supported)startWebhookConsumer()drains any unprocessed backlog at boot, then tails the changeStream filtered by sourcemarkWebhookProcessed()flipsprocessed=true(and stashes truncated error stack on failure) so resume after restart doesn't reprocessexpireAfterSeconds: 86400) oncreatedAtgives a 24h time-cap. Capped collections cap on bytes and don't allow per-doc updates, so we use a regular collection + TTL index instead.webhook_edge_dedup) with 1h TTL — used by the Vercel route to suppress retry storms before they reach the queue.bot/slack-bot.ts— wire bot consumer/slack/eventsHTTP handler now just verifies signature, dedups, andenqueueWebhook()— no inline dispatch.startSlackBot()callsstartWebhookConsumer({ sources: ["slack"] })so the existinghandleSlackEventruns against queue docs instead of inbound HTTP.app/api/webhook/slack/route.ts— Vercel receiverevent_callback→ edge dedup →enqueueWebhook({ source: "slack" })→ 200runtime: "nodejs"so the mongodb driver works (Edge runtime can't open Atlas connections)https://comfy-pr.vercel.app/api/webhook/slackdocs/cloudrun-vs-gke-vs-hybrid.mdBackground analysis comparing GKE vs Cloud Run vs Hybrid deployment options that led to this lighter-weight queue design.
Cutover
Slack app A078498JA5T Event Subscriptions Request URL has been moved:
Slack verified the new URL successfully. The local
/slack/eventsendpoint remains as a fallback during the cutover; safe to remove after a few days of clean Vercel traffic.Test plan
bunx tsc --noEmitbun test bot/taskInputFlow.spec.ts(4/4 pass)event_callback→ bot HTTP /slack/events →webhook_queueinsert → consumer dispatch →processed=true(~70ms)200 {challenge:...}afterSLACK_SIGNING_SECRETenv var setwebhook_queue(source=slack) → VM consumer →processed=truewithin ~26s/slack/eventsHTTP handler and stop redirectingprbot.stukivx.xyzto the VM🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.