fix(linear-bot): dedupe webhooks by Linear-Delivery header, not webhook configuration ID#627
Conversation
The bot dedup'd webhooks on the body's `webhookId` field, which Linear documents as the registered-webhook configuration ID — a constant for every delivery to a given endpoint. Empirically observed: three unrelated AgentSessionEvent deliveries across distinct issues all carried `webhookId: a5d92758-d29b-4214-adef-f1e452fee526`. So the first webhook of each hour poisoned the KV slot (TTL 3600s) and every subsequent delivery within the TTL was silently dropped — surfacing in Linear as "Anton did not respond." Switch the dedup key to the `Linear-Delivery` HTTP header, which Linear documents as a UUID v4 that "uniquely identifies the payload delivery." Fail closed with 400 if the header is absent so a future Linear change surfaces in the webhook delivery log rather than silently degrading.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe webhook handler for ChangesAgentSessionEvent Webhook Handler Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
The Linear bot dedupes incoming webhooks using the body's
webhookIdfield. Per Linear's webhook docs, that field is the registered-webhook configuration ID — a constant for every delivery to a given endpoint, not a per-delivery identifier. So once the first webhook of each hour writes its slot to KV, every subsequent delivery within theexpirationTtl(3600s) hits the duplicate branch inisDuplicateEventand is silently dropped withHTTP 200 { skipped: true, reason: "duplicate" }. From a user's perspective in Linear, the agent shows up as "Did not respond" on most issue assignments.This switches the dedup key to the
Linear-DeliveryHTTP header, which Linear documents as a UUID v4 that "uniquely identifies the payload delivery." The route also fails closed withHTTP 400when the header is absent, so a future Linear change surfaces in the webhook delivery log rather than silently degrading.Reproduction
Live worker tail while reproducing — three unrelated
AgentSessionEventdeliveries (different issues, minutes apart, including one freshly created) all carried the same bodywebhookId. The KV slot keyed on that ID was set on the first delivery and shadowed the next two until TTL expiry:Changes
packages/linear-bot/src/index.ts—+16/-13. The/webhookroute now:AgentSessionEventpayload shape before reading any headers.Linear-Deliveryfrom request headers.HTTP 400withreason: "missing_linear_delivery_header"if the header is missing.Test plan
npm run typecheck -w @open-inspect/linear-botnpm run lint -w @open-inspect/linear-botnpm test -w @open-inspect/linear-bot— all 103 tests passagent_session.received→agent_session.session_createdwith distinct trace IDs and no spurious dedup.Notes for reviewers
No new tests.
src/index.tsis explicitly excluded from coverage invitest.config.tsand the repo convention doesn't add route-level tests. The change is a single route edit with no extractable pure helper whose test would do more than restate the implementation.Summary by CodeRabbit