Skip to content

[AI] Mobile transaction updates field-level merging - #8196

Merged
MatissJanis merged 2 commits into
actualbudget:masterfrom
mannkind:amount-nearby-race
Jun 22, 2026
Merged

MatissJanis merged 2 commits into
actualbudget:masterfrom
mannkind:amount-nearby-race

Conversation

@mannkind

@mannkind mannkind commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

I haven't been able to reproduce the issue reported in #6706 (comment). I thought maybe there might be some kind of race condition on updating the transaction that I didn't quite grok.

Claude (Fable 5) concurs that is likely two concurrent updates (e.g. the blur committing the typed amount, and the Nearby tap setting the payee) each replacing the entire transaction from a stale copy, so whichever landed last erased the other's field.

Claude Code (Fable 5) helped work through the potential issue and the fix.

Related issue(s)

Issue reported on #6706 (comment)

Testing

Reproducing the issue has not been possible for me, but I've manually tested this locally and don't see it adding additional issues. 😅

Checklist

  • Release notes added (see link above)
  • No obvious regressions in affected areas
  • Self-review has been performed - I have read every line of this diff and can explain what each change does and why it is needed

Bundle Stats

Bundle Files count Total bundle size % Changed
desktop-client 28 13.02 MB → 13.02 MB (+383 B) +0.00%
loot-core 1 4.82 MB 0%
api 2 3.87 MB 0%
cli 1 8.02 MB 0%
crdt 1 11.12 kB 0%
View detailed bundle stats

desktop-client

Total

Files count Total bundle size % Changed
28 13.02 MB → 13.02 MB (+383 B) +0.00%
Changeset
File Δ Size
src/components/mobile/transactions/TransactionEdit.tsx 📈 +383 B (+0.52%) 71.92 kB → 72.3 kB
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 7.63 MB → 7.63 MB (+383 B) +0.00%

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
static/js/AppliedFilters.js 36.47 kB 0%
static/js/BackgroundImage.js 121.09 kB 0%
static/js/FormulaEditor.js 735.67 kB 0%
static/js/PayeeRuleCountLabel.js 7.1 kB 0%
static/js/ReportRouter.js 1.23 MB 0%
static/js/TransactionList.js 85.19 kB 0%
static/js/ca.js 179.71 kB 0%
static/js/da.js 100.19 kB 0%
static/js/de.js 177.24 kB 0%
static/js/en-GB.js 9.25 kB 0%
static/js/en.js 200.55 kB 0%
static/js/es.js 171.82 kB 0%
static/js/extends.js 435.39 kB 0%
static/js/fr.js 173.26 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.46 kB 0%
static/js/it.js 158.13 kB 0%
static/js/narrow.js 358.79 kB 0%
static/js/nb-NO.js 141.55 kB 0%
static/js/nl.js 119.14 kB 0%
static/js/pt-BR.js 181.5 kB 0%
static/js/th.js 173.33 kB 0%
static/js/theme.js 31.02 kB 0%
static/js/uk.js 209.97 kB 0%
static/js/useTransactionBatchActions.js 9.71 kB 0%
static/js/wide.js 305.07 kB 0%
static/js/workbox-window.prod.es5.js 7.21 kB 0%
static/js/zh-Hans.js 113.26 kB 0%

loot-core

Total

Files count Total bundle size % Changed
1 4.82 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
kcab.worker.RjHyOlEX.js 4.82 MB 0%

api

Total

Files count Total bundle size % Changed
2 3.87 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
index.js 3.87 MB 0%
models.js 0 B 0%

cli

Total

Files count Total bundle size % Changed
1 8.02 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 8.02 MB 0%

crdt

Total

Files count Total bundle size % Changed
1 11.12 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 11.12 kB 0%

@mannkind
mannkind requested a review from joel-jeremy as a code owner June 12, 2026 03:08
@actual-github-bot actual-github-bot Bot changed the title Mobile transaction updates field-level merging [WIP] Mobile transaction updates field-level merging Jun 12, 2026
@netlify

netlify Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit f453590
🔍 Latest deploy log https://app.netlify.com/projects/actualbudget/deploys/6a3955f82dbee100098be5f9
😎 Deploy Preview https://deploy-preview-8196.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hello contributor!

We would love to review your PR! Before we can do that, please make sure:

  • ✅ All CI checks pass
  • ✅ The PR is moved from draft to open (if applicable)
  • ✅ The "[WIP]" prefix is removed from the PR title
  • ✅ The PR description follows the provided template, with all checklist boxes filled in
  • ✅ All CodeRabbit code review comments are resolved (if you disagree with anything - reply to the bot with your reasoning so we can read through it). The bot will eventually approve the PR.
  • ✅ Any AI usage is disclosed (see our AI Usage Policy)

A quick note on volume: please get one PR reviewed and merged before opening several more. A stack of simultaneous, similar PRs from one author is reviewed slowly, and low-effort, untested, or undisclosed-AI PRs may be closed without a detailed review.

We do this to reduce the TOIL the core contributor team has to go through for each PR and to allow for speedy reviews and merges.

For more information, please see our Contributing Guide.

@mannkind mannkind changed the title [WIP] Mobile transaction updates field-level merging [WIP] [AI] Mobile transaction updates field-level merging Jun 12, 2026
@coderabbitai

coderabbitai Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR fixes a race condition in the mobile transaction editor where auto-fill rule updates could overwrite in-flight transaction changes. It introduces changedFields tracking and functional state updates to safely merge only modified fields, and updates release notes to document the bugfix.

Changes

Transaction state concurrency fix

Layer / File(s) Summary
Transaction state race condition fix
packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx
When applying auto-fill rules to temporary transactions, a changedFields set now tracks field modifications. Rule execution explicitly marks subtransactions as changed and merges only tracked fields onto the latest transaction state via functional setTransactions(prev => ...) before applying updateTransaction, avoiding race conditions from stale state references. Hook dependencies are tightened by removing transactions.
Release notes entry
upcoming-release-notes/8196.md
Release notes document the fix for an issue where entered amounts could be lost when interacting with the Nearby payee chip before the input field loses focus.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

size small

Suggested reviewers

  • joel-jeremy
  • MatissJanis

Poem

🐰 A race condition hops away,
Changed fields gather what must stay,
Functional merges, steady and bright,
Keep amounts safe through day and night,
Hooray — transactions sleep tonight!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately reflects the main change: implementing field-level merging for mobile transaction updates to fix a race condition.
Description check ✅ Passed The PR description clearly explains the reported issue (entered amount lost when tapping Nearby payee), the suspected race condition with concurrent updates, and the attempted fix. It is directly related to the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx (1)

1820-1848: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Don't merge subtransactions as a stale whole-array snapshot.

This still loses concurrent split edits. newTransaction.subtransactions is built before the functional state update, so if a child split changes while the rule run is in flight, Line 1846 copies the stale child objects onto merged. updateTransaction(...) then treats that array as originalSubtransactions, so the later parent update can wipe the child’s newer fields. Merge only the affected child field(s) onto latestTransaction.subtransactions inside the updater instead of assigning the stale array wholesale.

💡 Suggested direction
-        const merged = { ...latestTransaction };
-        for (const field of changedFields) {
-          (merged as Record<string, unknown>)[field] = newTransaction[field];
-        }
+        const merged = { ...latestTransaction };
+        for (const field of changedFields) {
+          if (
+            field === 'subtransactions' &&
+            latestTransaction.is_parent &&
+            latestTransaction.subtransactions &&
+            newTransaction.subtransactions
+          ) {
+            merged.subtransactions = latestTransaction.subtransactions.map(
+              latestSubtransaction => {
+                const nextSubtransaction = newTransaction.subtransactions?.find(
+                  subtransaction => subtransaction.id === latestSubtransaction.id,
+                );
+
+                if (!nextSubtransaction) {
+                  return latestSubtransaction;
+                }
+
+                return {
+                  ...latestSubtransaction,
+                  [updatedField]: nextSubtransaction[updatedField],
+                };
+              },
+            );
+            continue;
+          }
+
+          (merged as Record<string, unknown>)[field] = newTransaction[field];
+        }

Based on packages/loot-core/src/shared/transactions.ts:260-298, updateTransaction(...) rebases parent updates from transaction.subtransactions whenever that property is present.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx`
around lines 1820 - 1848, The updater is copying the pre-built
newTransaction.subtransactions array (which may be stale) onto merged, risking
lost concurrent child edits; instead, inside the setTransactions functional
updater where you find latestTransaction, handle the 'subtransactions' case
specially: for each changed child index/field present in
newTransaction.subtransactions, merge only those specific child fields onto
latestTransaction.subtransactions[index] (preserving other properties and other
children's newer values) before calling updateTransaction; keep the per-field
loop for changedFields but replace the wholesale assignment of
newTransaction.subtransactions with a targeted per-child merge into
merged.subtransactions so updateTransaction receives a rebased array rather than
a stale snapshot.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@upcoming-release-notes/8196.md`:
- Line 6: Replace the hedged release-note heading "Attempt to fix entered amount
being lost sometimes when tapping the Nearby payee chip before field loses
focus" with a definitive, concise statement of the shipped behavior; for example
use "Fixed an issue where an entered amount could be lost when tapping Nearby
before the amount field lost focus" (locate the original string in
upcoming-release-notes/8196.md and update it accordingly).

---

Outside diff comments:
In
`@packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx`:
- Around line 1820-1848: The updater is copying the pre-built
newTransaction.subtransactions array (which may be stale) onto merged, risking
lost concurrent child edits; instead, inside the setTransactions functional
updater where you find latestTransaction, handle the 'subtransactions' case
specially: for each changed child index/field present in
newTransaction.subtransactions, merge only those specific child fields onto
latestTransaction.subtransactions[index] (preserving other properties and other
children's newer values) before calling updateTransaction; keep the per-field
loop for changedFields but replace the wholesale assignment of
newTransaction.subtransactions with a targeted per-child merge into
merged.subtransactions so updateTransaction receives a rebased array rather than
a stale snapshot.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: abd0b271-37dc-4f1b-80a6-89afb83f7aca

📥 Commits

Reviewing files that changed from the base of the PR and between e6811e8 and 60399ef.

📒 Files selected for processing (2)
  • packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx
  • upcoming-release-notes/8196.md

Comment thread upcoming-release-notes/8196.md Resolved
@coderabbitai coderabbitai Bot removed the size small label Jun 12, 2026
@mannkind mannkind changed the title [WIP] [AI] Mobile transaction updates field-level merging [AI] Mobile transaction updates field-level merging Jun 12, 2026

@MatissJanis MatissJanis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense

RafaelEspino pushed a commit to RafaelEspino/actual that referenced this pull request Oct 28, 2026
…earby payee chip before field loses focus (actualbudget#8196)

Co-authored-by: Matiss Janis Aboltins <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants