Repository navigation
Conversation
The Slack mirror recorded a ticket's thread identity, but not which replies it had already posted. A retried reply job could therefore post the same message again. Add a per-message delivery ledger with an atomic claim lease, mark delivery after Slack accepts the post, and skip retries for messages already delivered. The claim is taken and judged against the database clock, so lease expiry does not depend on worker clock skew. A handler can now ask for a minimum delay before its next attempt, and the worker honours it when it is longer than the exponential backoff; that is how a job waits out a lease held by another execution. A permanent Slack rejection releases the claim so the message is not stranded; an ambiguous failure keeps it, because Slack may already have accepted the post. Slack requests get a timeout and the WebClient is cached per token, so a stalled request cannot outlive the job without bound and successive jobs reuse one client. Truncation now counts grapheme clusters rather than UTF-16 code units, so an emoji is never cut in half. The ledger is a new additive table related to Message, so rolling workers can continue using the existing schema. The delivery marker and the Slack post cannot be committed atomically; a process crash in between can still duplicate a post after the lease expires. Refs CopilotKit#152 Co-Authored-By: Claude Code <noreply@anthropic.com>
This branch has not been deployed
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 changed
#150 made each ticket's Slack thread idempotent, but replies were not: when Slack accepted a reply and the queue retried before it could record success, the same message could be posted again. Long replies could also be cut inside an emoji, and each job constructed a new Slack
WebClient.SlackMirrorDeliverytable keyed uniquely by source message. A worker atomically claims the row before posting, records delivery after Slack accepts it, and skips already delivered messages. An unexpired claim prevents concurrent posts. If another execution still owns the claim, the queue honors a minimum retry delay until the lease expires. Claims use the database clock and Slack requests have a timeout; a stalled execution can still outlive its lease.Message; the migration only creates a new table, its unique index, and its foreign key, so existing rows and older workers remain compatible during rollout.WebClientper token. A token change replaces the cached client.Delivery guarantee
Slack and Postgres cannot commit the message post and the delivery marker in one transaction. A process crash, or an ambiguous post failure, after Slack accepts a reply but before the database marker commits can therefore still lead to a duplicate after the 120-second claim lease expires. The ledger prevents normal queue retries, concurrent attempts, and retries after the marker is saved; it does not claim exactly-once delivery across those two systems.
Validation
prisma migrate diffreported no drift.git diff --checkpassed.Refs #152
🤖 Generated with Claude Code