Skip to content

Open the HR sync results screen when the result arrives after jobDone - #99591

Merged
Gonals merged 6 commits into
mainfrom
yuwen-99006-hr-sync-modal
Sep 11, 2026
Merged

Gonals merged 6 commits into
mainfrom
yuwen-99006-hr-sync-modal

Conversation

@yuwenmemon

@yuwenmemon yuwenmemon commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

@Gonals please review

Explanation of Change

The HR sync results screen never opened because the backend sends the jobDone stage and the sync result as two separate Onyx updates, in either order. The hook armed the screen only on the render where the stage first became jobDone, so a result-less update arriving first spent that render and dropped the result.

The hook now records that this mount watched a sync run, and it opens the result once for that run, so the order no longer matters. A mount that finds an already-finished sync in Onyx never saw the run, therefore it still opens nothing.

Rebased onto main's migration of the modal to a navigation screen, so this lands on the renamed useHRSyncResultsPage; that migration kept the same rising-edge guard, so the bug survived it. The hook is shared by every HR provider, so the fix covers TriNet and Merge HR too.

Background: where the two updates come from, and why the approved proposal needed a change

Integration-Server sends the jobDone event twice, from PushOnyxUpdateProgressManager.sendNotification:

  1. sendReliableNotification calls SendIntegrationProgressUpdate in Auth, which queues an Onyx merge of {stageInProgress: 'jobDone', connectionName, timestamp}. That command has no result parameter, so this update never carries one.
  2. It then pushes an onyxApiUpdate Pusher event directly, and that one does carry result.

Whichever lands first wins the rising edge. The result-bearing push arriving first is the working case; the reliable one arriving first is this bug.

The regression came from Prevent stale Gusto sync result modal, which replaced a per-render dedupe with the rising-edge check to stop the modal replaying on remount. That fixed the replay and introduced this drop. The new test covers both directions, so neither can come back.

The approved proposal keyed the dedupe on connectionSyncProgress.timestamp, treating it as a per-sync identity. It is not one: every progress update stamps a fresh timestamp (PushOnyxUpdateProgressManager uses ZonedDateTime.now(), Auth uses STimeNow(), and the optimistic write uses new Date()). A timestamp seen mid-sync therefore never matches the one on jobDone, so that version would have closed the modal permanently. This uses a per-mount flag instead, which is the same idea without the false identity.

A follow-up worth filing on the backend: a client that is offline when the sync finishes only ever receives update 1, so it gets jobDone with no result at all. Passing the result through SendIntegrationProgressUpdate would remove that gap, but it needs matching changes in Integration-Server, Web-Expensify, and Auth, so it does not belong here.

Fixed Issues

$ #99006
PROPOSAL: #99006 (comment)

Tests

  1. Sign in as an admin of a workspace connected to Gusto.
  2. Go to the workspace Members page.
  3. Open the More dropdown and select Sync with Gusto.
  4. Wait for the sync spinner to finish.
  5. Verify the sync results screen opens and shows the added, removed, and skipped employee counts.
  6. Dismiss the screen, navigate to another page, and return to the Members page.
  7. Verify nothing opens for the sync that already finished.
  8. Repeat steps 3 to 5 on the workspace HR page and verify the screen opens there too.
  9. Run npx jest tests/unit/hooks/useHRSyncResultsPage.test.ts and verify all cases pass.
  • Verify that no errors appear in the JS console

Offline tests

  1. Go to the Members page of a Gusto-connected workspace.
  2. Turn off your network connection.
  3. Open the More dropdown and select Sync with Gusto.
  4. Verify the sync does not start and no results screen opens.
  5. Turn the network connection back on and verify the page recovers with nothing opening.

QA Steps

  1. Sign in as an admin of a workspace connected to Gusto.
  2. Go to the workspace Members page.
  3. Open the More dropdown and select Sync with Gusto.
  4. Wait for the sync to finish.
  5. Verify the sync results screen opens and shows the added, removed, and skipped employee counts.
  6. Dismiss the screen, navigate away from the Members page, and come back.
  7. Verify nothing opens for the sync that already finished.
  • Verify that no errors appear in the JS console

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

@yuwenmemon
yuwenmemon requested review from a team as code owners August 26, 2026 18:20
@melvin-bot
melvin-bot Bot requested review from mananjadhav and removed request for a team August 26, 2026 18:20
@melvin-bot

melvin-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

@mananjadhav Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot requested review from garrettmknight and removed request for a team August 26, 2026 18:20

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4cfd2dc08c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +55 to +56
const isHRSyncDoneWithResult = isHRConnectionName && stageInProgress === CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.JOB_DONE && !!syncResult;
const didHRSyncComplete = isFocused && isHRSyncDoneWithResult && didWatchSyncRunRef.current;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear watched runs when they finish off-screen

When a screen observes a running sync and then loses focus before JOB_DONE, this condition leaves didWatchSyncRunRef set because isFocused is false. Both WorkspaceHRPage and WorkspaceMembersPage invoke this hook and can remain mounted as frozen stack screens, so if the user moves between them during a sync, the newly focused page can show the result and the original page will show the same result again when revisited. Consume or globally deduplicate the completed run even when this particular hook instance is unfocused.

Useful? React with 👍 / 👎.

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.

(Yuwen's Agent) Valid edge case, thanks. When WorkspaceHRPage and WorkspaceMembersPage are both mounted and both watched the same live run, the focused page shows the result while the unfocused page keeps didWatchSyncRunRef set and re-fires it on refocus, so the result appears twice.

The naive per-instance fix (consume the run on JOB_DONE regardless of isFocused) would regress the intended single-page case this PR exists for: start a sync, navigate away before it finishes, then return to see the result. Correct dedup has to be cross-instance, which needs a per-run identity. The backend doesn't give us one; connectionSyncProgress.timestamp changes on every progress update, so it is not a per-sync key.

Flagging for the author to decide the dedup approach rather than auto-fixing, since a wrong key here reintroduces the "modal never shows" bug.

garrettmknight
garrettmknight previously approved these changes Aug 26, 2026

@garrettmknight garrettmknight 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.

Looks good from a product perspective

@yuwenmemon

Copy link
Copy Markdown
Contributor Author

@ShridharGoel bump!

@ShridharGoel

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • 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 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.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

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

@ShridharGoel ShridharGoel 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.

Code looks fine, though could not test because of lack of credentials.

@yuwenmemon yuwenmemon changed the title Show the HR sync results modal when the result arrives after jobDone Open the HR sync results screen when the result arrives after jobDone Sep 2, 2026
@yuwenmemon

Copy link
Copy Markdown
Contributor Author

@ShridharGoel I believe we have cleared up your credentials issue?

@yuwenmemon
yuwenmemon requested a review from a team September 9, 2026 20:55
@melvin-bot
melvin-bot Bot requested review from Gonals and removed request for a team September 9, 2026 20:55
@melvin-bot

melvin-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

@Gonals Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@Gonals
Gonals merged commit 7e99371 into main Sep 11, 2026
35 of 36 checks passed
@Gonals
Gonals deleted the yuwen-99006-hr-sync-modal branch September 11, 2026 13:18
@github-actions

Copy link
Copy Markdown
Contributor

🚧 Gonals has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/Gonals in version: 9.4.77-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

🤖 Yes — help site changes are required. Draft PR: #101003

Your code change itself adds no new copy or flow, so it needs no docs on its own. But checking the HR articles against the current UI turned up three stale things, two of which this PR's behavior makes newly visible:

What's wrong today What the UI actually does
Five articles call the results "a sync results panel" A dedicated screen: header Gusto sync complete, heading Successfully synced your Gusto connection!, the Added / Removed / Skipped counts, an expandable Skipped list, and a Got it button
The Gusto article says to click a Re-sync button in the Gusto section of Members There is no Re-sync label. The paths are HR → three dots (⋮)Sync now, or MembersMoreSync with Gusto
No article said to stay on the page Your fix arms the screen only for a run the hook watched, so navigating away mid-sync means nothing opens when it finishes

Also fixed a three-dots-menu convention violation in the TriNet article, per docs/HELPSITE_NAMING_CONVENTIONS.md.

Files changed: the Gusto, TriNet, BambooHR, HiBob, Workday, and shared Connect an HR integration to Expensify articles. No new articles, no renamed files, no URL changes.

Label verification and one thing I deliberately left out

Every label was checked against source, not guessed:

I did not add the 2-per-day manual sync limit to the Gusto and TriNet articles, even though the BambooHR, HiBob, and Workday articles carry it. showMergeManualSyncLimitModalIfReached returns early unless isMergeConnectionName passes, and that covers only merge_hris and merge_atsMergeUtils.ts:19-20. The limit does not apply to Gusto or TriNet.

One thing worth a second look: the Gusto and TriNet articles claim that leaving the page mid-sync emails the results to the workspace's technical contact. That's a backend behavior I can't verify from the App repo, so I preserved the claim as written rather than changing it.


@yuwenmemon, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 9.4.77-4 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants