Repeated clock advance no longer 500s on a duplicate timeline id - #70
Merged
Conversation
…meline id Timeline ids are deterministic seeds derived from the billing event, so replaying one is a no-op rather than an error. Recording a duplicate raised a UNIQUE constraint failure surfaced as a 500, and the failure was unrecoverable: the test clock had already moved, so every later advance retried the same event and collided again, wedging the fixture permanently. Fixture packs that reset subscriptions but keep the ledger hit this on their second run. Guard the insert with ON CONFLICT DO NOTHING and cover it with a test that fails with the original UNIQUE error when the guard is removed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Aug 30, 2026
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
A repeated test-clock advance failed with
UNIQUE constraint failed: timeline_entries.id, returned as a 500.Timeline ids are deterministic seeds derived from the billing event — a trial activation is keyed by subscription and period end — so replaying one is a no-op, not an error.
Why it matters
The failure was unrecoverable. The clock is moved before the events are processed, so once processing failed the clock stayed ahead while the subscription stayed behind: every later advance retried the same event, collided again, and the fixture was wedged permanently. Fixture packs that reset subscriptions but keep the ledger hit this on their second run.
Found while driving subscription lifecycle transitions (trial expiry, dunning grace, grace expiry) from an end-to-end suite, where the same fixture is exercised on every run.
Change
insertTimelinenow guards withON CONFLICT(id) DO NOTHING.Test
TestRecordTimelineIsIdempotentForRepeatedEventIDsrecords the same entry twice and asserts the ledger holds exactly one copy. With the guard removed it fails with the originalUNIQUE constraint failederror.go test ./internal/...passes;gofmt -l internal/is clean.🤖 Generated with Claude Code