Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

The Free Budget Vanished in 90 Minutes: Debugging a Token Ledger That Charged Every Retry

说明与用途

通过实现单一尝试日志并使用幂等键,消除了聊天应用中的双重计费、答案重复和余额跟踪错误。

问题

Free usage allowance was depleted unexpectedly while users interacted normally with a chat UI.

结果

The ledger refactor prevented repeated charges, eliminated duplicate answers, and stabilized balance tracking, restoring correct usage accounting.

工作流

  • Identify symptoms visible in UI and requests
  • Check outbound request count per user action
  • Verify idempotency key usage
  • Inspect prompt size and context reuse
  • Ensure single event listener for keydown/submit
  • Confirm live region updates are outside stream loop
  • Audit abort handling and ledger settlement
  • Refactor code to use a ledger module with createLedger, begin, settle, and summary functions
  • Add idempotency key to each request
  • Ensure ledger writes only on attempt start and settlement
  • Test with multiple users and edge cases

证据

Balance drops faster than the transcript grows

来源

Retries sent without an idempotency key

来源

Ledger.ts — the single source of truth for attempts and usage

来源

  • 记录日期: 2026-10-27T13:26:17.403Z