Repository navigation
Releases
Releases · joshuavivo/exactly-once-webhooks
v0.10.1
No change to what the library does since 0.10.0: in src/ only comments changed
(the doc comments in types.ts). This is the first version built to be published to
the npm registry.
Added
- Release workflow publishes to npm. After the GitHub Release, the
release
workflow runsnpm publish --provenance, so a published version records the commit
and workflow run it was built from (#29). The README keeps the release-tarball
install line until a version is on the registry.
Changed
- README: the
onRetryparagraph has its own heading. It sat under
createPostgresStorealthough it is mostly about the Redis store. Same text, moved
below the Redis section. package.jsondescription no longer says "exactly once" without its limits. It
is the first line of the package's registry page, and it now matches the repository
description: once on Postgres, a lease on Redis.- Docs: a worked outbox example. The README and
DESIGN.mdtell callers to use an
outbox for calls to outside APIs. Both now link to
webhook-crm-alert's Postgres path, which uses this library's Postgres store for
the claim and an outbox for its CRM and chat calls, with its own tests against a real
Postgres. No code change. - Package metadata:
package.jsonnow names the repository, homepage, issue
tracker and author, so an installed copy (node_modules/exactly-once-webhooks/package.json)
and npm tooling link back to this repo. - README badges: live test status for
main, the latest release, the Node
floor and the license, at the top of the README. - Docs: "exactly once" means the effect, not the delivery. The README now says so
up front: delivery stays at-least-once, and what runs once is the handler's work,
as strongly as the store allows. DESIGN's statement of the guarantee is now scoped
per store (Postgres fully, for writes made through the transaction; Redis a lease;
memory one process), and no longer lists "calling the downstream API" as an effect
the library makes happen once: an outside call isn't rolled back, which is what the
outbox paragraph under "Alternatives" covers. The API docs (README and the
IdempotencyStorecomments intypes.ts) no longer say "at most once" without
the store's limits, and the concurrent-call line now notes the Redis lease. - Docs: the benchmark notes no longer point at #11 as open. The Postgres waiter
cost now says the wait has been bounded bylockTimeoutMssince 0.9.
v0.10.0
Added
- DESIGN: "Alternatives, and why this design doesn't use them". Check-then-insert,
a plain insert that catches the unique violation, advisory locks,SERIALIZABLE
and retry, effect-then-record, Redlock, and the provider's idempotency key, each
with the reason it falls short here, plus the outbox pattern for external API
calls. The Postgres behaviour it cites (a failed insert aborts the transaction
unless it's in a savepoint;hashtextis 32-bit; how a concurrent insert waits)
was checked on Postgres 16. Written as reasoning, not as a history of what was
tried. - Redis: a call whose claim expired mid-effect now says so. It still returns
status: "processed"(the effect did run), pluslostClaim: true, because its
compare-and-set result write did not apply, so nothing was recorded. Either another
caller had taken the key over (the effect may have run twice) or nobody had (the
next delivery runs it again); DESIGN limitation 4. Before, the CAS outcome was
ignored and the call looked like a normal first run.Outcome<T>gains the
optionallostClaim?: true; the Postgres and memory stores never set it. Found in
an AI review.
Changed
- Postgres: the claim's
lock_timeoutis now a bound parameter
(SELECT set_config('lock_timeout', $1, true), the parameterised form of
SET LOCAL) instead of a number spliced into the SQL. It was safe before
(lockTimeoutMsis validated as a non-negative integer), but it was the one
statement in the store built by string interpolation. Same behaviour; the
lockTimeoutMstest now also checks the bound value. Found in an AI review. - Memory store: completing a key no longer scans the whole map. With
maxEntriesset, every completion used to count all done entries before
evicting; it now keeps a running count, so the bookkeeping is O(1) and eviction
only walks past keys still in flight. Which key is evicted is unchanged, and a new
test pins that order across a failed effect and re-delivered keys. Locally, 40k
completions with a 20k cap went from ~1.0 s to ~0.08 s. Found in an AI
review. - Every store returns the same JSON copy for a duplicate. The memory store
used to hand a duplicate the first run's live object, while Postgres and Redis
returned a JSON copy (aDateas its ISO string,undefinedasnull), so code
tested against the memory store could behave differently in production. The
memory store now keeps results as JSON too, so a result JSON can't hold (a
BigInt, a cycle) fails in tests the way it fails in production. A function or
Symbolresult, whichJSON.stringifydrops, now comes back asnullfrom
every store, as it already did from Postgres; before, the memory store returned
the live value and Redis returnedundefined. A new contract test pins this for
every store; DESIGN limitation 5 says what each store does. The call that ran
the effect still gets its own value back. Found in an AI review.
Fixed
- Redis:
pollIntervalMsandmaxWaitMsare validated when the store is
created, like the TTLs already were. Before,maxWaitMs: NaNmade a waiter
wait forever (elapsed > NaNis never true), a negativemaxWaitMsgave up on
the first look, and a negative or NaNpollIntervalMswas silently treated as
~1 ms. NowpollIntervalMsmust be finite and non-negative, andmaxWaitMs
non-negative (0 andInfinitystill allowed), orcreateRedisStorethrows with
the bad value in the message. Found in an AI review. - Docs: what the effect's
lock_timeoutactually is. The code comment said the
effect gets "the session default";SET LOCAL lock_timeout TO DEFAULTactually
restores the server or role default, so alock_timeoutthe appSETon the
connection does not apply inside the effect (checked on Postgres 16: session
5sreads0inside the effect,5sagain after commit). Behaviour unchanged
since 0.9.0; the comment is corrected and DESIGN limitation 6 says how to bound
the effect's own lock waits. Found by an adversarial AI review of this release. - Example: replaying a dead letter that was parked as malformed is refused
cleanly.replay()cast the parse result to an event without checking it, so
replaying a malformed letter threw a bareTypeError(Cannot read properties of undefined) from inside the ledger write. Nothing was written and the letter was
kept, but the person replaying it got a crash, not a reason. It now returns
400 still malformed: <reason>, never runs the write, and keeps the letter. Found
in an AI review. - Docs: where a losing caller waits on Postgres. The README, DESIGN.md, the
schema.sql header and four code comments said the loser waits in
SELECT ... FOR UPDATE. It actually waits in its own
INSERT ... ON CONFLICT DO NOTHING, which blocks until the winner's transaction
ends; by the time it reads, the winner has finished. This is what limitation 7
already said; the earlier text now agrees with it. No code change. Found by an
adversarial AI review. - Postgres: a connection whose
ROLLBACKfailed is destroyed, not reused. The
store swallowed a failedROLLBACKand calledrelease()with no argument, so a
connection left in an unknown state went back into the pool for the next caller.
It now passes the error torelease(err), which tellspgto discard the
connection; after a clean rollback the connection is reused as before.
PoolClient.releaseaccepts the optional error, aspg's does. Found in an
AI review.
v0.9.0
Added
fromIoRedis(client)(closes #3): ioredis adapter using the same Lua
scripts asfromNodeRedis. The full shared contract runs against it through an
ioredis-shaped stub that checks the positionalSEToptions andevalorder.
Changed
- Postgres: waits on another caller's claim are bounded (closes #11). New
lockTimeoutMsoption, default 5000 (before: no limit; set0to keep
that). A transaction-locallock_timeouton the claim, reset before the effect
runs, so effect statements are unaffected. A timed-out caller throws a clear
error and frees its pooled connection; a real-Postgres test with a 2-connection
pool shows an unrelated key served promptly while a slow holder runs.
Fixed
- Postgres claim-loop comments, the cap's error message and DESIGN limitations 6–7
described a "retry after the holder rolls back" that real Postgres never does:
the waiter's blocked INSERT takes the key directly (closes #24). The loop now
says what really sends it round (a prune racing the key), with a test.
v0.8.0
Added
onRetry({ key, attempt })on the Redis and Postgres stores (closes #7):
fires when a waiter must retry because the holder failed, so contention and a
deterministically failing key are visible before the retry cap. Optional and a
no-op by default; a throwing hook is ignored. On Postgres a rollback hands the
claim straight to the blocked waiter, so it rarely fires there (tested).- Benchmark (
npm run bench,benchworkflow; closes #5): distinct-key
throughput and p50/p99, and the hot-key case with an exactly-once assertion,
on the memory store and real Postgres + Redis. Numbers in the README link the
run that produced them. examples/payment-path: the whole payment path in one place. Signature
verification (raw-body HMAC, constant-time, timestamp tolerance, rotation),
exactly-once via the store, an append-only ledger, and a dead-letter path with
replay. The Postgres version writes the ledger row in the same transaction as
the idempotency key, andledger.sqlmakes the table append-only with a trigger
plus UNIQUEevent_idandreverses. Tests for each step, on the memory store
and (in CI) a real Postgres.make exampleruns the demo.
Fixed
- Redis store:
ttlSeconds/pendingTtlSecondsthat are zero, negative or not
finite are refused at construction. Before, Redis rejectedPX 0on the result
write, after the effect had run, so a redelivery ran it again. Milliseconds are
rounded up in the store instead of in each adapter. - payment-path example: a partial refund is dead-lettered instead of reversing the
whole charge; a refund that arrives before its charge is retried, not parked;
concurrent copies that fail together count as one failed delivery; a malformed
event delivered twice makes one dead letter; the refund lookup is ordered.
Changed
- README install line: the package is installed from the GitHub release tarball
(it is not on the npm registry), and CI now installs that tarball into a fresh
project and imports it on every change. Docs corrected where they overclaimed:
Redis waiters time out aftermaxWaitMs; the Redis hot-key benchmark row uses a
tuned poll interval; "secret rotation" is the provider's; the ledger trigger is
a second line behind table grants. DESIGN's testing section now says Redis also
runs the contract against a real server.
v0.7.0
Changed (breaking for custom RedisLike adapters)
- Redis claims carry an ownership token (closes #10). The pending value now
holds a random token, andRedisLikeswapssetValue/delfor
setIfValue(key, expected, value, ttlMs)anddelIfValue(key, expected):
atomic compare-and-set / compare-and-delete.fromNodeRedisimplements them as
Lua scripts, exported asSET_IF_VALUE_LUA/DEL_IF_VALUE_LUAso other
adapters reuse the same ones.fromNodeRedisusers need no change.
Fixed
- A Redis holder whose claim expired mid-effect could overwrite the result of the
caller that took over, or — if its effect then threw — delete that caller's
live claim and let a third caller run the effect again. Both are now no-ops for
a holder that no longer owns the claim. Two tests force the expiry and fail
without the token.