Skip to content
This repository was archived by the owner on Nov 1, 2026. It is now read-only.

fix(invoice): refuse a non-USD payout when conversion fails - #812

Closed
tieubao wants to merge 1 commit into
mainfrom
fix/fx-fallback-refuse
Closed

tieubao wants to merge 1 commit into
mainfrom
fix/fx-fallback-refuse

Conversation

@tieubao

@tieubao tieubao commented Jul 28, 2026

Copy link
Copy Markdown
Member

contractor_invoice.go:463-469 fell back to amountUSD = p.Amount whenever ResolveAmountUSD errored. For a non-USD payout that assigns the raw local figure to the dollar field: a 26,000,000 VND payout becomes a $26,000,000 invoice line. It fails open, and it fails precisely when Wise or Redis is down.

Not theoretical: the Contractor Payouts database currently holds 393 VND rows against 420 USD. Roughly half of all payouts take this path on every run.

The fallback is kept where it is harmless (a payout already in USD, where the raw amount is the dollar amount) and refused everywhere else. The first failure is recorded and checked after the WaitGroup, so one bad payout refuses the whole invoice instead of contributing a wrong line to it.

An invoice that fails to generate is a support ticket. An invoice with a 1000x line is a payment.

Verified: go build, go vet, and go test ./pkg/controller/invoice/... all pass (built with the mise Go 1.24.2 that matches GOROOT, per the repo's known toolchain trap).

Found while porting this pipeline to Cloudflare, where the port refuses the same case rather than inheriting the fallback.

https://claude.ai/code/session_01UgkobZof5By2wCpkBXhjK4

The fallback assigned the raw local amount to the dollar field, so a payout in
dong became an invoice line a thousand times too large, and it did so exactly
when Wise or Redis was unavailable, which is when nobody is watching. Roughly
half the payout rows are in dong today, so this was one outage away from a
wrong invoice.

The fallback is kept where it is harmless, a payout already denominated in
USD, and refused everywhere else. One failed conversion now fails the whole
invoice rather than quietly contributing a wrong line to it: an invoice that
does not generate is a support ticket, an invoice with a thousandfold line is
a payment.

Claude-Session: https://claude.ai/code/session_01UgkobZof5By2wCpkBXhjK4
@tieubao

tieubao commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

Closing per Han: the goal is to shut GKE down, not to invest in it.

The bug is real (a failed conversion assigns the raw VND figure to the dollar field, and 393 of 813 payout rows are VND), but the durable fix is on the Cloudflare side, which is where this pipeline is moving:

  • the CF port already REFUSES a non-USD payout it cannot convert, rather than inheriting the fallback (foundation-workers feat: archive and unarchive work unit api #103)
  • the CF fx worker now has real Wise rates, synced live: VND->USD 0.0000379724 (~26,335 VND/USD)

So the same class of failure cannot produce a wrong invoice on the new stack, and fortress keeps its behaviour unchanged for the remainder of its life rather than taking a deploy it does not need.

Residual risk stays recorded in dfoundation DF-174 so it is a known-accepted exposure, not a forgotten one.

@tieubao tieubao closed this Jul 28, 2026
@tieubao
tieubao deleted the fix/fx-fallback-refuse branch November 1, 2026 03:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant