Skip to content

fix(exchange): reconcile stale processing RI exchange rows that now hold daily headroom indefinitely #692

Closed

Description

@cristim

Summary

A processing RI exchange row that never completes or fails holds daily headroom forever once #690 lands.

Current behaviour

After #690, riExchangeDailySpendQuery (internal/config/store_postgres.go) counts every processing row regardless of day, so an in-flight reservation survives UTC rollover (#657). The AUTO flow only logs a warning for processing rows older than 15 minutes (GetStaleProcessingExchanges in pkg/exchange/auto.go, no settle or release). Nothing reconciles a row left in processing after a Lambda crash or timeout between the provider call and CompleteRIExchangeWithPayment/FailRIExchange. Such a row keeps its reserved ceiling counted against the daily cap on every later day.

Steps to verify the gap

Reserve an exchange (AUTO or approval), kill the process before settlement, then read GetRIExchangeDailySpend on the next UTC day. The reserved ceiling is still counted. Code-derived, not an observed incident.

Expected behaviour

Stale processing rows are reconciled against the provider (exchange ID or describe call) and completed or failed, or an operator-visible alarm fires, so a crashed run cannot silently consume the cap indefinitely. Counting an ambiguous row conservatively until then is intended.

Proposed fix

A reconciler for processing rows older than a threshold: look up the provider exchange, settle or fail the row, and log/alert when it cannot decide. Add an operator path to release a row after manual verification. Paths: internal/config/store_postgres.go, internal/api/handler_ri_exchange.go.

References and severity

Follow-up to #656 and #657 (PR #690), go#41. Medium severity; fails safe (blocks exchanges rather than overspending) but can block all exchanges until cleared.

Activity

  1. IAmJSD commented on Oct 19, 2026

    @IAmJSD
    Collaborator

    Claiming: working on this

  2. self-assigned this
    on Oct 19, 2026
  3. added a commit that references this issue on Oct 23, 2026
    f9ae766
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions