surveys: make the atomic per-rider cap part of the repository contract #117
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 273 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.336
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #117"
general
weight: 0.35
aaronbrethorst
Fixes #116. Follow-up to #114 (merged).
Context
#114 enforces the per-rider survey cap inside the write transaction via an optional
surveys.CappedCreator, whichcreateSurveyResponsetype-asserts for, falling back to plainCreateResponse(pre-check only, races) when missing;internal/store/storetestdoesn't exercise it. So a future adapter could omit it and pass conformance, reintroducing concurrent over-cap creates. Also,surveys.ErrTooManyResponses→ 422 had no handler coverage.Change (option: fold in + drop fallback)
surveys.Repository:CreateResponseCapped(ctx, in, now, maxPerRider int64) (Response, error)is now mandatory (ErrNotFound,ErrTooManyResponses;maxPerRider <= 0= no cap; atomic per-rider cap inside the write transaction). sqlitesurveyRepoalready implements it.surveys.CappedCreator;createSurveyResponsecallsh.deps.Surveys.CreateResponseCapped(..., limit)directly, drop the fallback branch;CountResponsesByUserfast pre-check kept;ErrTooManyResponses→ same 422"User identifier has already responded to this survey".surveys.Repository:failingSurveys,erroringSurveysRepo,fatalOnWriteRepo(CreateResponseCapped);fatalOnWriteRepot.Fatals on any create.internal/store/storetestunaffected (callsCreateResponse); conformance now can't omitCreateResponseCapped.Handler test
TestSurveyResponse_ErrTooManyResponses422(internal/httpapi/surveys_responses_test.go):tooManyRepoCreateResponseCapped → surveys.ErrTooManyResponses,CountResponsesByUser → 0, rest real → 422 + per-rider message. (Pre-check passes; atomic branch rejects.)Existing atomicity pin kept:
TestCreateResponseCappedConcurrentSameUser(internal/store/sqlite, N=8 same user,maxPerRider=1→ exactly 1 success, restErrTooManyResponses, 1 stored;_txlock=immediate).Verification
go vet ./...;gofmt;go test ./internal/httpapi ./internal/surveys ./internal/store/... -count=1.internal/store/sqlitehas only pre-existing WindowsTestOpen_FileModesOwnerOnly(Unix file modes; passes on Linux). Full CI pending.