[PR #6999] [AI] Invalidate spreadsheet cache when sync applies while spreadsheet is not loaded #6872

Open
opened 2026-02-28 21:33:55 -06:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/actualbudget/actual/pull/6999

State: open
Merged: No


Summary

Fix a cache invalidation gap in sync processing that can leave budget calculations stale until users manually click Reset budget cache.

Problem

In multi-device/multi-user usage (especially mobile Safari lifecycle transitions), sync messages can be applied while the spreadsheet instance is not loaded.

In that path, cache invalidation could be skipped, allowing stale cached budget values to be reused on next load.

Root Cause

In applyMessages (packages/loot-core/src/server/sync/index.ts), cache barriers were only applied when a spreadsheet instance existed.

When no spreadsheet instance existed, kvcache / kvcache_key were not invalidated.

Fix

  • In the no-spreadsheet sync path, explicitly clear:
    • kvcache
    • kvcache_key
  • Re-read the spreadsheet reference before post-sync projection updates for safer lifecycle handling.

Tests

Added regression test in:

  • packages/loot-core/src/server/sync/sync.test.ts

New test verifies that when applyMessages runs without a loaded spreadsheet, both kvcache and kvcache_key are cleared.

Ran:

  • yarn workspace loot-core run test:node src/server/sync/sync.test.ts src/server/sync/migrate.test.ts
  • Result: passing

Notes

This change was driven by a real-world report of stale budget calculations requiring repeated “Reset budget cache” on iOS Safari.

I have not fully reproduced the full iOS flow in an isolated end-to-end sandbox, so maintainer validation in that environment would be appreciated.

This is my first contribution; feedback on approach and test coverage is welcome.


Bundle Stats

Bundle Files count Total bundle size % Changed
desktop-client 27 14.85 MB 0%
loot-core 1 5.82 MB → 5.82 MB (+370 B) +0.01%
api 1 4.43 MB → 4.43 MB (+330 B) +0.01%
View detailed bundle stats

desktop-client

Total

Files count Total bundle size % Changed
27 14.85 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 9.54 MB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 12.94 kB 0%
static/js/workbox-window.prod.es5.js 5.64 kB 0%
static/js/ca.js 188.15 kB 0%
static/js/da.js 106.35 kB 0%
static/js/de.js 180.07 kB 0%
static/js/en-GB.js 7.18 kB 0%
static/js/en.js 170.37 kB 0%
static/js/es.js 174.55 kB 0%
static/js/fr.js 179.6 kB 0%
static/js/it.js 171.16 kB 0%
static/js/nb-NO.js 156.96 kB 0%
static/js/nl.js 106.37 kB 0%
static/js/pl.js 88.37 kB 0%
static/js/pt-BR.js 154.22 kB 0%
static/js/th.js 181.87 kB 0%
static/js/uk.js 214.74 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/BackgroundImage.js 120.54 kB 0%
static/js/ReportRouter.js 1.16 MB 0%
static/js/narrow.js 637.68 kB 0%
static/js/TransactionList.js 106.22 kB 0%
static/js/wide.js 164.15 kB 0%
static/js/AppliedFilters.js 9.71 kB 0%
static/js/usePayeeRuleCounts.js 10.04 kB 0%
static/js/useTransactionBatchActions.js 13.23 kB 0%
static/js/FormulaEditor.js 1.04 MB 0%

loot-core

Total

Files count Total bundle size % Changed
1 5.82 MB → 5.82 MB (+370 B) +0.01%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/loot-core/src/server/sync/index.ts 📈 +370 B (+2.04%) 17.71 kB → 18.07 kB
View detailed bundle breakdown

Added

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

Removed

Asset File Size % Changed
kcab.worker.BwrdDDMW.js 5.82 MB → 0 B (-5.82 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 4.43 MB → 4.43 MB (+330 B) +0.01%
Changeset
File Δ Size
src/server/sync/index.ts 📈 +330 B (+2.09%) 15.42 kB → 15.74 kB
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger

Asset File Size % Changed
bundle.api.js 4.43 MB → 4.43 MB (+330 B) +0.01%

Smaller
No assets were smaller

Unchanged
No assets were unchanged

**Original Pull Request:** https://github.com/actualbudget/actual/pull/6999 **State:** open **Merged:** No --- ## Summary Fix a cache invalidation gap in sync processing that can leave budget calculations stale until users manually click **Reset budget cache**. ## Problem In multi-device/multi-user usage (especially mobile Safari lifecycle transitions), sync messages can be applied while the spreadsheet instance is not loaded. In that path, cache invalidation could be skipped, allowing stale cached budget values to be reused on next load. ## Root Cause In `applyMessages` (`packages/loot-core/src/server/sync/index.ts`), cache barriers were only applied when a spreadsheet instance existed. When no spreadsheet instance existed, `kvcache` / `kvcache_key` were not invalidated. ## Fix - In the no-spreadsheet sync path, explicitly clear: - `kvcache` - `kvcache_key` - Re-read the spreadsheet reference before post-sync projection updates for safer lifecycle handling. ## Tests Added regression test in: - `packages/loot-core/src/server/sync/sync.test.ts` New test verifies that when `applyMessages` runs without a loaded spreadsheet, both `kvcache` and `kvcache_key` are cleared. Ran: - `yarn workspace loot-core run test:node src/server/sync/sync.test.ts src/server/sync/migrate.test.ts` - Result: passing ## Notes This change was driven by a real-world report of stale budget calculations requiring repeated “Reset budget cache” on iOS Safari. I have not fully reproduced the full iOS flow in an isolated end-to-end sandbox, so maintainer validation in that environment would be appreciated. This is my first contribution; feedback on approach and test coverage is welcome. <!--- actual-bot-sections ---> <hr /> <!--- bundlestats-action-comment key:combined start ---> ### Bundle Stats Bundle | Files count | Total bundle size | % Changed ------ | ----------- | ----------------- | --------- desktop-client | 27 | 14.85 MB | 0% loot-core | 1 | 5.82 MB → 5.82 MB (+370 B) | +0.01% api | 1 | 4.43 MB → 4.43 MB (+330 B) | +0.01% <details> <summary>View detailed bundle stats</summary> #### desktop-client **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 27 | 14.85 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 | 9.54 MB | 0% static/js/indexeddb-main-thread-worker-e59fee74.js | 12.94 kB | 0% static/js/workbox-window.prod.es5.js | 5.64 kB | 0% static/js/ca.js | 188.15 kB | 0% static/js/da.js | 106.35 kB | 0% static/js/de.js | 180.07 kB | 0% static/js/en-GB.js | 7.18 kB | 0% static/js/en.js | 170.37 kB | 0% static/js/es.js | 174.55 kB | 0% static/js/fr.js | 179.6 kB | 0% static/js/it.js | 171.16 kB | 0% static/js/nb-NO.js | 156.96 kB | 0% static/js/nl.js | 106.37 kB | 0% static/js/pl.js | 88.37 kB | 0% static/js/pt-BR.js | 154.22 kB | 0% static/js/th.js | 181.87 kB | 0% static/js/uk.js | 214.74 kB | 0% static/js/resize-observer.js | 18.37 kB | 0% static/js/BackgroundImage.js | 120.54 kB | 0% static/js/ReportRouter.js | 1.16 MB | 0% static/js/narrow.js | 637.68 kB | 0% static/js/TransactionList.js | 106.22 kB | 0% static/js/wide.js | 164.15 kB | 0% static/js/AppliedFilters.js | 9.71 kB | 0% static/js/usePayeeRuleCounts.js | 10.04 kB | 0% static/js/useTransactionBatchActions.js | 13.23 kB | 0% static/js/FormulaEditor.js | 1.04 MB | 0% </div> </details> --- #### loot-core **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 1 | 5.82 MB → 5.82 MB (+370 B) | +0.01% <details> <summary>Changeset</summary> File | Δ | Size ---- | - | ---- `home/runner/work/actual/actual/packages/loot-core/src/server/sync/index.ts` | 📈 +370 B (+2.04%) | 17.71 kB → 18.07 kB </details> <details> <summary>View detailed bundle breakdown</summary> <div> **Added** Asset | File Size | % Changed ----- | --------- | --------- kcab.worker.A08EYJOV.js | 0 B → 5.82 MB (+5.82 MB) | - **Removed** Asset | File Size | % Changed ----- | --------- | --------- kcab.worker.BwrdDDMW.js | 5.82 MB → 0 B (-5.82 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 | 4.43 MB → 4.43 MB (+330 B) | +0.01% <details> <summary>Changeset</summary> File | Δ | Size ---- | - | ---- `src/server/sync/index.ts` | 📈 +330 B (+2.09%) | 15.42 kB → 15.74 kB </details> <details> <summary>View detailed bundle breakdown</summary> <div> **Added** No assets were added **Removed** No assets were removed **Bigger** Asset | File Size | % Changed ----- | --------- | --------- bundle.api.js | 4.43 MB → 4.43 MB (+330 B) | +0.01% **Smaller** No assets were smaller **Unchanged** No assets were unchanged </div> </details> </details> <!--- bundlestats-action-comment key:combined end --->
GiteaMirror added the pull-request label 2026-02-28 21:33:55 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#6872