Repository navigation
feat(events): deduplicate emits with a dedupe_key - #77
Merged
Merged
Conversation
psteinroe
commented
Oct 12, 2026
psteinroe
force-pushed
the
feat/emit-dedupe
branch
from
October 13, 2026 12:03
9f35f35 to
a33a767
Compare
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.
Webhook providers redeliver, so ingress may emit the same delivery twice.
conductor.emitandctx.emitnow take adedupe_keyoption, named like the one onconductor.invoke. Repeating a key for the same event name stores nothing and returns the original event ID.emit()always returns the event ID; thededupe_keyis the caller's own key and is never returned.SQL
pgconductor.emit_eventgains a trailingp_dedupe_key text default null, so existing plain-SQL callers are unaffected. The two mechanisms stay separate:p_iduuid from fix(events): make retried emits idempotent #63 makes a retry after a lost response idempotent;p_dedupe_keyis the caller's key. The dispatch execution stores'<event name>:<dedupe_key>'as itsdedupe_key, and the existing unique(task_key, dedupe_key, queue)constraint enforces it.The insert now uses an untargeted
on conflict do nothing, which covers both. It then returns the stored row's ID. This is insert-or-return-existing, not invoke's dedupe semantics: the original payload is kept. Concurrent emits with the same key serialize on the unique index. The loser waits for the winner to commit, then returns the winner's ID.Retention window
The internal
pgconductor.event-dispatchtask changes fromremoveOnComplete: trueto{ days: 1 }, in both the task definition and the_private_tasksseed row. Completed dispatch rows now stay for a day, and the daily maintenance run removes them. Every worker, including the internalpgconductor.internalone, registers a maintenance cron, so keys are remembered for 1–2 days. The tests check that maintenance is scheduled on the internal queue.The scope (per event name) and the window are documented in
triggers.md("Deduplicating Emits"),api/conductor.md, a newctx.emitsection inapi/task-context.md, and next to invoke indeduplication.md.Verification
New integration tests in
event-pipeline.test.ts:p_dedupe_keycaller gets the same ID. The same key under another event name emits a second event.conductor.emitkey after dispatch triggers the listener once and resumes the waiter once. The waiter's second wait times out instead of seeing the repeat.ctx.emitwith a key across a failed and retried attempt stores one event.Three existing tests asserted that the dispatch row is deleted on completion. They now assert it is completed.
just lint,bun run typecheckand the fullbun testpass.Follow-ups
emit. Whichever lands second merges{ dedupe_key, metadata }into one options type.removeOnFail. Out of scope here.dedupe_keyindex. Not bounded here.