Repository navigation
fix(distributions): resume partial runs from persisted allocation plan - #1346
Merged
thlpkee20-wq merged 3 commits intoOct 22, 2026
Conversation
|
@Oluwasegun6921 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Oluwasegun6921
force-pushed
the
fix/issue-1303-fix-distributions-resuming-a-partial-run
branch
from
October 22, 2026 06:52
b7268e4 to
902ef37
Compare
Strips the payload this branch picked up (deleted api.js, truncated eslint.config.js, unhooked package.json). No functional change to the branch's own work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR fixes a correctness bug in
distributeWithBatch: when resuming a partially completed distribution run, the engine refetched balances and recomputed every investor's share from the new balances, then inserted payouts only for investors that did not already have one. Old and new payouts therefore came from different proration bases, so the sum of payouts could drift fromrun.total_amount, and a holder who arrived between the first attempt and the resume could receive a payout for a period they did not hold.The fix persists the computed allocation when the run is created, executes that persisted plan on resume instead of recomputing, and asserts the payout total against the run total on completion.
Related Issue
Changes
🗄️ Schema
src/db/migrations/044_create_distribution_allocations.sqldistribution_allocationstable storing the planned(run_id, investor_id, amount)allocation for each distribution run.(run_id, investor_id)so a plan can be written exactly once per investor per run.⚙️ Distribution Engine
src/services/distributionEngine.ts409when a non-completed run has no persisted plan, rather than silently recomputing from fresh balances.sum(payouts) == run.total_amountusingDecimal; on mismatch, mark the runfailedand log the discrepancy.🧪 Tests
src/services/distributionEngine.test.tsmasterfor the recompute-on-resume behavior.Verification Results
Decimaltotal assertion on completionsrc/services/distributionEngine.test.ts, plus a regression test that fails onmasterCloses #1303