Skip to content

fix(purchase): surface save error on failed-status execution record#1237

Open
cristim wants to merge 1 commit into
mainfrom
fix/cor-10-fix
Open

fix(purchase): surface save error on failed-status execution record#1237
cristim wants to merge 1 commit into
mainfrom
fix/cor-10-fix

Conversation

@cristim

@cristim cristim commented Jun 11, 2026

Copy link
Copy Markdown
Member

Problem

COR-10 (#1184): in executeForAccount (internal/purchase/execution.go), the credential-resolution failure branch discarded the SavePurchaseExecution error (_ =), while the post-purchase save thirty lines later treats a save failure as AUDIT LOSS and 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 (via errors.Join) with the original credential-resolution error, so neither failure is masked and the underlying save error stays inspectable via errors.Is.

Test evidence

  • New regression test TestExecuteForAccount_CredentialFailure_SaveErrorSurfaced replicates the real scenario (credential resolution fails AND the failed-row save fails) and asserts both the AUDIT LOSS error and the credential error surface.
  • Confirmed it FAILS on pre-fix code (save error silently dropped) and passes with the fix.
  • go build ./... clean; go test ./internal/purchase/... -count=1: 207 passed; go vet clean.
  • Per the finding guidance, execution_test.go timing 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

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
@cristim cristim added triaged Item has been triaged priority/p3 Polish / idea / may never ship severity/low Minor harm urgency/eventually No deadline impact/few Limited audience effort/xs Trivial / one-liner type/bug Defect labels Jun 11, 2026
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@cristim, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 57 minutes and 56 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f9289c75-f31f-450e-98c4-552148302acb

📥 Commits

Reviewing files that changed from the base of the PR and between 4108e51 and 8a08afd.

📒 Files selected for processing (2)
  • internal/purchase/execution.go
  • internal/purchase/execution_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cor-10-fix

Comment @coderabbitai help to get the list of available commands and usage tips.

@cristim

cristim commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/xs Trivial / one-liner impact/few Limited audience priority/p3 Polish / idea / may never ship severity/low Minor harm triaged Item has been triaged type/bug Defect urgency/eventually No deadline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

COR-10: Failed-status purchase execution save is unchecked (_ =) while the success-path save treats failure as audit loss

1 participant