Repository navigation
AI-3513: count a forward's attempt at its claim, leave an unopenable secret to another router - #2269
Conversation
…an unopenable secret to another router The claim of event deliveries now counts the attempt, as queue.go's claim does, and Retry no longer writes it. A delivery whose forwarder dies between claim and send every time is given up once it was claimed more often than it may be tried, instead of coming back with the same count for ever. A router that does not hold the key version a destination's secret was sealed with sends nothing: it gives the counted attempt back and leaves the delivery due a poll later, rather than deleting it as refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
/jeffery review |
|
Thanks for asking Jeffery for review. I'll stay on this PR until I can approve it. How it works
Commands (each as a whole comment)
|
There was a problem hiding this comment.
✅ Approved 98735f3f73a4 after 1 round
Left open, your call:
- consider: Shutdown during a send now spends an attempt (
acceleration/internal/eventforward/forwarder.go:524) - consider: Unopenable key version is re-claimed every poll forever (
acceleration/internal/eventforward/forwarder.go:532)
…im counted Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Round 1, point by point:
|
|
/jeffery review |
Withdrawing approval until d6d8aeb is reviewed.
There was a problem hiding this comment.
✅ Approved d6d8aeb4732f after 2 rounds · 1 fixed
Left open, your call:
- consider: Unopenable key version is re-claimed every poll forever (
acceleration/internal/eventforward/forwarder.go:532)
…release A release is due a lease later rather than a poll, so a router without the key no longer cycles the destination's backlog every second, and logs once a lease per destination. A forward no router has signed for longer than its retries and a lease is given up as forward_failed. Release names the claim it gives back by its attempts and lease, so it cannot undo a newer claim. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…513-webhook-forwards-are-retried-for
Withdrawing approval until d7ab375 is reviewed.
There was a problem hiding this comment.
Round 3 on d7ab37572667 · 🆕 1 new · ✅ 1 fixed
Still open: 1 should-fix. Full list on the checks tab.
| // The claim counted this attempt. | ||
| attempts := delivery.Attempts | ||
| switch { | ||
| case errors.Is(err, auth.ErrKeyVersionUnavailable) && time.Since(delivery.CreatedAt) > f.unsignedWait(): |
There was a problem hiding this comment.
[Should Fix] Give-up by row age drops a forward still on its retries
Issue: A forward still within its normal retries, or one that waited behind a slow destination's backlog, is dropped as not sent the first time a router without its key version claims it. A router that holds the key never gets to send it.
Cause: forwarder.go:532 compares time.Since(delivery.CreatedAt) with unsignedWait(), which is the lease plus the sum of the retries. That measures the row's age, not how long no router could sign it. Retries are scheduled from the end of each send (forwarder.go:549), so real retries pass the margin.
Fix: Time the give-up from the first release for ErrKeyVersionUnavailable. For example, store a marker that Release sets once and that a successful send or a retry leaves alone.
Side effect: This needs a new column or marker on the delivery row, so check the migration order.
Evidence
- created_at comes from DEFAULT now() in Queue (store/event_delivery.go:87), so it is the queue time
- unsignedWait = lease + sum(retries) (forwarder.go:562-568); defaultRetries sum is about 2h35m (line 90)
- Retry at forwarder.go:549 schedules from time.Now() after each send, and attemptTimeout is 15s (line 50). Four timed-out sends add 60s, which is the whole lease margin.
- Key rotation rollout: a v1-only router claims an old row, errors.Is(err, ErrKeyVersionUnavailable) holds and the row age is over the limit. Finish at line 536 deletes it without any v2 router trying.
There was a problem hiding this comment.
✅ Approved d7ab37572667 after 3 rounds · 2 fixed
Left open, your call:
- should-fix: Give-up by row age drops a forward still on its retries (
acceleration/internal/eventforward/forwarder.go:532)
Why
https://linear.app/stream/issue/AI-3513/webhook-forwards-are-retried-for-ever-when-the-sender-dies-and-deleted
Two problems with webhook forwards:
Retrycounted an attempt, and it runs after a send. If the forwarder died between the claim and the send, the delivery came back with the same count every time and was never given up.What changed
store/event_delivery.go). The claim'sUPDATEnow setsattempts = cedl.attempts + 1, asclaiminqueue.godoes.Retryonly writes the next due time and no longer takesattempts. The forwarder reads the count the claim returned. A delivery that was claimed more times than it may be tried (the first try plus one per retry wait) is now given up without being sent. It is counted asforward_failed, because the claims before it never recorded an outcome.eventforward/forwarder.go).auth.ErrKeyVersionUnavailable, the existing sentinel the sealer returns for a key version it does not hold, the forwarder calls the newEventDeliveries.Release. Release takes back the attempt the claim counted and makes the row due again one lease later, on Postgres's clock, as if the claim had simply run out. It does not make the row due at once: this router is woken by its own finished send, so it would take the destination's backlog straight back on every poll.attempts = ? AND next_attempt_at = ?, the values the claim wrote), so a release whose lease ran out cannot undo another router's newer claim.forward_failed. Before this change it was deleted on the first try; without the bound it would cycle forever.forward_failed, asTestAForwardThatCouldNotBeSignedIsCountedAsNotSentexpects.Releasetakes the attempt back, while AI-3517: judge leases on the database's clock #2267'sunclaimfor the other queues leaves it counted. The difference is on purpose. Those queues fence every later write onattempts(heldBy), so lowering it there would let the claim before it write again. Event deliveryRetry/Finishtake no attempts fence, so nothing here reads the number as a token.eventforward/AGENTS.mddescribes both behaviours.This change is independent of #2267 (AI-3517). That PR moves
queue.go's claim onto the database clock and leaves the event delivery claim alone. Three things are filed as AI-3716 rather than fixed here:Closecuts off between its commit and the read of its rows uses up an attempt.openSecrets).No other open PR touches
event_delivery.goorinternal/eventforward.Tests
TestAForwardWhoseSenderDiesEveryTimeIsGivenUpAfterItsAttempts: three claims whose lease ends at once and that are never sent, then a started forwarder. The delivery is dropped and the destination is never hit.TestAForwardWhoseSecretThisRouterCannotOpenIsLeftToOneThatCan: a router on key version 1 alone neither sends nor drops a forward sealed under version 2. Once a router that holds version 2 starts, it sends the forward exactly once.TestAForwardNoRouterCanSignIsGivenUpAndNotClaimedEveryPoll: a router on key version 1, with a 500 ms lease, releases a forward sealed under version 2 at least once and at most twice, then gives it up. It sends nothing, and does not claim the forward again on each 10 ms poll.TestAClaimCountsItsAttemptAndAReleaseTakesItBack(store): two claims count 1 and 2. After a release the row is due again, even though the last lease runs an hour, and the next claim counts 2. That claim runs a minute on, so the release's DB-clocknow()is behind it.TestAReleaseOfAClaimTakenOverChangesNothing(store): releasing a stale claim leaves the newer claim's attempts and lease as they were.TestEventDeliveryQueryBudgetscoversRelease(1 query).TestARetriedDeliveryIsDueAtItsNextAttemptstill sees 1 attempt: the count now comes from the claim.go test -tags integration ./internal/eventforward(3 runs), the whole./internal/storeStoreSuite, and./internal/channelbridge: all pass.go vet ./...andgofmtare clean.🤖 Generated with Claude Code