[PR #7562] [CLOSED] [WIP] [AI] [POC] Cumulative milestone allocation for #template by and schedule #60907

Closed
opened 2026-05-07 03:15:20 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/actualbudget/actual/pull/7562
Author: @StephenBrown2
Created: 4/20/2026
Status: Closed

Base: masterHead: push-ulsulqnnytrx


📝 Commits (2)

  • 83cb45e [AI] Use cumulative milestone allocation for by and schedule templates
  • 2e6051a [autofix.ci] apply automated fixes

📊 Changes

6 files changed (+219 additions, -243 deletions)

View changed files

📝 packages/loot-core/src/server/budget/category-template-context.test.ts (+4 -3)
📝 packages/loot-core/src/server/budget/category-template-context.ts (+56 -94)
packages/loot-core/src/server/budget/milestone-allocation.ts (+113 -0)
📝 packages/loot-core/src/server/budget/schedule-template.test.ts (+2 -2)
📝 packages/loot-core/src/server/budget/schedule-template.ts (+38 -144)
upcoming-release-notes/7562.md (+6 -0)

📄 Description

Description

This PR replaces the previous #template … by … math (shortest-window interpolation and summed scaled targets) and the separate sinking-fund / pay-month path for #template schedule … with a single cumulative milestone allocator.

Behavior:

  • Collect each #template X by Y and each active schedule line as a deadline month plus an increment (integer minor units, same as today).
  • Sort by month, sum increments that share the same deadline month, then take a running cumulative requirement at each deadline.
  • For each deadline j, let B be category carryover plus any amount already budgeted earlier at the same priority before this block; let Cj be the cumulative target due by that deadline, and nj = differenceInCalendarMonths(deadlineMonth, currentMonth). Compute ratej = max(0, Cj - B) / (nj + 1), then budget max over j of ratej (rounded).

This is memoryless with respect to template-specific history: only current month, balances, and stated targets matter, and one-off deposits or withdrawals flow through B.

Implementation notes:
  • New module: packages/loot-core/src/server/budget/milestone-allocation.ts (milestonesFromByTemplates, allocateCumulativeMilestones).
  • category-template-context.ts: at a given priority, by and schedule run once via runMilestoneTemplates; balance input is fromLastMonth + accumulatedToBudget for that priority pass.
  • schedule-template.ts: loadScheduleMilestones reuses existing createScheduleList (rules, adjustments, repeating monthly aggregation); runSchedule delegates to the same allocator as by. Uses isTrackingBudget after upstream rename from isReflectBudget.
  • Unit tests updated for new numeric expectations (including a fully funded yearly schedule where the monthly add is 0).

See this Discord thread for a fairly detailed explanation of the logic and demonstration using graphs.

https://discord.com/channels/937901803608096828/1493290910937645137

Testing

Automated tests updated to match expected budget amounts, manually tested locally.

Checklist

  • Release notes added
  • No obvious regressions in affected areas
  • Self-review has been performed - I understand what each change in the code does and why it is needed

NOTE: This will probably need documentation if actually adopted, I think it may surprise people coming from the previous additive method, as well as those expecting a simpler calculation.

Bundle Stats

Bundle Files count Total bundle size % Changed
desktop-client 34 13.86 MB 0%
loot-core 1 5.26 MB → 5.26 MB (-1.51 kB) -0.03%
api 1 3.89 MB → 3.89 MB (-1.47 kB) -0.04%
cli 1 7.91 MB 0%
crdt 1 41.83 kB 0%
View detailed bundle stats

desktop-client

Total

Files count Total bundle size % Changed
34 13.86 MB 0%
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
static/js/index.js 1.87 MB 0%
static/js/BackgroundImage.js 121.09 kB 0%
static/js/FormulaEditor.js 962.55 kB 0%
static/js/PayeeRuleCountLabel.js 52.52 kB 0%
static/js/ReportRouter.js 1.2 MB 0%
static/js/ScheduleEditForm.js 136.13 kB 0%
static/js/TransactionEdit.js 186.46 kB 0%
static/js/TransactionList.js 85.81 kB 0%
static/js/Value.js 4.94 MB 0%
static/js/ca.js 191.68 kB 0%
static/js/chart-theme.js 796.5 kB 0%
static/js/client.js 451.37 kB 0%
static/js/da.js 104.4 kB 0%
static/js/de.js 174.08 kB 0%
static/js/en-GB.js 8.2 kB 0%
static/js/en.js 176.64 kB 0%
static/js/es.js 181.5 kB 0%
static/js/extends.js 518.36 kB 0%
static/js/fr.js 182.7 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.46 kB 0%
static/js/it.js 168.53 kB 0%
static/js/narrow.js 364.25 kB 0%
static/js/nb-NO.js 151.58 kB 0%
static/js/nl.js 108.66 kB 0%
static/js/pl.js 88.34 kB 0%
static/js/pt-BR.js 193.45 kB 0%
static/js/resize-observer.js 18.06 kB 0%
static/js/th.js 178.91 kB 0%
static/js/theme.js 31.67 kB 0%
static/js/uk.js 212.28 kB 0%
static/js/useFormatList.js 8.63 kB 0%
static/js/wide.js 453 B 0%
static/js/workbox-window.prod.es5.js 7.33 kB 0%
static/js/zh-Hans.js 119.52 kB 0%

loot-core

Total

Files count Total bundle size % Changed
1 5.26 MB → 5.26 MB (-1.51 kB) -0.03%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/loot-core/src/server/budget/milestone-allocation.ts 🆕 +2.4 kB 0 B → 2.4 kB
home/runner/work/actual/actual/packages/loot-core/src/server/budget/category-template-context.ts 📉 -856 B (-4.89%) 17.08 kB → 16.25 kB
home/runner/work/actual/actual/packages/loot-core/src/server/budget/schedule-template.ts 📉 -3.07 kB (-40.32%) 7.62 kB → 4.55 kB
View detailed bundle breakdown

Added

Asset File Size % Changed
kcab.worker.DIg1cc1g.js 0 B → 5.26 MB (+5.26 MB) -

Removed

Asset File Size % Changed
kcab.worker.Flemh25r.js 5.26 MB → 0 B (-5.26 MB) -100%

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged
No assets were unchanged


api

Total

Files count Total bundle size % Changed
1 3.89 MB → 3.89 MB (-1.47 kB) -0.04%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/loot-core/src/server/budget/milestone-allocation.ts 🆕 +2.36 kB 0 B → 2.36 kB
home/runner/work/actual/actual/packages/loot-core/src/server/budget/category-template-context.ts 📉 -837 B (-5.04%) 16.23 kB → 15.41 kB
home/runner/work/actual/actual/packages/loot-core/src/server/budget/schedule-template.ts 📉 -3.01 kB (-40.27%) 7.47 kB → 4.46 kB
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger
No assets were bigger

Smaller

Asset File Size % Changed
index.js 3.89 MB → 3.89 MB (-1.47 kB) -0.04%

Unchanged
No assets were unchanged


cli

Total

Files count Total bundle size % Changed
1 7.91 MB 0%
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
cli.js 7.91 MB 0%

crdt

Total

Files count Total bundle size % Changed
1 41.83 kB 0%
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
index.js 41.83 kB 0%

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/actualbudget/actual/pull/7562 **Author:** [@StephenBrown2](https://github.com/StephenBrown2) **Created:** 4/20/2026 **Status:** ❌ Closed **Base:** `master` ← **Head:** `push-ulsulqnnytrx` --- ### 📝 Commits (2) - [`83cb45e`](https://github.com/actualbudget/actual/commit/83cb45ee17b31e95a35c3a6d7e31faf8b7b56046) [AI] Use cumulative milestone allocation for by and schedule templates - [`2e6051a`](https://github.com/actualbudget/actual/commit/2e6051a568e9267979e5fe1ef007792562837414) [autofix.ci] apply automated fixes ### 📊 Changes **6 files changed** (+219 additions, -243 deletions) <details> <summary>View changed files</summary> 📝 `packages/loot-core/src/server/budget/category-template-context.test.ts` (+4 -3) 📝 `packages/loot-core/src/server/budget/category-template-context.ts` (+56 -94) ➕ `packages/loot-core/src/server/budget/milestone-allocation.ts` (+113 -0) 📝 `packages/loot-core/src/server/budget/schedule-template.test.ts` (+2 -2) 📝 `packages/loot-core/src/server/budget/schedule-template.ts` (+38 -144) ➕ `upcoming-release-notes/7562.md` (+6 -0) </details> ### 📄 Description <!-- Thank you for submitting a pull request! Make sure to follow the instructions to write release notes for your PR — it should only take a minute or two: https://github.com/actualbudget/docs#writing-good-release-notes. Try running yarn generate:release-notes *before* pushing your PR for an interactive experience. --> ## Description This PR replaces the previous `#template … by …` math (shortest-window interpolation and summed scaled targets) and the separate sinking-fund / pay-month path for `#template schedule …` with a **single cumulative milestone allocator**. Behavior: - Collect each `#template X by Y` and each active schedule line as a **deadline month** plus an **increment** (integer minor units, same as today). - Sort by month, **sum increments that share the same deadline month**, then take a **running cumulative** requirement at each deadline. - For each deadline *j*, let **B** be category carryover plus any amount already budgeted earlier at the **same priority** before this block; let **C<sub>j</sub>** be the cumulative target due by that deadline, and **n<sub>j</sub>** = `differenceInCalendarMonths(deadlineMonth, currentMonth)`. Compute **rate<sub>j</sub>** = max(0, C<sub>j</sub> - B) / (n<sub>j</sub> + 1), then budget **max over j of rate<sub>j</sub>** (rounded). This is memoryless with respect to template-specific history: only current month, balances, and stated targets matter, and one-off deposits or withdrawals flow through **B**. <details><summary>Implementation notes:</summary> - New module: `packages/loot-core/src/server/budget/milestone-allocation.ts` (`milestonesFromByTemplates`, `allocateCumulativeMilestones`). - `category-template-context.ts`: at a given priority, `by` and `schedule` run **once** via `runMilestoneTemplates`; balance input is `fromLastMonth + accumulatedToBudget` for that priority pass. - `schedule-template.ts`: `loadScheduleMilestones` reuses existing `createScheduleList` (rules, adjustments, repeating monthly aggregation); `runSchedule` delegates to the same allocator as `by`. Uses `isTrackingBudget` after upstream rename from `isReflectBudget`. - Unit tests updated for new numeric expectations (including a fully funded yearly schedule where the monthly add is 0). </details> ## Related issue(s) See this Discord thread for a fairly detailed explanation of the logic and demonstration using graphs. https://discord.com/channels/937901803608096828/1493290910937645137 ## Testing Automated tests updated to match expected budget amounts, manually tested locally. ## Checklist - [x] Release notes added - [x] No obvious regressions in affected areas - [x] Self-review has been performed - I understand what each change in the code does and why it is needed NOTE: This will probably need documentation if actually adopted, I think it may surprise people coming from the previous additive method, as well as those expecting a simpler calculation. <!--- actual-bot-sections ---> <!--- bundlestats-action-comment key:combined start ---> ### Bundle Stats Bundle | Files count | Total bundle size | % Changed ------ | ----------- | ----------------- | --------- desktop-client | 34 | 13.86 MB | 0% loot-core | 1 | 5.26 MB → 5.26 MB (-1.51 kB) | -0.03% api | 1 | 3.89 MB → 3.89 MB (-1.47 kB) | -0.04% cli | 1 | 7.91 MB | 0% crdt | 1 | 41.83 kB | 0% <details> <summary>View detailed bundle stats</summary> #### desktop-client **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 34 | 13.86 MB | 0% <details> <summary>View detailed bundle breakdown</summary> <div> **Added** No assets were added **Removed** No assets were removed **Bigger** No assets were bigger **Smaller** No assets were smaller **Unchanged** Asset | File Size | % Changed ----- | --------- | --------- static/js/index.js | 1.87 MB | 0% static/js/BackgroundImage.js | 121.09 kB | 0% static/js/FormulaEditor.js | 962.55 kB | 0% static/js/PayeeRuleCountLabel.js | 52.52 kB | 0% static/js/ReportRouter.js | 1.2 MB | 0% static/js/ScheduleEditForm.js | 136.13 kB | 0% static/js/TransactionEdit.js | 186.46 kB | 0% static/js/TransactionList.js | 85.81 kB | 0% static/js/Value.js | 4.94 MB | 0% static/js/ca.js | 191.68 kB | 0% static/js/chart-theme.js | 796.5 kB | 0% static/js/client.js | 451.37 kB | 0% static/js/da.js | 104.4 kB | 0% static/js/de.js | 174.08 kB | 0% static/js/en-GB.js | 8.2 kB | 0% static/js/en.js | 176.64 kB | 0% static/js/es.js | 181.5 kB | 0% static/js/extends.js | 518.36 kB | 0% static/js/fr.js | 182.7 kB | 0% static/js/indexeddb-main-thread-worker-e59fee74.js | 13.46 kB | 0% static/js/it.js | 168.53 kB | 0% static/js/narrow.js | 364.25 kB | 0% static/js/nb-NO.js | 151.58 kB | 0% static/js/nl.js | 108.66 kB | 0% static/js/pl.js | 88.34 kB | 0% static/js/pt-BR.js | 193.45 kB | 0% static/js/resize-observer.js | 18.06 kB | 0% static/js/th.js | 178.91 kB | 0% static/js/theme.js | 31.67 kB | 0% static/js/uk.js | 212.28 kB | 0% static/js/useFormatList.js | 8.63 kB | 0% static/js/wide.js | 453 B | 0% static/js/workbox-window.prod.es5.js | 7.33 kB | 0% static/js/zh-Hans.js | 119.52 kB | 0% </div> </details> --- #### loot-core **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 1 | 5.26 MB → 5.26 MB (-1.51 kB) | -0.03% <details> <summary>Changeset</summary> File | Δ | Size ---- | - | ---- `home/runner/work/actual/actual/packages/loot-core/src/server/budget/milestone-allocation.ts` | 🆕 +2.4 kB | 0 B → 2.4 kB `home/runner/work/actual/actual/packages/loot-core/src/server/budget/category-template-context.ts` | 📉 -856 B (-4.89%) | 17.08 kB → 16.25 kB `home/runner/work/actual/actual/packages/loot-core/src/server/budget/schedule-template.ts` | 📉 -3.07 kB (-40.32%) | 7.62 kB → 4.55 kB </details> <details> <summary>View detailed bundle breakdown</summary> <div> **Added** Asset | File Size | % Changed ----- | --------- | --------- kcab.worker.DIg1cc1g.js | 0 B → 5.26 MB (+5.26 MB) | - **Removed** Asset | File Size | % Changed ----- | --------- | --------- kcab.worker.Flemh25r.js | 5.26 MB → 0 B (-5.26 MB) | -100% **Bigger** No assets were bigger **Smaller** No assets were smaller **Unchanged** No assets were unchanged </div> </details> --- #### api **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 1 | 3.89 MB → 3.89 MB (-1.47 kB) | -0.04% <details> <summary>Changeset</summary> File | Δ | Size ---- | - | ---- `home/runner/work/actual/actual/packages/loot-core/src/server/budget/milestone-allocation.ts` | 🆕 +2.36 kB | 0 B → 2.36 kB `home/runner/work/actual/actual/packages/loot-core/src/server/budget/category-template-context.ts` | 📉 -837 B (-5.04%) | 16.23 kB → 15.41 kB `home/runner/work/actual/actual/packages/loot-core/src/server/budget/schedule-template.ts` | 📉 -3.01 kB (-40.27%) | 7.47 kB → 4.46 kB </details> <details> <summary>View detailed bundle breakdown</summary> <div> **Added** No assets were added **Removed** No assets were removed **Bigger** No assets were bigger **Smaller** Asset | File Size | % Changed ----- | --------- | --------- index.js | 3.89 MB → 3.89 MB (-1.47 kB) | -0.04% **Unchanged** No assets were unchanged </div> </details> --- #### cli **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 1 | 7.91 MB | 0% <details> <summary>View detailed bundle breakdown</summary> <div> **Added** No assets were added **Removed** No assets were removed **Bigger** No assets were bigger **Smaller** No assets were smaller **Unchanged** Asset | File Size | % Changed ----- | --------- | --------- cli.js | 7.91 MB | 0% </div> </details> --- #### crdt **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 1 | 41.83 kB | 0% <details> <summary>View detailed bundle breakdown</summary> <div> **Added** No assets were added **Removed** No assets were removed **Bigger** No assets were bigger **Smaller** No assets were smaller **Unchanged** Asset | File Size | % Changed ----- | --------- | --------- index.js | 41.83 kB | 0% </div> </details> </details> <!--- bundlestats-action-comment key:combined end ---> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-07 03:15:21 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#60907