You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fineract.apache.org by "budaidev (via GitHub)" <gi...@apache.org> on 2026/08/18 12:18:05 UTC

[PR] FINERACT-2455: working capital breach reset split period undo [fineract]

budaidev opened a new pull request, #6283:
URL: https://github.com/apache/fineract/pull/6283

   ## Description
   
   Describe the changes made and why they were made. (Ignore if these details are present on the associated Apache Fineract JIRA ticket.)
   
   ## Checklist
   
   Please make sure these boxes are checked before submitting your pull request - thanks!
   
   - [ ] Write the commit message as per [our guidelines](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#pull-requests)
   - [ ] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
   - [ ] Create/update [unit or integration tests](https://fineract.apache.org/docs/current/#_testing) for verifying the changes made.
   - [ ] Follow our [coding conventions](https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions).
   - [ ] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
   - [ ] [This PR must not be a "code dump"](https://cwiki.apache.org/confluence/display/FINERACT/Pull+Request+Size+Limit). Large changes can be made in a branch, with assistance. Ask for help on the [developer mailing list](https://fineract.apache.org/#contribute).
   - [ ] If merging this PR resolves a JIRA issue, I will mark that issue as resolved and set "Fix Version/s" appropriately.
   
   Your assigned reviewer(s) will follow our [guidelines for code reviews](https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2455: working capital breach reset split period undo [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #6283:
URL: https://github.com/apache/fineract/pull/6283#issuecomment-5528095607

   **Can you please verify the below use cases?**
   
   WorkingCapitalLoanBreachScheduleServiceImpl.java:277 : a PAUSE recorded after a restart reset makes recalculatePeriodsForPauses re-date every period from the schedule start, wiping the split while leaving reset=true on a period that no longer contains the reset date. Probe: P2 goes back to 70 days and P3 shifts to [2026-05-11..2026-07-09] still flagged, so past due is computed from the wrong row. Pre-existing code, but it makes the split non-durable and this PR is what gives the split meaning: the pause/resume handler should re-derive flags via the new applyResetFlags.
   WorkingCapitalLoanBreachResetServiceImpl.java:53; PLAUSIBLE (also line 76): applyResetFlags runs before reprocessBreachSchedule regenerates periods, so an active reset whose date falls outside the mid-operation schedule gets pinned to the wrong row by resolveEvaluationPeriod's fallback. Needs a backwards business-date move to trigger, which the activeResets javadoc explicitly says can happen. Apply the flags after the schedule is final.
   
   Some minor:
   
   restoreSplitPeriod filters reschedules to those recorded before the reset (beforeActionId) but passes the unfiltered pause list to applyPauses. That happens to be consistent today because a pause already re-dates all periods, but the asymmetry is worth a comment.
   The WorkingCapitalLoanAccount.feature scenario C102391 (modify with invalid product id) and its step def are unrelated to breach reset undo. I traced the path and the expectation holds: validateForUpdate collects the longGreaterThanZero() error but productRepository.findById(...).orElseThrow(WorkingCapitalLoanProductNotFoundException) fires first, so 0 and -1 do return 404, but it's scope creep in a PR the checklist asks not to be a code dump. WorkingCapitalBreachReset.feature also lost its trailing newline (not spotless-enforced for .feature, so cosmetic only).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2455: working capital breach reset split period undo [fineract]

Posted by "budaidev (via GitHub)" <gi...@apache.org>.
budaidev commented on PR #6283:
URL: https://github.com/apache/fineract/pull/6283#issuecomment-5579127086

   > I think only one gap remained:
   > 
   > WorkingCapitalLoanBreachScheduleServiceImpl.java:346: restoreSplitPeriod derives the pre-split end as calculateToDate(...) + graceDays for period 1, but fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/service/WorkingCapitalLoanBreachScheduleServiceImpl.java:297 — which runs on every PAUSE/RESUME — re-dates period 1 without grace days. On a loan with breachGraceDays > 0 that has ever been paused, the undo restores the wrong boundary. Probe over the PR's own harness (grace 3, freq 60, pause 02-10..02-14): P1 stands at [01-01..03-06] (65 days), a restart reset on 02-20 splits it correctly, and the undo restores [01-01..03-09] (68 days) instead of 65 — every later boundary shifts by the grace days. Same mismatch defeats the new early-out at line 352: after that pause, a restart reset on P2's fromDate splits nothing (correctly), but the undo re-dates P1 and deletes P2 without regenerating it, leaving no period covering the business d
 ate — which contradicts the PR's own e2e scenario "Undo of a no-split restart reset is flag-only: schedule structure unchanged". The grace omission in recalculatePeriodsForPauses is pre-existing, but restoreSplitPeriod is new and depends on agreeing with it; both should compute the period end through one shared helper.
   
   Confirmed, reproduced with the numbers. Fixed the way you suggested: one private helper computes the natural period end. Test coverage has been added


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2455: working capital breach reset split period undo [fineract]

Posted by "budaidev (via GitHub)" <gi...@apache.org>.
budaidev commented on PR #6283:
URL: https://github.com/apache/fineract/pull/6283#issuecomment-5545540361

   > **Can you please verify the below use cases?**
   > 
   > WorkingCapitalLoanBreachScheduleServiceImpl.java:277 : a PAUSE recorded after a restart reset makes recalculatePeriodsForPauses re-date every period from the schedule start, wiping the split while leaving reset=true on a period that no longer contains the reset date. Probe: P2 goes back to 70 days and P3 shifts to [2026-05-11..2026-07-09] still flagged, so past due is computed from the wrong row. Pre-existing code, but it makes the split non-durable and this PR is what gives the split meaning: the pause/resume handler should re-derive flags via the new applyResetFlags. WorkingCapitalLoanBreachResetServiceImpl.java:53; PLAUSIBLE (also line 76): applyResetFlags runs before reprocessBreachSchedule regenerates periods, so an active reset whose date falls outside the mid-operation schedule gets pinned to the wrong row by resolveEvaluationPeriod's fallback. Needs a backwards business-date move to trigger, which the activeResets javadoc explicitly says can happen. Apply the flags after
  the schedule is final.
   
   1. PAUSE after a restart reset (`recalculatePeriodsForPauses`)** - confirmed, exactly your numbers.
   `recalculatePeriodsForPauses` is unchanged on this branch (identical to develop), so the erasure is pre-existing, but agreed that this PR is what gives the split meaning. Fixed: the pause recalculation now re-derives the flags (via `applyResetFlags` over the persisted actions) before it recalculates the past due, so the flag and the past-due anchor follow the reset date to its re-dated row.
   
   applyResetFlags fixed by moving the derivation into the schedule service, which is the one reshaping the schedule: `reprocessBreachSchedule` derives the flags right after it generated the periods up to the business date and before it replays the payments and recalculates the past due. The reset service no longer derives flags ahead of the split/restore; on the flag-only paths (plain reset, its undo) it asks the schedule service to derive them and recalculates the past due. One derivation, always over the persisted actions, always on the final schedule. The same re-derivation now also runs after a reschedule re-dates the periods and after `generateNextPeriodIfNeeded` created periods (COB, charge extension), so a reset placed on the last period by the fallback moves to its containing period once that period exists.
   
   > 
   > Some minor:
   > 
   > restoreSplitPeriod filters reschedules to those recorded before the reset (beforeActionId) but passes the unfiltered pause list to applyPauses. That happens to be consistent today because a pause already re-dates all periods, but the asymmetry is worth a comment. The WorkingCapitalLoanAccount.feature scenario C102391 (modify with invalid product id) and its step def are unrelated to breach reset undo. I traced the path and the expectation holds: validateForUpdate collects the longGreaterThanZero() error but productRepository.findById(...).orElseThrow(WorkingCapitalLoanProductNotFoundException) fires first, so 0 and -1 do return 404, but it's scope creep in a PR the checklist asks not to be a code dump. WorkingCapitalBreachReset.feature also lost its trailing newline (not spotless-enforced for .feature, so cosmetic only).
   
   - C102391 (invalid product id) and its step definition: dropped from this PR. QA can re-add it on its own ticket.
   - Trailing newline in `WorkingCapitalBreachReset.feature`: restored.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2455: working capital breach reset split period undo [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #6283:
URL: https://github.com/apache/fineract/pull/6283#issuecomment-5570976417

   I think only one gap remained:
   
   WorkingCapitalLoanBreachScheduleServiceImpl.java:346: restoreSplitPeriod derives the pre-split end as calculateToDate(...) + graceDays for period 1, but fineract-working-capital-loan/src/main/java/org/apache/fineract/portfolio/workingcapitalloan/service/WorkingCapitalLoanBreachScheduleServiceImpl.java:297 — which runs on every PAUSE/RESUME — re-dates period 1 without grace days. On a loan with breachGraceDays > 0 that has ever been paused, the undo restores the wrong boundary. Probe over the PR's own harness (grace 3, freq 60, pause 02-10..02-14): P1 stands at [01-01..03-06] (65 days), a restart reset on 02-20 splits it correctly, and the undo restores [01-01..03-09] (68 days) instead of 65 — every later boundary shifts by the grace days. Same mismatch defeats the new early-out at line 352: after that pause, a restart reset on P2's fromDate splits nothing (correctly), but the undo re-dates P1 and deletes P2 without regenerating it, leaving no period covering the business dat
 e — which contradicts the PR's own e2e scenario "Undo of a no-split restart reset is flag-only: schedule structure unchanged". The grace omission in recalculatePeriodsForPauses is pre-existing, but restoreSplitPeriod is new and depends on agreeing with it; both should compute the period end through one shared helper.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2455: working capital breach reset split period undo [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy merged PR #6283:
URL: https://github.com/apache/fineract/pull/6283


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2455: working capital breach reset split period undo [fineract]

Posted by "budaidev (via GitHub)" <gi...@apache.org>.
budaidev commented on PR #6283:
URL: https://github.com/apache/fineract/pull/6283#issuecomment-5579135300

   > Thanks @budaidev, this addresses everything I raised in the draft review. The LIFO replay now goes by recording order (not business-date order) with the reasoning documented directly on the method, the negative-period guard is in, and the reschedule-after-reset case is handled by filtering to reschedules in force at the time of the reset. Test coverage went from thin to substantial - unit tests on the resolver, the flag derivation, and the split/restore methods, plus a large Feign integration suite and new e2e scenarios.
   > 
   > One thing I want called out explicitly rather than left implicit: two of your own new integration tests demonstrate that a split can still be silently lost. `pauseAfterRestartReset_keepsTheFlagOnThePeriodHoldingTheResetDate` shows a pause recorded after a restart-reset re-expanding the truncated boundary back to its natural length - the reset flag survives but the split itself is gone, so the later undo has nothing to restore. And `undoAfterBackwardsBusinessDateMove_flagsTheRegeneratedPeriodOfTheStillActiveReset` shows a second restart-reset deleting an earlier, still-active reset's boundary permanently, even though that earlier reset stays on the active stack.
   > 
   > Both of these read like accepted/intentional behavior in the tests as written, and I don't think either needs to block this PR - the acute failure modes (heuristic drift, stale reschedule params, "success" on a no-op undo) are genuinely closed. But if the split is meant to be durable across a pause or a stacked reset, these two cases say otherwise, and I'd rather that be a documented decision (or a follow-up ticket to persist the pre-split boundary on the reset action itself, which would close both at once) than something a future bug report rediscovers.
   > 
   > Recommendation: COMMENT (would be APPROVE if the two cases above get an explicit answer either in this PR's description or as a tracked follow-up)
   
   Since your review, one more fix from Adam's last comment went in: the pause re-dating, the initial period and the undo restore now compute the period end through one shared helper, so period 1's grace days can no longer drift between them; unit and Feign scenarios cover it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2455: working capital breach reset split period undo [fineract]

Posted by "budaidev (via GitHub)" <gi...@apache.org>.
budaidev commented on PR #6283:
URL: https://github.com/apache/fineract/pull/6283#issuecomment-5545555184

   > The undo path is well covered - unit tests on both the resolver and the schedule methods, plus six integration tests including the pause-extended and payment-reassignment cases. That's usually the part I have to ask for, so nice work there.
   > 
   > My concern is with how the undo figures out what to revert. `restoreSplitPeriod` reverse-engineers the pre-split state from the schedule as it stands now plus the current breach config, using three guard clauses to decide whether the split it's looking at is actually the one this undo owns. Two of those guards fall through to a `log.warn` and a `false`, and the caller then just recalculates past due and returns 200 - so the user gets a success response for an undo that only lifted a flag and left the split in place.
   > 
   > Concretely: a RESCHEDULE recorded between the reset and the undo changes `resolveEffectiveRescheduleParams`, so the restore recomputes a boundary that never existed. And any PAUSE/RESUME between reset and undo rewrites every period contiguously from the schedule's first `fromDate` without knowing about the split, so the split disappears from the schedule entirely while the RESET row still says `restartPeriodFromResetDate = true` - the undo then silently falls into the flag-only branch.
   > 
   > Wouldn't it be simpler and deterministic to record on the RESET action row what the reset actually changed (the pre-split `toDate`, maybe the period id), and have the undo just write that back? Then there's nothing to guess and nothing that can silently degrade. The same reconstruction problem shows up in `findLatestFlaggedPeriod`'s "last flagged period by period number" fallback in the reset service - it assumes period-number order tracks reset-date order, which is exactly the assumption the boundary rewrites can break.
   > 
   > Two smaller things while I was in there:
   > 
   > * `splitPeriodAtReset` only guards `resetDate == fromDate`; `resetDate < fromDate` falls through and can persist a period with `toDate < fromDate` / negative `numberOfDays`.
   > * The RESET-undo replay in `WorkingCapitalLoanActiveBreachResetResolver` is ordered by `startDate, id` - since reset/undo dates are always "the current business date," if the business date is ever moved backwards between two actions the replay order diverges from creation order, and the `break`-on-id can stop before the reset it's meant to cancel.
   > 
   > This is a draft so nothing's blocking yet, but I'd like to settle the design question (store vs. reconstruct) before it comes out of draft - it affects several of the methods above at once.
   > 
   > Recommendation: COMMENT
   
   Thanks for the review, and sorry for the late answer here: the design question was settled with Adam and the implementation you reviewed has been replaced, so the concerns below no longer apply to the current head.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] FINERACT-2455: working capital breach reset split period undo [fineract]

Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on PR #6283:
URL: https://github.com/apache/fineract/pull/6283#issuecomment-5540844468

   @budaidev Please rebase


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org