Skip to content

Email the owner when their AnyAPI wallet is empty or its connection is revoked - #93

Open
kev1n wants to merge 1 commit into
mainfrom
alert-count-and-lead-quality
Open

kev1n wants to merge 1 commit into
mainfrom
alert-count-and-lead-quality

Conversation

@kev1n

@kev1n kev1n commented Sep 20, 2026

Copy link
Copy Markdown
Member

Why

Wallet-funded jobs that hit insufficient balance (HTTP 402) fail, requeue, and fail again every hour with nobody told: boat has 29 failed competitor scans, idealista 15, Anantya 14. A revoked wallet connection (see #92) is the same shape and needs a reconnect only the user can do.

What

  • src/lib/alerts/walletNotice.ts: reads the failure's cause chain for the SDK's InsufficientBalanceError or a 400/401 TokenRequestError, and emails the project's owner what stopped and where to fix it.
  • One email per trouble per user: the stamp (wallet_connections.balance_notice_at / reconnect_notice_at) is claimed by a conditional update before sending, handed back if the send fails, repeats after 3 days if still failing, and is cleared on reconnect.
  • No wallet row means the house key paid, so nobody is emailed.
  • The runner calls it after the job's end is written; a notice failure never changes the job.

Testing

tests/walletNotice.test.ts against Postgres: two jobs failing together send one email; silent within the gap; sends again after it and after a reconnect; nothing for a house-funded user; a failed send can be retried. Typecheck and lint clean; only the existing tests/jobs.test.ts timeout fails.

🤖 Generated with Claude Code

…s revoked

A job that fails because the wallet paying for it has no credits comes back
every hour and fails again, and nothing told the person: one prod project has
29 failed competitor scans reading 'insufficient balance'. The same is true of
a revoked connection, which only a reconnect fixes.

When a job ends on either, the project's owner gets one email saying what
stopped and where to fix it. A conditional update takes the stamp before the
send, so jobs failing together send one email; it repeats after three days if
still so, and a reconnect clears it. A house-funded failure emails nobody.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.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