Skip to content

fix: make user balance initialization idempotent - #19

Merged
suguanYang merged 2 commits into
stagingfrom
fix/wangbinqi/idempotent-user-balance-init
May 11, 2026
Merged

suguanYang merged 2 commits into
stagingfrom
fix/wangbinqi/idempotent-user-balance-init

Conversation

@suguanYang

@suguanYang suguanYang commented May 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • replace first-use user balance creation with Postgres ON CONFLICT DO NOTHING so concurrent requests do not emit duplicate-key error spans
  • only create the initial grant transaction/payment from the request that actually inserted user_balances
  • keep the sync worker billing service aligned with the async API service
  • add an HTTP contract test that sends concurrent GET /billing/credits requests and verifies only one balance/grant/payment is created

Verification

  • uv run --package knowhere-api-app --group dev pytest apps/api/tests/contract/test_billing_contract.py -q
  • uv run --package knowhere-worker-app --group dev pytest apps/worker/tests/contract/test_parse_task_contract.py -q
  • uv run --group lint ruff check packages/shared-python/shared/services/billing/credits_service.py packages/shared-python/shared/services/billing/credits_sync_service.py apps/api/tests/contract/test_billing_contract.py

@suguanYang
suguanYang force-pushed the fix/wangbinqi/idempotent-user-balance-init branch 3 times, most recently from eca0daf to 84d98fd Compare May 11, 2026 11:10
@suguanYang
suguanYang force-pushed the fix/wangbinqi/idempotent-user-balance-init branch from 84d98fd to e66fa9e Compare May 11, 2026 11:14
@suguanYang
suguanYang merged commit 08d3f4e into staging May 11, 2026
9 checks passed
suguanYang added a commit that referenced this pull request May 12, 2026
* fix: make user balance initialization idempotent (#19)

* fix: downgrade insufficient credits billing log (#21)
EricNGOntos added a commit that referenced this pull request May 12, 2026
* fix: make user balance initialization idempotent (#19)

* fix: optimize agentic rag evidence rendering and navigation

* chore: fix ruff lint errors

* fix: resolve typecheck errors for agentic orchestrator

* docs: update AGENTS.md with current 3-phase agentic navigation and hydration logic

* chore: test github flow skill

---------

Co-authored-by: suguanYang <wangbinqi77@gmail.com>
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