Skip to content

fix: return AlreadyExists gRPC code for duplicate account creation#2168

Merged
bjcoombs merged 2 commits intodevelopfrom
fix-demo-seed-idempotent
Apr 8, 2026
Merged

fix: return AlreadyExists gRPC code for duplicate account creation#2168
bjcoombs merged 2 commits intodevelopfrom
fix-demo-seed-idempotent

Conversation

@bjcoombs
Copy link
Copy Markdown
Collaborator

@bjcoombs bjcoombs commented Apr 8, 2026

Summary

  • The InitiateCurrentAccount endpoint returned codes.Internal when repo.Save hit a duplicate account (ErrAccountExists). The seed-dev fixture seeder's createAccountIdempotent checks for codes.AlreadyExists to skip existing accounts, so the wrong status code caused the nightly demo reset to fail on re-runs.
  • Now checks for persistence.ErrAccountExists and returns codes.AlreadyExists, making the seeder's idempotent retry logic work correctly.

Test plan

  • Existing current-account tests pass (no behavior change for non-duplicate paths)
  • Nightly demo reset succeeds on re-run without "account already exists" failures

The InitiateCurrentAccount endpoint returned codes.Internal when
repo.Save hit an ErrAccountExists duplicate. The seed-dev fixture
seeder checks for codes.AlreadyExists to skip existing accounts
idempotently, so the wrong code caused the nightly demo reset to
fail on re-runs.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e7c192af-41ba-4d4c-a32a-fe5194391671

📥 Commits

Reviewing files that changed from the base of the PR and between c452a1f and d9fa3ae.

📒 Files selected for processing (2)
  • services/current-account/service/grpc_account_endpoints.go
  • services/current-account/service/grpc_service_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • services/current-account/service/grpc_account_endpoints.go

📝 Walkthrough

Walkthrough

InitiateCurrentAccount now returns a gRPC AlreadyExists status when repo.Save yields persistence.ErrAccountExists or persistence.ErrVersionConflict. A new unit test asserts duplicate initiation returns codes.AlreadyExists.

Changes

Cohort / File(s) Summary
Error handling differentiation
services/current-account/service/grpc_account_endpoints.go
Extended InitiateCurrentAccount error handling: treat persistence.ErrAccountExists and persistence.ErrVersionConflict from repo.Save as gRPC AlreadyExists with a specific message; other save errors still return Internal.
Tests
services/current-account/service/grpc_service_test.go
Added TestInitiateCurrentAccount_DuplicateReturnsAlreadyExists which creates an account then calls InitiateCurrentAccount again with the same ExternalIdentifier and asserts a codes.AlreadyExists gRPC error is returned.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: returning AlreadyExists gRPC code for duplicate account creation attempts, which matches the primary focus of the changeset.
Description check ✅ Passed The description clearly explains the problem (wrong gRPC status code causing demo seeder failures) and the solution (detecting duplicate account errors and returning AlreadyExists), directly relating to the changes made.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-demo-seed-idempotent

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

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — clean fix, LGTM. See summary comment for details.

@claude
Copy link
Copy Markdown

claude Bot commented Apr 8, 2026

Claude Code Review

Commit: d9fa3ae | CI: running

Summary

Clean, targeted bug fix. The InitiateCurrentAccount endpoint was returning codes.Internal for duplicate account creation, but the seed-dev fixture seeder relies on codes.AlreadyExists for idempotent retries. The fix correctly intercepts persistence.ErrAccountExists and persistence.ErrVersionConflict before the generic Internal fallback.

The test is well-structured: integration test against a real DB, creates an account then retries the same request, and asserts the specific gRPC status code.

Risk Assessment

Area Level Detail
Blast radius Low Only affects gRPC status code for duplicate account creation
Rollback Safe Pure code change, no data migration
Scale Low No new queries or loops
Cross-system Low Fixes existing contract expectation
Migration N/A No migration files

Findings

No issues found. The fix is correct, minimal, and well-tested.

Bot Review Notes

No unresolved bot threads. CodeRabbit review is still in progress.

The InitiateCurrentAccount endpoint returned codes.Internal when
repo.Save hit a duplicate account (via ErrAccountExists or
ErrVersionConflict on existing external_identifier). The seed-dev
fixture seeder checks for codes.AlreadyExists to skip existing
accounts idempotently, so the wrong code caused the nightly demo
reset to fail on re-runs.
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix - correct gRPC status mapping, good integration test, no domain risks. See summary comment for details.

@bjcoombs bjcoombs merged commit 2a88f96 into develop Apr 8, 2026
35 of 36 checks passed
@bjcoombs bjcoombs deleted the fix-demo-seed-idempotent branch April 8, 2026 06:15
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant