fix(purchase): surface save error on failed-status execution record#1237
fix(purchase): surface save error on failed-status execution record#1237cristim wants to merge 2 commits into
Conversation
|
Warning Review limit reached
More reviews will be available in 43 minutes and 57 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
The credential-resolution failure branch in executeForAccount discarded the SavePurchaseExecution error (_ =), while the post-purchase save in the same function treats a save failure as AUDIT LOSS. If the DB write failed on the credential-failure path, the per-account "failed" row was silently lost with no trace, leaving a gap in the History audit trail. Handle the failure-path save exactly like the success path: when the save fails, return an AUDIT LOSS error joined with the original credential-resolution error so neither failure is masked and the save error stays inspectable via errors.Is. Regression test asserts both errors surface; it fails on the previous code (save error silently dropped) and passes with the fix. Closes #1184
|
@coderabbitai review |
✅ Action performedReview finished.
|
…lo:10 The new `if saveErr != nil` audit-loss branch added to executeForAccount on this PR pushed its cyclomatic complexity from 10 to 11, tripping the `gocyclo -over 10` pre-commit hook (and leaving the PR UNSTABLE on three retries). Hoist the credential-failure save into a tiny `persistFailedAccountExecution` helper so executeForAccount drops back to 10 while the audit-loss surfacing behaviour and the new regression test (TestExecuteForAccount_CredentialFailure_SaveErrorSurfaced) remain identical: the helper still does `errors.Join(AUDIT LOSS..., cause)` on save-failure and returns `cause` unchanged on success, so neither the credential error nor the save error can be silently dropped. - gocyclo -over 10 internal/purchase/execution.go: clean (executeForAccount=10). - go vet ./internal/purchase/...: clean. - go test ./internal/purchase/... -count=1: 207 passed.
Adversarial review notesReviewed this as a money-path silent-failure surface (per-account "failed" row dropping silently leaves a re-approval / re-fire window). Findings: Fixed in
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
Problem
COR-10 (#1184): in
executeForAccount(internal/purchase/execution.go), the credential-resolution failure branch discarded theSavePurchaseExecutionerror (_ =), while the post-purchase save thirty lines later treats a save failure asAUDIT LOSSand returns it. If the DB write failed on the credential-failure path, the per-account "failed" row was silently lost with no log and no error, leaving a gap in the History audit trail.Fix
Handle the failure-path save exactly like the success path: when the save fails, return an
AUDIT LOSS: failed to save execution record ...error joined (viaerrors.Join) with the original credential-resolution error, so neither failure is masked and the underlying save error stays inspectable viaerrors.Is.Test evidence
TestExecuteForAccount_CredentialFailure_SaveErrorSurfacedreplicates the real scenario (credential resolution fails AND the failed-row save fails) and asserts both the AUDIT LOSS error and the credential error surface.go build ./...clean;go test ./internal/purchase/... -count=1: 207 passed;go vetclean.execution_test.gotiming assertions were not touched (TEST-05 / TEST-05: Elapsed-wall-time parallelism assertion in purchase fan-out test is CI-load sensitive #1158 is separate).Closes #1184