Nobody has started this yet — be first.
Business impact
This metric is one half of the README's own headline deliverable: the benchmark comparing the two locking strategies reports a "retry rate" computed from this counter. If every successful, zero-contention claim is counted as at least one retry, the reported retry rate is inflated across the board -- an operator deciding whether to switch LOCK_STRATEGY based on "how much contention is the optimistic strategy actually seeing in production" would be working from a number that's wrong even under perfectly healthy, uncontended traffic.
Problem
optimistic_lock_retries_total increases by the full attempt count on every optimistic claim -- including claims that succeeded on their very first try, which should contribute nothing.
Current behavior
OptimisticAttempts(n) adds n unconditionally whenever n >= 1, which is every single call, since n is never 0.
Expected behavior
Per the metric's own HELP text ("extra attempts (beyond the first)"), a claim that succeeds on attempt 1 should add 0; a claim that needed 3 attempts should add 2.
Steps to reproduce
go test ./tickets/tests/... -run TestTicket17 -vWhy this matters
OptimisticAttempts(n) is called once per Claim call with the total number of attempts it made. It currently adds n unconditionally whenever n >= 1 -- which is every single call, since n is never 0. It should only add n - 1, and only when n > 1.
Suggested approach
Compare the guard condition and the value passed to .Add(...) in OptimisticAttempts against its own doc comment on the struct field (optimisticRetries) two lines above it, which already states the intended semantics.
Acceptance criteria
Verification
go test ./tickets/tests/... -run TestTicket17 -v
Hints (0/2)
Try it without hints first — the reading is the exercise.
Working on this ticket
Work on a branch named for the ticket — that's what you'll submit.
Branch off your fork
Sign in to create it automatically, or do it yourself:
$git checkout -b fix/optimistic-attempts-overcountFix it and commit
Meet every acceptance criterion, and add a test that would have caught this.
Push the branch
$git push -u origin fix/optimistic-attempts-overcountSubmit it below
Paste your fork URL and the branch name, with a short write-up of the root cause.
Questions
Ask about anything unclear in the ticket — the maintainer and anyone who has solved it can answer. Please don't post full solutions.
Sign in to ask a question or reply.
Sign inSKIP LOCKEDhttp://localhost:8081localhost:5434flash-saleeveryday-widgetcurl localhost:8081/healthzgo run ./cmd/loadtest -url http://localhost:8081 -sku flash-sale -concurrency 10000Work the tickets in tickets/docs/ (ordered easy → hard); each names one dedicated Go test in tickets/tests/:
export TEST_DATABASE_URL=postgresql://inventory:inventory@localhost:5432/inventory_test?sslmode=disable
go test ./tickets/tests/... -run TestTicket24 -v # a single ticket
./tickets/run_tickets.sh # all 25, clean pass/fail summary
Tickets that don't touch Postgres (02, 07, 17, 19) run fine without TEST_DATABASE_URL; the rest t.Skip cleanly, not fail, if it's unset.
Level 1
Fix a bug
Read existing behaviour, correct it.