Skip to content

Make invoice funding reconciliation idempotent across retried batches #1189

Description

@mikewheeleer

Summary

Reconciliation can be run more than once while a previous batch is still finishing, which can duplicate adjustments or reports.

Why this matters

This closes a correctness, security, or operability gap in the Liquifact backend and makes the behavior explicit, observable, and safe under failure.

Requirements

  • Repository scope: Liquifact/Liquifact-backend only.
  • Introduce a run identity and durable completion record; make retries resume or return the existing result; keep reconciliation scoped to one tenant and time window.
  • Preserve tenant isolation, structured errors, and existing API compatibility unless the issue explicitly requires a contract change.
  • Add focused unit and integration coverage for the new behavior.

Technical guidance

  • Follow the repository's existing middleware, service, persistence, logging, and error-envelope conventions.
  • Keep side effects bounded and make retries, authorization, and failure handling explicit.
  • Document non-obvious tradeoffs and include security notes in the PR.

Edge cases — each must have a test

  • first run completes once
  • same run key is replayed
  • two workers start the same run concurrently
  • a partially completed batch resumes
  • an empty window produces a stable result

Acceptance criteria

  • Every requirement and edge case above is implemented and tested
  • Unit and integration tests cover success, failure, retry, and authorization paths
  • Existing tests pass with no regressions
  • Errors are structured and do not leak secrets or internal stack details
  • npm run lint, npm test, and npm run build passes locally
  • Code follows existing conventions with no duplication or dead code
  • Documentation or concise comments explain non-obvious decisions
  • PR description explains the approach, includes test evidence and security notes, and references Closes #

Out of scope

  • automatic financial remediation

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveStellar Wave Program task

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions