Skip to content

Refresh policy connections after an external accounting setup handoff - #100360

Closed
MelvinBot wants to merge 5 commits into
mainfrom
claude-xeroConnectionsRefresh
Closed

MelvinBot wants to merge 5 commits into
mainfrom
claude-xeroConnectionsRefresh

Conversation

@MelvinBot

Copy link
Copy Markdown
Contributor

Explanation of Change

The Vendors switch on Workspace > More features stays locked OFF after connecting Xero, and only flips ON after a manual "Sync now".

NewDot lazy-loads policy.connections behind policyHasConnectionsDataBeenFetched_<policyID>, which openPolicyAccountingPage sets write-once with no invalidation path. Xero setup runs outside NewDot (OldDot in a browser tab on web, an in-app WebView on native), so the connection is created after that flag was already set — the client keeps serving the copy it fetched before the connection existed. The switch reads isXeroVendorMatchingActive → policy.connections.xero.config.isConfigured, a server-only field, so it renders visible but OFF. SyncPolicyToXero returns fresh connections in its read response, which is why a manual re-sync is currently the only repair.

This adds a bounded "connections are stale" marker set at each Xero handoff, and re-reads the config when the app or the screen regains focus.

Two details worth calling out for review:

  1. Both focus triggers are needed — they are not redundant. On web the setup opens OldDot in a separate browser tab, so the user returns to an already-mounted screen and only the window focus event fires. On native the setup runs in an in-app WebView, so the app is never backgrounded, AppState never leaves active, and useAppFocusEvent never fires — there the screen regaining focus is the only signal. Each platform's blind spot is the other's signal.

  2. The marker is a deadline, not a one-shot flag. The sync the setup starts is asynchronous, so a refresh can land before the sync does. Consuming the marker on that first response would clear it while isConfigured is still false and strand the stale value exactly as before — reproducing the reported bug. Instead the marker is cleared only once the connection reports isConfigured, or once its 15-minute window passes. This also makes the marker immune to the refetch the still-mounted screen fires the moment it is set: that read is just one of several attempts in the window rather than the only one.

What this deliberately does not do, per the approved proposal: it does not remove the config.isConfigured predicate (it guards against selecting stale contacts during a Xero tenant switch), does not gate row visibility on hasVendorFeature, does not set isConfigured optimistically, and does not refetch unconditionally on every mount. A connection that is genuinely still syncing or failed still renders OFF, which is correct.

Scoping note: the stale-flag semantics affect every usePolicyConnectionsPrefetch consumer, but the marker is only set by the Xero setup handoff, so routine network traffic is unchanged.

Follow-up worth considering separately: policyConnectionSyncProgress_<policyID> receives server-pushed stage updates and would be a truer "the server now has fresh config" trigger than focus. It was left out here to keep the change scoped, and because Pusher updates are dropped by non-leader tabs — which is exactly the web case, since the handoff opens a second tab.

Fixed Issues

$ #99986
PROPOSAL: #99986 (comment)

Tests

// TODO: The human co-author must fill out the tests you ran before marking this PR as "ready for review".
// Please describe what tests you performed that validate your change worked.
// Note: reproducing this needs a real Xero OAuth connection plus the vendorMatching beta, so it could not be automated.

  • Verify that no errors appear in the JS console

Offline tests

The refresh is skipped entirely while offline — usePolicyConnectionsPrefetch returns early on isOffline, and the stale marker is left in place so the re-read happens on the next focus after reconnecting. This is covered by an automated test (does not refresh while offline).

QA Steps

// TODO: These must be filled out, or the issue title must include "[No QA]."
// The human co-author must fill out the QA steps before marking this PR as "ready for review".
// Please describe what QA needs to do to validate your changes and what areas they need to test for regressions.

  • Verify that no errors appear in the JS console

AI Tests

Run locally by MelvinBot on this branch:

Check Result
npm run typecheck ✅ passed
npm run lint-changed ✅ passed
npm run spell-changed ✅ passed
npm run react-compiler-compliance-check check <changed files> ✅ passed (exit 0)
npm test — 9 affected suites ✅ 469 passed
npm test tests/unit/hooks — all hook suites ✅ 1614 passed (157 suites)

Affected suites run: usePolicyConnectionsPrefetch.test.ts (new), DynamicSuccessPageTest.tsx (new), ConnectToXeroFlowTest.tsx, ConnectToXeroFlowWebTest.tsx, WorkspaceMoreFeaturesPageTest.tsx, PolicyUtilsTest.ts, PolicyConnectionsTest.ts, WorkspaceInitialPageTest.tsx, ProductMarketingWindowTest.tsx.

Could not run:

  • Full npm test suite — exceeded the 10-minute local command cap. All hook suites were run instead, since the change touches a shared hook. CI runs the full suite.
  • npm run prettier — no such script exists in package.json at this commit; formatting is enforced through npm run lint-changed.
  • npm run storybook -- --smoke-test --ci — not run; no Storybook stories are touched by this change.
  • Browser smoke test — the CI-provided web session was unresponsive (blank page, 0 DOM nodes, no network activity) and could not be driven to Home. The dev server itself responded 200, so this is a session infra failure, not a code failure.

New regression coverage added:

  • The marker is set at all three Xero setup entry points (web flow, native flow, 2FA-success bypass) and not set when the 2FA requirement blocks the handoff.
  • Refresh fires on app focus (web signal) and on screen focus (native signal).
  • A refresh landing mid-sync keeps the marker; the marker clears once isConfigured is true, and once the window passes.
  • More features renders the Vendors switch locked ON for a configured Xero connection and locked OFF for one that is not configured.

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

The lazy connections fetch is gated on policyHasConnectionsDataBeenFetched_<policyID>,
which is set write-once and never invalidated. A connection created after that fetch —
Xero setup runs outside NewDot — is therefore invisible to the client until a manual
re-sync, so the Vendors switch on More features stays locked OFF.

Mark the policy's connections stale at each Xero handoff and re-read them when the app
or the screen regains focus. Both triggers are needed: on web the setup opens OldDot in
a separate browser tab so only window focus fires, while on native it runs in an in-app
WebView so the app never backgrounds and only screen focus fires.

The marker is a deadline rather than a one-shot flag because the sync the setup starts is
asynchronous. A single refresh can land before the sync does, and consuming the marker
there would strand the stale value exactly as before.

Co-authored-by: Chuck Dries <chuckdries@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team September 3, 2026 21:06
@melvin-bot melvin-bot Bot added Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web labels Sep 3, 2026
@MelvinBot

MelvinBot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Web test steps verification results: ⚠️ partial

Reached More features on a newly-created workspace on PR branch claude-xeroConnectionsRefresh, but the test account has no Xero connection (fresh account, no OAuth possible in this sandboxed session), so the Vendors row never renders and the switch-state bug could not be exercised. Note the PR's own Tests section is still a // TODO placeholder, so these steps come from the repro in #99986.

Accounting connections page showing Xero with an unclicked Connect button, confirming no Xero connection exists

Step Status
1. Open a workspace that has a configured Xero connectionAccount had zero workspaces ("No workspaces yet"). Created one to proceed, but its Accounting → Connections page shows Xero with a "Connect" button (not connected) — no OAuth was performed, since that requires external Xero credentials and an off-app redirect that would kill the pinned test session.
Workspaces list showing 'No workspaces yet' on the fresh test account
Accounting connections page showing Xero with an unclicked Connect button, confirming no Xero connection exists
❌
2. Navigate to Settings → Workspace → More featuresReached the More features page for the newly created workspace via Workspaces → [workspace] → More features.
More features page with Accounting toggle on but no Vendors row present
✅
3. Locate the Vendors row on the More features pageVendors row is absent — 55 rows enumerated (Accounting, HR, Receipt partners, Categories, Tags, Taxes, Workflows, Rules, Distance rates, Travel, Expensify Card, Company cards, Per diem, Time, Invoices), no Vendors. Expected: the row is gated on the policy having a connected QBO/Xero/Sage Intacct integration, which this workspace lacks.
More features page with Accounting toggle on but no Vendors row present
❌
4. Observe the Vendors switch is locked ON with Xero correctly configuredNot observable — the Vendors row and switch do not render without an active Xero connection, so no pass or fail evidence for the switch's ON/OFF state could be gathered.
❌

No console errors were captured during the run.

What a real verification needs: a pre-provisioned workspace with a completed Xero OAuth connection, plus the vendorMatching beta on the account. This CI session can create neither — it gets a fresh account each run and cannot complete a third-party OAuth redirect. The ❌ marks above mean "could not be exercised," not "the fix is broken." The PR's automated coverage (usePolicyConnectionsPrefetch.test.ts, WorkspaceMoreFeaturesPageTest.tsx) is currently the only evidence for this behavior.


view run · no recording available

…props in the 2FA success test

The Onyx key export coverage test requires every ONYXKEYS.COLLECTION value to sit in an export bucket. policyConnectionsRefreshDeadline_ holds only a timestamp, so it goes in safeOnyxKeys next to policyHasConnectionsDataBeenFetched_.

DynamicSuccessPage takes the full PlatformStackScreenProps, so the test has to supply navigation as well as route.

Co-authored-by: Chuck Dries <chuckdries@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Both real failures were caused by this PR. Fixed and pushed in bbb356b.

Check Cause Fix
test (job 5) — ExportOnyxStateTest The new policyConnectionsRefreshDeadline_ collection key wasn't in any export bucket. That test asserts every ONYXKEYS.COLLECTION value is sorted into one. Added it to safeOnyxKeys — it holds only a timestamp — next to policyHasConnectionsDataBeenFetched_: src/libs/ExportOnyxState/common.ts:189
typecheck DynamicSuccessPage takes the full PlatformStackScreenProps, but the new test passed only route, so navigation was missing. Build both props and spread them: tests/unit/pages/DynamicSuccessPageTest.tsx:66-74

Check independent approval is also red, but that's the human review gate, not a code failure.

Verified locally on the pushed commit
Check Result
npm run typecheck ✅ passed
npm test — ExportOnyxStateTest, DynamicSuccessPageTest, usePolicyConnectionsPrefetch ✅ 40 passed, 3 suites
npx eslint on both changed files ✅ no errors
npm run spell-changed on both changed files ✅ 0 issues
oxfmt (via npm run fmt) ✅ no reformatting produced
npm run react-compiler-compliance-check check <changed files> ✅ passed (exit 0)

npm run lint-changed and the unqualified npm run spell-changed both bail out on git merge-base in this shallow checkout, so I ran ESLint and cspell against the two changed files directly instead.


view run

@MelvinBot

MelvinBot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Android test steps verification results: ⚠️ partial

Reached More features on the account's only workspace at PR head bbb356b, but the workspace has no accounting connection configured (Accounting toggle OFF, no Vendors row present), so the Xero-specific Vendors-switch bug from #99986 could not be reproduced or verified on this fresh test account. Note the PR's own Tests section is still a // TODO placeholder, so these steps come from the repro in the linked issue.

Android More features page showing Accounting toggle OFF and no Vendors row present

Step Status
1. Open a workspace that has a configured Xero connectionAccount has exactly one workspace ("Melvin Bot's Workspace"). Its More features page shows the Accounting toggle in the OFF state, confirming no accounting integration (Xero or otherwise) is connected. No second workspace exists on this account to try instead. Establishing a real Xero OAuth connection needs external Xero credentials, which this run does not have.
❌
2. Navigate to Settings → Workspace → More featuresNavigated Workspaces tab → workspace → More features. Snapshot confirms the page rendered with its feature toggles (Accounting, HR, Receipt partners, Categories, Tags, Taxes).
Android More features page showing Accounting toggle OFF and no Vendors row present
✅
3. Locate the Vendors row on the More features pageVendors is a sub-feature that only appears once an accounting integration is connected. With Accounting OFF, a search for "Vendors" returned no match anywhere on screen — the row does not exist for this account.
Android More features page — Vendors row absent because no accounting connection exists
❌
4. Observe the Vendors switch is locked ON with Xero correctly configuredNot observable — blocked upstream by steps 1 and 3. No Xero connection exists on the account and no Vendors row renders, so no pass or fail evidence for the switch's ON/OFF state could be gathered.
❌

The tester also completed first-run onboarding (purpose selection, name entry, work-email skip) to reach a usable Home state, since CI handed over a brand-new account. No console errors were captured.

What a real verification needs: a workspace pre-seeded with a completed Xero OAuth connection, plus the vendorMatching beta on the account. This CI session can provision neither — it gets a fresh account each run and cannot complete a third-party OAuth flow. The ❌ marks above mean "could not be exercised," not "the fix is broken." This matches the earlier Web run on this PR, which stalled at the same point. The PR's automated coverage (usePolicyConnectionsPrefetch.test.ts, WorkspaceMoreFeaturesPageTest.tsx) remains the only evidence for this behavior.


view run · view recording

@huult

huult commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot Could you please assign this PR to me?

@MelvinBot

MelvinBot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Done — you're now assigned to this PR alongside chuckdries.


view run · view recording

return;
}
// The connection this produces is created outside NewDot, so the lazily-fetched policy.connections copy
// this client already holds can't see it. Mark it stale before handing off so it gets re-read on return.

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.

@MelvinBot Could you remove this comment? The field name is self-explanatory, so I don't think we need a comment here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed in 091dc83.


view run

return;
}
// The connection this produces is created outside NewDot, so the lazily-fetched policy.connections copy
// this client already holds can't see it. Mark it stale before handing off so it gets re-read on return.

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.

@MelvinBot Could you remove this comment? The field name is self-explanatory, so I don't think we need a comment here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed in 091dc83.


view run

Comment thread src/CONST/index.ts Outdated
Comment on lines +4482 to +4484
// How long after an external accounting setup handoff NewDot keeps re-reading the policy's
// connection config on focus. The setup runs outside NewDot and the sync it starts is
// asynchronous, so the client has to keep looking for a while rather than refreshing once.

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.

@MelvinBot Could you remove this comment? The field name is self-explanatory, so I don't think we need a comment here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed in 091dc83.


view run

Comment on lines +49 to +56
// The lazy fetch above runs at most once per policy per device, so it can't pick up a connection that was
// created after it ran. `markPolicyConnectionsAsStale` marks that case, and the refresh below is what
// actually re-reads the config.
//
// The only flow that sets the marker today is the Xero setup handoff, and the field that handoff is
// expected to produce is `xero.config.isConfigured` — the same field the Vendors toggle reads. Checking it
// directly is what lets the marker survive a refresh that lands while the sync is still running, instead of
// clearing on the first response and stranding the stale value.

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.

@MelvinBot Could you remove this comment? The field name is self-explanatory, so I don't think we need a comment here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed in 091dc83.


view run

Comment on lines +60 to +63
// Two triggers, because neither one covers both platforms. On web the setup opens OldDot in a separate
// browser tab, so the user comes back to an already-mounted screen and only the window focus event fires.
// On native the setup runs in an in-app WebView, so the app is never backgrounded and `AppState` never
// leaves `active` — there the screen regaining focus is the only signal.

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.

@MelvinBot Could you remove this comment? The field name is self-explanatory, so I don't think we need a comment here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed in 091dc83.


view run

Comment thread src/libs/actions/PolicyConnections.ts Outdated
Comment on lines +45 to +59
/**
* Marks a policy's connection data as stale for a bounded window, so `usePolicyConnectionsPrefetch` re-reads
* it the next time the app or the screen regains focus.
*
* Call this whenever NewDot hands the user off to an external accounting setup flow. `openPolicyAccountingPage`
* sets `policyHasConnectionsDataBeenFetched_<policyID>` write-once and nothing invalidates it, so without this
* marker the client keeps serving the copy it fetched *before* the connection existed and never picks up the
* config that the setup produces.
*
* This is a deadline rather than a one-shot flag on purpose. The sync the setup starts is asynchronous, so the
* user can be back in NewDot before it lands; a one-shot refresh would then read a connection that is still not
* configured, consume itself, and leave the stale value in place until a manual re-sync. It also makes the
* marker immune to the refetch that the still-mounted screen fires the moment it is set — that read is simply
* one of several attempts within the window rather than the only one.
*/

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.

@MelvinBot Could you remove this comment? The field name is self-explanatory, so I don't think we need a comment here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed in 091dc83.


view run

Comment thread src/libs/actions/PolicyConnections.ts Outdated
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY_CONNECTIONS_REFRESH_DEADLINE}${policyID}`, Date.now() + CONST.POLICY.CONNECTIONS.REFRESH_AFTER_SETUP_WINDOW_MS);
}

/** Drops the stale marker set by `markPolicyConnectionsAsStale`, once the refresh has served its purpose or its window has passed. */

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.

@MelvinBot Could you remove this comment? The field name is self-explanatory, so I don't think we need a comment here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed in 091dc83.


view run

Comment on lines +121 to +122
// This path bypasses ConnectToXeroFlow, so it has to mark the connections stale itself — otherwise
// users who set up 2FA as part of connecting Xero keep the pre-connection policy.connections copy.

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.

@MelvinBot Could you remove this comment? The field name is self-explanatory, so I don't think we need a comment here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed in 091dc83.


view run

Comment thread src/ONYXKEYS.ts Outdated
Comment on lines +895 to +898
// Deadline (epoch ms) until which the policy's connection data is treated as stale and re-read
// whenever the app or the screen regains focus. Set when NewDot hands the user off to an external
// accounting setup flow. Like the flag above this is client-only state, so it lives outside the
// policy object.

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.

@MelvinBot Could you remove this comment? The field name is self-explanatory, so I don't think we need a comment here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed in 091dc83.


view run

Co-authored-by: huult <huult@users.noreply.github.com>
@MelvinBot

MelvinBot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Removed all nine commented blocks you flagged in 091dc83, and replied in each thread.

File What was removed
src/CONST/index.ts comment above REFRESH_AFTER_SETUP_WINDOW_MS
src/ONYXKEYS.ts comment above POLICY_CONNECTIONS_REFRESH_DEADLINE
src/components/ConnectToXeroFlow/index.tsx comment above markPolicyConnectionsAsStale
src/components/ConnectToXeroFlow/index.native.tsx comment above markPolicyConnectionsAsStale
src/hooks/usePolicyConnectionsPrefetch.ts both blocks (stale-marker rationale, two-triggers rationale)
src/libs/actions/PolicyConnections.ts JSDoc on markPolicyConnectionsAsStale and on clearPolicyConnectionsStaleMarker
src/pages/settings/Security/TwoFactorAuth/DynamicSuccessPage.tsx comment above markPolicyConnectionsAsStale

One thing worth your call: the markPolicyConnectionsAsStale JSDoc explained why it's a bounded deadline rather than a one-shot flag — a one-shot refresh can land while the Xero sync is still running, consume itself, and strand the stale value. That reasoning isn't recoverable from the name. Happy to restore a one-line version if you want it kept.

Checks run
  • ESLint on the seven changed files — 0 errors (6 pre-existing seatbelt warnings, untouched by this change)
  • npm run typecheck — passed
  • React Compiler compliance check on the four component/hook files — passed
  • Jest: ConnectToXeroFlowTest, ConnectToXeroFlowWebTest, usePolicyConnectionsPrefetch.test, DynamicSuccessPageTest, WorkspaceMoreFeaturesPageTest — 44 passed
  • npm run prettier isn't defined in this repo, so it was skipped

view run · no recording available

@MelvinBot

MelvinBot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor Author

There is nothing to fix in the code — the only failing check is waiting on a human.

PR Reviewer Checklist / checklist (run) fails with No PR Reviewer Checklist was found. The action scanned all 24 comments on this PR and none of them is the reviewer checklist. It will keep failing until the assigned reviewer (huult) posts it. Check independent approval is pending for the same reason.

Every code check passes on the current head: typecheck, ESLint, Oxfmt, spellcheck, React Compiler compliance, all 8 test jobs, Bun tests, Storybook, knip, unused styles, both perf-test jobs, and all four builds.

Full check status
Check Result
PR Reviewer Checklist / checklist ❌ fail — no reviewer checklist comment posted
Check independent approval ⏳ pending — awaiting review
typecheck, ESLint, Oxfmt, spellcheck ✅ pass
React Compiler Compliance ✅ pass
test jobs 1–8, Bun tests, Storybook tests ✅ pass
knip, unused styles, codecov patch + project ✅ pass
baseline-perf-tests, branch-perf-tests, validate-perf-tests ✅ pass
all 4 build jobs, CLA, verifySignedCommits ✅ pass

Relevant log lines from the failing run:

There are 43 items in the reviewer checklist.
Pulled 18 review comments, now adding them to the list...
Pulled 6 comments, now adding them to the list...
Looking through all 24 comments for the reviewer checklist...
##[error]No PR Reviewer Checklist was found

I did not push anything, since no code change would clear this check.


view run · view recording

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Nothing is broken in the code — there's no fix to push. Both failing checks are human-process gates waiting on a reviewer:

Check Why it's failing
PR Reviewer Checklist / checklist No PR Reviewer Checklist was found — no reviewer has posted the checklist comment yet.
Check independent approval The Verify peer review step fails because there's no independent approving review. The PR is still a draft and reviewDecision is REVIEW_REQUIRED.

Every code check passes on the current commit: typecheck, ESLint, Oxfmt, spellcheck, React Compiler Compliance, all 8 test jobs, Bun tests, Storybook tests, knip, Check for unused styles, both perf-test jobs, and all four builds.

To go green: huult posts the reviewer checklist and submits an approving review, then mark the PR ready for review. Both checks clear on their own after that — no commit needed.


view run

@huult

huult commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

@Beamanator After the Xero OAuth completes, does the backend automatically trigger a sync immediately (either synchronously or via a high-priority queue), or does it only enable autoSync.enabled=true and wait for the next scheduled sync cycle?

@Beamanator

Copy link
Copy Markdown
Contributor

@Beamanator After the Xero OAuth completes, does the backend automatically trigger a sync immediately (either synchronously or via a high-priority queue), or does it only enable autoSync.enabled=true and wait for the next scheduled sync cycle?

It looks like we automatically trigger a sync immediately when the oauth flow originated from NewDot - https://github.com/Expensify/Web-Expensify/blob/cf68a16343bd9482525012c128ca01d6877c8c44/partners/xero/oauth_callback.php#L128

@huult

huult commented Sep 7, 2026

Copy link
Copy Markdown
Contributor
Screen.Recording.2026-09-07.at.11.26.18.mov

@Beamanator I can't access the backend source. Could you check why Pusher doesn't immediately update isConfigured to true, and it remains false? isConfigured is only updated after I click "Sync Now". Could you also check whether isConfigured is updated during the initial sync? Thanks!

@huult

huult commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

@Beamanator I think we need to update the backend based on this. Could you check it and help me update it?

@huult

huult commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot Could you resolve the conflict?

Resolves conflict in src/libs/actions/PolicyConnections.ts: main added
openPolicyRecruitingPage to the export list while this branch added the
connections stale-marker helpers. Kept both.
@MelvinBot

MelvinBot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Conflict resolved and pushed — the PR is mergeable again.

There was one conflict, in src/libs/actions/PolicyConnections.ts:118. Both sides only edited the export list: main added openPolicyRecruitingPage, this branch added the two stale-marker helpers. I kept both.

export {openPolicyAccountingPage, openPolicyHRPage, openPolicyRecruitingPage, updateConnectionConfig, markPolicyConnectionsAsStale, clearPolicyConnectionsStaleMarker};

Merged with git merge main (merge commit 24a1e90), so every original commit is preserved — no rebase, squash, or force-push.

Verification

Three other files this PR touches were also changed on main and auto-merged. I checked each to confirm this PR's additions survived:

Checks run locally on the merge commit:

Check Result
npm run typecheck ✅ passed
npm run lint-changed ✅ passed (13 files)
npm run spell-changed ✅ 12 files, 0 issues
npm run react-compiler-compliance-check check <changed files> ✅ passed (exit 0)
npm test — 8 affected suites ✅ 448 passed

Suites run: usePolicyConnectionsPrefetch.test.ts, DynamicSuccessPageTest.tsx, ConnectToXeroFlowTest.tsx, ConnectToXeroFlowWebTest.tsx, WorkspaceMoreFeaturesPageTest.tsx, PolicyUtilsTest.ts, PolicyConnectionsTest.ts, WorkspaceInitialPageTest.tsx.

Could not run:

  • Full npm test suite — exceeds the local command time cap. CI runs it.
  • npm install — main bumped package.json / package-lock.json and several patches, but dependency installation is blocked in this environment. The checks above ran against the pre-merge node_modules. CI installs fresh, so treat CI as the authority on anything dependency-related.

mergeStateStatus is now BLOCKED rather than DIRTY — that is the review/checklist gate, not a conflict.


view run · no recording available

@Beamanator

Copy link
Copy Markdown
Contributor

yeah interesting, i think you're right so i made a PR to get that fix up sir 👍

@huult

huult commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

yeah interesting, i think you're right so i made a PR to get that fix up sir 👍

thank you 😄

@Beamanator

Copy link
Copy Markdown
Contributor

got the fix merged, not deployed yet 😬

@huult

huult commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

got the fix merged, not deployed yet 😬

Thank you! Tag me when it’s ready. I’ll retest it and continue checking this PR.

@huult huult mentioned this pull request Sep 11, 2026
3 tasks
@Beamanator

Copy link
Copy Markdown
Contributor

@huult deployed! Check again when you have time plz 🙏

@huult

huult commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot could you sync with main?

…sRefresh

Co-authored-by: huult <huult@users.noreply.github.com>
@huult

huult commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

@huult deployed! Check again when you have time plz 🙏

Screen.Recording.2026-09-12.at.22.31.20.mov

It’s working, thanks!

@MelvinBot

Copy link
Copy Markdown
Contributor Author

⚠️ MelvinBot CI Fix Loop Detected

MelvinBot has made 5 consecutive commits trying to fix CI failures. Automatic CI fix dispatches are now paused for this PR.

Next steps: A human should review the recent commits and resolve the conflicting CI errors manually.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Synced with main — merged and pushed as 7701daa2d59.

The branch was 1545 commits behind. The merge was conflict-free and tsc --noEmit passes on the result.

Details
  • Merged origin/main (6d42ea040fb) into claude-xeroConnectionsRefresh with git merge (no rebase, no force-push).
  • Of the files this PR touches, only src/CONST/index.ts, src/ONYXKEYS.ts, and src/libs/ExportOnyxState/common.ts also changed on main. All merged additively. The PR's core logic files (usePolicyConnectionsPrefetch.ts, PolicyConnections.ts, ConnectToXeroFlow/, DynamicSuccessPage.tsx) were untouched by main.
  • The PR diff against main is unchanged: 13 files, +400/-3.
  • I couldn't run Jest locally in this environment, so CI is the check on the test suites.

@huult

huult commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

@huult deployed! Check again when you have time plz 🙏

@MelvinBot The issue is gone after we fixed it on the backend side, so I don't think we need this PR anymore, right?

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Agreed — close it. The backend fix removes the cause; this PR was only a client-side workaround for it, and you've confirmed the bug is gone.

One thing to confirm with Beamanator first, and one correction worth recording.

Confirm: does the connections push carry an updateID in the account's reliable-update stream? If it does, every scenario this PR covered is already handled — offline during setup, tab closed mid-handoff, and dropped Pusher messages all recover via Reconnect.ts:38 replaying from lastUpdateIDAppliedToClient, plus OnyxUpdateManager gap detection. If it's a fire-and-forget broadcast, there's a narrow residual gap: a client that was closed or offline at that instant never gets it, and nothing else refetches (ReconnectApp doesn't return connections for non-active policies — see the note at withPolicyConnections.tsx:29).

Even if that gap is real, this PR isn't the right shape for it. The underlying defect is that policyHasConnectionsDataBeenFetched_<policyID> is set write-once on success at PolicyConnections.ts:20-26 and never invalidated anywhere in src/. QBO does the identical external handoff at ConnectToQuickbooksOnlineFlow/index.tsx:20 and gets nothing from this PR. Invalidating that flag generically would beat a Xero-only 15-minute polling window living in a hook that the whole workspace surface consumes.

Correction for the record: the PR description's web justification was wrong. It claimed "Pusher updates are dropped by non-leader tabs — which is exactly the web case, since the handoff opens a second tab." The setup tab is OldDot on a different origin, so it never joins NewDot's leader election and can't demote the NewDot tab. Backgrounding alone never demotes either, and nothing unsubscribes Pusher on blur.

Evidence for the leader-election correction
  • Pusher subscription is not leader-gated; only the handlers are, at User.ts:830 and User.ts:866.
  • Leader election re-runs on visibility change, but going background is an explicit no-op — Expensify.tsx:184-187. Demotion only happens when another NewDot tab becomes visible, or on unload.
  • OldDot is a separate origin, so it can't touch NewDot's activeClients list — the handoff opens EXPENSIFY_URL, not NEW_EXPENSIFY_URL (CONFIG.ts:76-78).
  • Even with two NewDot tabs, Onyx cross-tab sync is on by default on web (shouldSyncMultipleInstances = !!global.localStorage) and policy_<id> is a persisted key, so a follower tab converges on the leader's write.
  • The fetch flag never gated pushed data anyway — the Pusher apply path is a plain Onyx.update(pushJSON), so a pushed isConfigured = true always lands.

@huult

huult commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot please close this PR

@MelvinBot MelvinBot closed this Sep 15, 2026
@MelvinBot

MelvinBot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Closed this PR as requested.

The branch claude-xeroConnectionsRefresh is still there if you want to reopen or reuse it later.


view run · no recording available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants