You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Due for payment 2026-05-12] [$250] Don't fire duplicate ReconnectApp on delegate account switch #89271
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in review
This issue tracks the fix for duplicate ReconnectApp requests being fired when switching accounts via delegate access.
When a user switches accounts via delegate access, the app sends OpenApp and then an unnecessary ReconnectApp right after. The OpenApp already performs a full sync, making the subsequent ReconnectApp wasted work.
Root Cause: Race condition in Onyx update ordering during delegate account switching. Onyx.clear() wipes LAST_FULL_RECONNECT_TIME to empty, then when the OpenApp response arrives, applyHTTPSOnyxUpdates processes response.onyxData (containing server's NVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFORE) beforesuccessData (which sets LAST_FULL_RECONNECT_TIME). This causes subscribeToFullReconnect to see '' < serverTimestamp → true, firing a spurious ReconnectApp.
Recommended Fix: PR #89262 correctly addresses this by seeding LAST_FULL_RECONNECT_TIME with the current time before Onyx.clear() and preserving it through the clear, so the timestamp is already satisfied when the server NVP arrives.
Investigation details
Data flow:
User initiates delegate switch → Delegate.connect() calls Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS) — LAST_FULL_RECONNECT_TIME is NOT in the preserve list, so it gets wiped to ''
openApp() fires and server responds
applyHTTPSOnyxUpdates processes response.onyxData first → NVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFORE gets a real timestamp
Only then does successData set LAST_FULL_RECONNECT_TIME via App.ts:371-377 — too late
Alternative explanations considered:
Network reconnect or visibility change triggering ReconnectApp independently — ruled out; the timing (immediately after OpenApp response) points to the Onyx ordering race
Multiple openApp() calls — no evidence of this in the delegate flow
PR assessment: The fix in #89262 is correct and well-targeted. The new clearOnyxForDelegateTransition() helper sets LAST_FULL_RECONNECT_TIME to current time via Onyx.merge, then passes it as a preserved key to Onyx.clear(). Applied to all four relevant call sites: connect(), disconnect(), restoreDelegateSession(), and setupNewDotAfterTransitionFromOldDot().
Next Steps: Reply with @MelvinBot implement this to create a draft PR, or @MelvinBot <your feedback> to refine this analysis.
changed the title [-]Don't fire duplicate ReconnectApp on delegate account switch[/-][+][$250] Don't fire duplicate ReconnectApp on delegate account switch[/+]on Apr 30, 2026
Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS) wipes both LAST_FULL_RECONNECT_TIME and NVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFORE to ''. Then openApp() fires, and when the response arrives applyHTTPSOnyxUpdates applies onyxData before successData. This means NVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFORE gets set to a server timestamp first — the subscribeToFullReconnect subscriber fires with '' < serverTimestamp → reconnectApp() fires. Only afterwards does successData set LAST_FULL_RECONNECT_TIME to current time — too late.
The race isn't delegate-specific; it's structural: openApp() is already doing a full sync and will stamp LAST_FULL_RECONNECT_TIME via successData, but the NVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFORE check fires before that stamp lands.
What changes are needed?
Guard doFullReconnectIfNecessary() in subscribeToFullReconnect.ts with an isLoadingApp check. While openApp() is in progress (IS_LOADING_APP = true), a ReconnectApp is by definition redundant — the full sync is already underway and successData will set LAST_FULL_RECONNECT_TIME. Defer the check until loading completes:
// subscribeToFullReconnect.ts
let isLoadingApp = false;
Onyx.connectWithoutView({
key: ONYXKEYS.IS_LOADING_APP,
callback: (value) => {
isLoadingApp = value ?? false;
// Re-evaluate once openApp() finishes — catches the case where
// successData never ran (e.g. network failure) and LAST_FULL_RECONNECT_TIME is still empty
if (!isLoadingApp) {
doFullReconnectIfNecessary();
}
},
});
function doFullReconnectIfNecessary() {
if (lastFullReconnectTime >= reconnectAppIfFullReconnectBefore) {
return;
}
if (isLoadingApp) {
// openApp() is in progress and will set LAST_FULL_RECONNECT_TIME via successData
return;
}
Log.info('Full reconnect triggered', false, {lastFullReconnectTime, reconnectAppIfFullReconnectBefore});
reconnectApp();
}
Why this over alternatives?
Single file, no new helpers: Everything lives in subscribeToFullReconnect.ts. No need to touch KEYS_TO_PRESERVE_DELEGATE_ACCESS, no new wrapper function, no changes across 4 call sites in Delegate.ts.
Fixes the conceptual invariant, not the symptom:ReconnectApp should never fire while openApp() is running — that's the invariant. Encoding it here is cleaner than pre-seeding LAST_FULL_RECONNECT_TIME before every Onyx.clear() call.
HandlesopenApp()failure correctly: If openApp() fails and successData never runs, IS_LOADING_APP transitions to false via finallyData, which re-triggers doFullReconnectIfNecessary(). At that point LAST_FULL_RECONNECT_TIME is still empty and reconnect fires correctly — better behavior than the status quo.
Not delegate-specific: Works for any flow that calls openApp(), protecting against the same race in future contexts.
Tests:
Unit test in subscribeToFullReconnect tests: set NVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFORE while IS_LOADING_APP=true → verify reconnectApp() is NOT called.
Verify reconnectApp() IS called once IS_LOADING_APP becomes false with LAST_FULL_RECONNECT_TIME still empty (failure path).
Regression: normal network recovery (IS_LOADING_APP=false) still triggers reconnect correctly.
Please re-state the problem that we are trying to solve in this issue.
The app fires duplicate ReconnectApp requests when switching accounts via delegate access, which is unnecessary since the OpenApp call already performs a full sync.
What is the root cause of that problem?
I dug into this and found that the issue starts in src/libs/actions/Delegate.ts. When we switch accounts using delegate access, Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS) wipes both LAST_FULL_RECONNECT_TIME and NVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFORE to empty strings. Then when the OpenApp response arrives in src/libs/actions/OnyxUpdates.ts, the function applyHTTPSOnyxUpdates applies response.onyxData (which contains the server's timestamp for NVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFORE) before it processes successData (which sets LAST_FULL_RECONNECT_TIME). This causes a race condition where subscribeToFullReconnect.ts triggers a reconnectApp() call unnecessarily.
What changes do we need to make in order to solve the problem?
We should modify src/libs/actions/Delegate.ts so when switching accounts, LAST_FULL_RECONNECT_TIME is set to a current timestamp right after clearing Onyx keys but before triggering the OpenApp. This will prevent subscribeToFullReconnect.ts from thinking we need a full reconnect.
Here's how we can fix it:
// In src/libs/actions/Delegate.ts, around line 196-203Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS).then(()=>{// Set LAST_FULL_RECONNECT_TIME to current time before OpenApp is triggeredreturnOnyx.merge(ONYXKEYS.LAST_FULL_RECONNECT_TIME,DateUtils.getDBTime());}).then(openApp);
That the timestamp for LAST_FULL_RECONNECT_TIME is always up-to-date right after clearing and before any checks in subscribeToFullReconnect.ts, preventing unnecessary duplicate ReconnectApp calls.
[Contributor] The offending PR and associated issue have been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
[Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion: N/A
[Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in review
Activity
MelvinBot commentedon Apr 30, 2026
Issue Analysis
Root Cause: Race condition in Onyx update ordering during delegate account switching.
Onyx.clear()wipesLAST_FULL_RECONNECT_TIMEto empty, then when theOpenAppresponse arrives,applyHTTPSOnyxUpdatesprocessesresponse.onyxData(containing server'sNVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFORE) beforesuccessData(which setsLAST_FULL_RECONNECT_TIME). This causessubscribeToFullReconnectto see'' < serverTimestamp→ true, firing a spuriousReconnectApp.Recommended Fix: PR #89262 correctly addresses this by seeding
LAST_FULL_RECONNECT_TIMEwith the current time beforeOnyx.clear()and preserving it through the clear, so the timestamp is already satisfied when the server NVP arrives.Investigation details
Data flow:
Delegate.connect()callsOnyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS)—LAST_FULL_RECONNECT_TIMEis NOT in the preserve list, so it gets wiped to''openApp()fires and server respondsapplyHTTPSOnyxUpdatesprocessesresponse.onyxDatafirst →NVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFOREgets a real timestampsubscribeToFullReconnect.tsfires:'' < serverTimestamp→ triggersreconnectApp()(duplicate)successDatasetLAST_FULL_RECONNECT_TIMEviaApp.ts:371-377— too lateAlternative explanations considered:
openApp()calls — no evidence of this in the delegate flowPR assessment: The fix in #89262 is correct and well-targeted. The new
clearOnyxForDelegateTransition()helper setsLAST_FULL_RECONNECT_TIMEto current time viaOnyx.merge, then passes it as a preserved key toOnyx.clear(). Applied to all four relevant call sites:connect(),disconnect(),restoreDelegateSession(), andsetupNewDotAfterTransitionFromOldDot().Next Steps: Reply with
@MelvinBot implement thisto create a draft PR, or@MelvinBot <your feedback>to refine this analysis.melvin-bot commentedon Apr 30, 2026
Current assignee @abzokhattab is eligible for the External assigner, not assigning anyone new.
[-]Don't fire duplicate ReconnectApp on delegate account switch[/-][+][$250] Don't fire duplicate ReconnectApp on delegate account switch[/+]melvin-bot commentedon Apr 30, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022049849402501236092
oqildev commentedon Apr 30, 2026
Proposal
Root cause?
Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS)wipes bothLAST_FULL_RECONNECT_TIMEandNVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFOREto ''. ThenopenApp()fires, and when the response arrivesapplyHTTPSOnyxUpdatesappliesonyxDatabeforesuccessData. This meansNVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFOREgets set to a server timestamp first — thesubscribeToFullReconnectsubscriber fires with'' < serverTimestamp→reconnectApp()fires. Only afterwards doessuccessDatasetLAST_FULL_RECONNECT_TIMEto current time — too late.The race isn't delegate-specific; it's structural:
openApp()is already doing a full sync and will stampLAST_FULL_RECONNECT_TIMEviasuccessData, but theNVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFOREcheck fires before that stamp lands.What changes are needed?
Guard
doFullReconnectIfNecessary()insubscribeToFullReconnect.tswith anisLoadingAppcheck. WhileopenApp()is in progress(IS_LOADING_APP = true), a ReconnectApp is by definition redundant — the full sync is already underway andsuccessDatawill setLAST_FULL_RECONNECT_TIME. Defer the check until loading completes:Why this over alternatives?
subscribeToFullReconnect.ts. No need to touchKEYS_TO_PRESERVE_DELEGATE_ACCESS, no new wrapper function, no changes across 4 call sites inDelegate.ts.ReconnectAppshould never fire whileopenApp()is running — that's the invariant. Encoding it here is cleaner than pre-seedingLAST_FULL_RECONNECT_TIMEbefore everyOnyx.clear()call.openApp()failure correctly: IfopenApp()fails andsuccessDatanever runs,IS_LOADING_APPtransitions to false viafinallyData, which re-triggersdoFullReconnectIfNecessary(). At that pointLAST_FULL_RECONNECT_TIMEis still empty and reconnect fires correctly — better behavior than the status quo.openApp(), protecting against the same race in future contexts.Tests:
NVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFOREwhileIS_LOADING_APP=true→ verifyreconnectApp()is NOT called.reconnectApp()IS called onceIS_LOADING_APPbecomes false withLAST_FULL_RECONNECT_TIMEstill empty (failure path).(IS_LOADING_APP=false)still triggers reconnect correctly.ProjectNOVACo commentedon Apr 30, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
The app fires duplicate
ReconnectApprequests when switching accounts via delegate access, which is unnecessary since theOpenAppcall already performs a full sync.What is the root cause of that problem?
I dug into this and found that the issue starts in
src/libs/actions/Delegate.ts. When we switch accounts using delegate access,Onyx.clear(KEYS_TO_PRESERVE_DELEGATE_ACCESS)wipes bothLAST_FULL_RECONNECT_TIMEandNVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFOREto empty strings. Then when theOpenAppresponse arrives insrc/libs/actions/OnyxUpdates.ts, the functionapplyHTTPSOnyxUpdatesappliesresponse.onyxData(which contains the server's timestamp forNVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFORE) before it processessuccessData(which setsLAST_FULL_RECONNECT_TIME). This causes a race condition wheresubscribeToFullReconnect.tstriggers areconnectApp()call unnecessarily.What changes do we need to make in order to solve the problem?
We should modify
src/libs/actions/Delegate.tsso when switching accounts,LAST_FULL_RECONNECT_TIMEis set to a current timestamp right after clearing Onyx keys but before triggering theOpenApp. This will preventsubscribeToFullReconnect.tsfrom thinking we need a full reconnect.Here's how we can fix it:
That the timestamp for
LAST_FULL_RECONNECT_TIMEis always up-to-date right after clearing and before any checks insubscribeToFullReconnect.ts, preventing unnecessary duplicateReconnectAppcalls.ProjectNOVACo commentedon Apr 30, 2026
📋 Contributor details
12 remaining items
melvin-bot commentedon May 5, 2026
@abzokhattab Eep! 4 days overdue now. Issues have feelings too...
melvin-bot commentedon May 7, 2026
Triggered auto assignment to @mallenexpensify (
Awaiting Payment)melvin-bot commentedon May 12, 2026
Payment Summary
Upwork Job
BugZero Checklist (@mallenexpensify)
mallenexpensify commentedon May 13, 2026
Payment Summary
Contributor+: @abzokhattab due $250 via NewDot
@abzokhattab plz complete the BZ checklist and tag me in a post once you have. Thx
abzokhattab commentedon May 15, 2026
BugZero Checklist:
[Contributor] The offending PR and associated issue have been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.
Link to the comment on the PR: https://github.com/Expensify/App/pull/47338/changes#r3245089692
[Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.
Link to discussion: N/A
[Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.
[BugZero Assignee] Create a GH issue for creating/updating the regression test once above steps have been agreed upon.
Link to issue: https://github.com/Expensify/Expensify/issues/637603
Regression Test Proposal
Precondition:
Test:
ReconnectAppReconnectAppis NOT called afterOpenAppReconnectAppis NOT called afterOpenAppDo we agree 👍 or 👎
Zapier Logs
Run ID: 00040eee-dc0a-ab56-e027-81933595e194quinthar commentedon Jun 7, 2026
Approved $250 to @abzokhattab