Recalculate the account after a Wise linked-balance processing failure #6139
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #6139"
general
weight: 0.35
jaysbeekay
Closes #6105
Fork pre-flight: jaysbeekay/sure#1060 (same branch,
up/wise-linked-failure-sync, same commit).Summary
When
WiseItem::ProcessLinkedAccountJobfails while processing a newly linked balance, after the processor has committed transactions, the account is now recalculated, as on success. Before, the rescue only logged, so the booked entries had no materialised balances, no completed Sync for the family caches and no transfer matching until the next connection sync.What changed
account.sync_lateronce it has logged. The processor commits rows one by one, and a raise loses the signal of whether any were committed, so the job recalculates either way; without new rows the account sync re-materialises balances that are already right.sync_laterjoins a visible sync, so it does not duplicate one the connection's own sync scheduled.sync_latermoves to the rescue'selsebranch, so a failure to schedule is not logged as a failed process and is not tried twice.DebugLogEntry(providerwise, the balance's account provider, the error class), so it never turns a logged failure into a failed job. Nothing is scheduled when the account itself could not be read.ActiveRecord::Deadlockedbranch is unchanged.Non-test diff: +27 / -2 in
app/jobs/wise_item/process_linked_account_job.rb.Left out: making the processor transactional (the job comment explains why), retrying, the current balance after an
update_balance!failure (a:reverseaccount sync does not writeaccounts.balance), a sync already running when the rows commit (the success path has the same gap), andWiseItem::SyncerPhase 3 callinglink_jar_transfers!without a rescue.Demo data
No demo data needed: no Wise data in the demo generator, and this is a failure path.
Migration notes
No migration.
Verification
main7e8693344: "recalculates the account when processing fails after booking its transactions" failed withsyncs.count didn't change by 1, but by 0; the updated "logs a processing failure for support instead of raising" withExpected: 1 Actual: 0. The deadlock test (now asserting no Sync), "does not recalculate the account when jar linking fails" and "a failure before the account is read" pass onmain, as guards.edae65b46: "does not recalculate the account when jar linking fails" (syncs changed by 1, expected 0); "a sync_later failure after success is logged once as a scheduling failure" (logged as "Failed to process"); "a sync_later failure after a processing failure is logged for support" (DebugLogEntry+1, expected +2).elserecalculation removed (the success test and the success scheduling test);sync_laterback in the body (scheduling test logs "Failed to process"); the stage never set (both processing-failure tests);recalculate's rescue removed (the scheduling-failure test raises); itsDebugLogEntryremoved (both scheduling tests); theAccount#update!stub removed (first positive test,DebugLogEntry0, expected 1).bin/rails test test/jobs/wise_item test/models/wise_item test/models/wise_item_test.rb test/models/wise_account/processor_test.rb: 254 runs, 0 failures.ApplicationJob'sretry_onretries the job, on both the success and the processing-failure path; any other scheduling failure is still logged. The failure log's metadata names the stage that failed (loading,processingorlinking). "retries a deadlock scheduling the recalculation" failed before withNo enqueued job found; the stage tests failed withActual: nil.bin/rails teston3d7c7b18b: 20282 runs, 0 failures, 8 errors (allReleaseNotesWorkflowTest:nodeis missing from the local test image), 9 skips.Blast radius
The job is queued only from
WiseItem#sync_linked_account_later, whichWiseItemsController#complete_account_setup,#link_accountsand#link_existing_accountcall. Nothing else calls the job or reads its result.account.sync_lateris the call the success path already makes. #5278 addscategorize_card_refunds!beforesync_laterinside the samebegin, so a failure there is covered by this rescue too; #4740 changes only the header comment.<!-- This is an auto-generated description by cubic. -->
---
Summary by cubic
Closes we-promise/sure#6105.
When
WiseItem::ProcessLinkedAccountJobfails after the processor has booked transactions for a newly linked Wise balance, the account is now recalculated as on success. The failure path previously only logged, so committed entries went without materialised balances, a completed Sync, or transfer matching until the next connection sync.account.sync_later; after a linking failure it does not, so the account sync's transfer matching doesn't see unlinked legs.sync_latermoves to the rescue'selsebranch, so a scheduling failure is logged as such and not tried twice.DebugLogEntryinstead of raising, so it can't turn a logged failure into a failed job.<sup>Written for commit acbde6cbba620589778a200f545f59592e3753aa. Summary will update on new commits.</sup>
<a href="https://cubic.dev/pr/we-promise/sure/pull/6139?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
Bug Fixes
Account balances are now refreshed after successful linked-account processing and after processing errors, helping keep account information current.
Failures while linking an account no longer trigger an unnecessary refresh.
Deadlocks during processing or account refresh are retried, while other errors continue to be logged without automatic retries.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->