Skip to content

fix(ui): reliably refresh teams list after create (fixes flaky Teams breadcrumb E2E) - #34619

Merged
Rohit0301 merged 14 commits into
mainfrom
fix/teams-list-advanced-refresh-race
Oct 5, 2026
Merged

Rohit0301 merged 14 commits into
mainfrom
fix/teams-list-advanced-refresh-race

Conversation

@Rohit0301

@Rohit0301 Rohit0301 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Screen.Recording.2026-10-05.at.11.32.29.AM.mov

The Playwright test "Teams Page › Verify breadcrumb navigation for a team with a dot in its name" intermittently times out at the first addTeamHierarchy (utils/team.ts:442), waiting for GET /api/v1/teams?parentTeam=…&fields=owns,childrenCount,userCount,parents,defaultPersona. The trace shows that GET is never sent — it is a frontend race, not a slow backend, which is why it only fails under parallel load.

Root cause

In TeamsPage.tsx the "advanced" all-teams fetch (the fields=… GET) was never called directly — it rode a boolean flag:

  • fetchAllTeamsBasicDetails success → setFetchAllTeamAdvancedDetails(true)
  • an effect fired the advanced GET on the flag flipping to true
  • fetchAllTeamsAdvancedDetails finally → setFetchAllTeamAdvancedDetails(false)

On mount the page already runs one basic→advanced cycle. Under parallel load that initial advanced GET is slow, so the flag is still true when the user submits the new team. createNewTeam → loadAdvancedDetails → fetchAllTeamsBasicDetails sets the flag true while it is already true → React bails on the no-op write → the effect never re-runs → the post-create refresh is swallowed. The test waits for a request that is never sent → 60s wall.

This is also a real product bug: creating a team while the page is still loading counts leaves the new row's userCount/childrenCount stale until the next navigation.

Fix

Split the one boolean that was doing two jobs:

  • Trigger → monotonic nonce. Each basic-fetch completion bumps advancedFetchNonce, so the effect always re-fires — even while a prior advanced fetch is in flight. No more coalescing.
  • Loading flag preserved. A dedicated isFetchAllTeamAdvancedDetails boolean (set at the start/finally of the advanced fetch) keeps driving the hierarchy count skeletons in TeamHierarchy.

No test change needed — the fields=… GET now reliably fires after every create, so the existing wait in addTeamHierarchy stops hanging.

Tests

  • No new tests: this fixes an existing flaky E2E (Teams.spec.ts breadcrumb-with-dot) by removing its root cause; behaviour for mount and showDeletedTeam toggle is unchanged (nonce 0 → 1 → single advanced fetch, as before).
  • Verify locally (requires a running stack):
    npx playwright test playwright/e2e/Pages/Teams.spec.ts \
      -g "Verify breadcrumb navigation for a team with a dot in its name" --repeat-each=5
    
    Expect 5/5 green with a parentTeam=…&fields=… GET firing after each create.

The all-teams advanced fetch (parentTeam=...&fields=...) rode a boolean
flag: fetchAllTeamsBasicDetails set it true, an effect fired the fetch on
the flip, and the fetch reset it to false. When a refresh was requested
while a prior advanced fetch was still in flight (slow under load), the
boolean was already true, so the write was a no-op, the effect never
re-ran, and the refresh was silently dropped.

Split the single boolean into a monotonic nonce (trigger) and a dedicated
loading flag. Each basic-fetch completion bumps the nonce, so the effect
always re-fires even while a prior fetch is in flight. The loading flag
keeps driving the hierarchy count skeletons.

Fixes the flaky Teams breadcrumb Playwright test (the awaited teams-list
GET was never sent) and the underlying bug where creating a team while
counts were still loading left the new row's counts stale.
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@github-actions github-actions Bot added the UI UI specific issues label Oct 4, 2026
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@Rohit0301 Rohit0301 self-assigned this Oct 4, 2026
@Rohit0301 Rohit0301 added the safe to test Add this label to run secure Github workflows on PRs label Oct 4, 2026
@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 9017195c7cc2104e81d98269e2df500c57d44142 in Playwright run 37290544368, attempt 1.

✅ 3428 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 55m 31s

⏱️ Max setup 5m 4s · max shard execution 20m 26s · max shard-job elapsed before upload 23m 38s · reporting 12s

🌐 213.15 requests/attempt · 2.02 app boots/UI scenario · 37.77% common-shard skew

Optimization targets still in progress:

  • Common shard skew was 37.77% (convergence target: at most 15%).
  • Browser traffic was 213.15 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.02 per UI scenario (7322 boots / 3627 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard advanced-search-01 65 0 0 0 0 0
✅ Shard advanced-search-02 65 0 0 0 0 0
✅ Shard chromium-01 154 0 0 0 0 0
✅ Shard chromium-02 192 0 0 0 0 0
✅ Shard chromium-03 187 0 0 0 0 0
✅ Shard chromium-04 189 0 0 0 0 0
✅ Shard chromium-05 154 0 0 0 0 0
✅ Shard chromium-06 209 0 0 0 0 0
✅ Shard chromium-07 215 0 0 0 0 0
✅ Shard chromium-08 174 0 0 0 0 0
✅ Shard chromium-09 204 0 0 0 0 0
✅ Shard chromium-10 177 0 0 0 0 0
✅ Shard chromium-11 179 0 0 0 0 0
✅ Shard chromium-12 165 0 0 0 0 0
✅ Shard chromium-13 147 0 0 1 0 0
✅ Shard chromium-14 165 0 0 0 0 0
✅ Shard chromium-15 195 0 0 0 0 0
✅ Shard chromium-16 165 0 0 0 0 0
✅ Shard data-asset-rules-01 65 0 0 0 0 0
✅ Shard global-state-01 67 0 0 0 0 0
✅ Shard import-export-01 81 0 0 0 0 0
✅ Shard import-export-02 71 0 0 0 0 0
✅ Shard ingestion-01 34 0 0 0 0 0
✅ Shard ingestion-02 30 0 0 0 0 0
✅ Shard ingestion-03 29 0 0 0 0 0
✅ Shard reindex-01 41 0 0 0 0 0
✅ Shard search-rbac-01 9 0 0 0 0 0

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

Address review feedback on the nonce change:

- Overlapping full refreshes: the nonce lets a newer advanced fetch start
  before an older one resolves. Tag each full refresh (updateChildNode=false)
  with a request id and only let the latest apply its list and clear the
  loading flag, so a slow pre-create response can no longer overwrite the
  list with stale data or hide the count skeletons early. Expand calls merge
  into a specific subtree and skip the request-id bump, so they don't
  invalidate each other.
- Duplicate fetch on navigation: keying the effect on both the nonce and fqn
  fired the advanced GET twice per navigation (once from fqn, once from the
  following nonce bump). Trigger on the nonce alone and read the latest fqn
  through a ref.
- cyclomatic-complexity (error): the previous helper only touched the map
  callback (a separate function), so fetchAllTeamsAdvancedDetails stayed at
  11. Extract the result-application branch into applyAllTeamsData, dropping
  two decision points from the function (now 9).
- exhaustive-deps (warnings): add the stable t to the two useCallback dep
  arrays that use it; annotate the three trigger effects with justified
  eslint-disable-next-line (their fetchers are non-memoized triggers, not
  reactive inputs — adding them would re-run every render or duplicate the
  navigation fetch).
The nonce refactor set isFetchAllTeamAdvancedDetails(true) at the start of
every advanced fetch, including expand (updateChildNode=true). That flag
drives the per-column skeletons across all rows in TeamHierarchy, so
expanding one row blanked the whole table. Restore the original behavior:
set the flag only for full refreshes (setIsFetchAllTeamAdvancedDetails(
isFullRefresh)); expand leaves it off.
setIsFetchAllTeamAdvancedDetails(isFullRefresh) still wrote false on expand,
and the finally cleared it too (isLatestFullRefresh is always true for
expands) — so expanding a row while a full refresh is mid-flight hid the
count skeletons early and showed stale values. Guard both the set and the
clear on full-refresh-only: set behind if (isFullRefresh); clear behind a
new isActiveFullRefresh() (isFullRefresh && latest). The && lives in a
nested arrow so cyclomatic-complexity stays at 10.
Overlap two full refreshes (mount + showDeleted toggle), resolve the newer
one first and the older (stale) one last, and assert the stale response does
not overwrite the list. Verified it fails without the request-id guard in
fetchAllTeamsAdvancedDetails. Extends the TeamDetailsV1 mock to render
childTeams names so the applied list is observable.
Replace the three disable directives with real fixes:

- Move updateTeamsHierarchy to module scope (pure, no closure); convert
  applyAllTeamsData, fetchAllTeamsAdvancedDetails, fetchAllTeamsBasicDetails,
  getParentTeam, and fetchTeamBasicDetails to useCallback with honest dep
  arrays so their identities are stable.
- fetchAllTeamsBasicDetails now chains the advanced fetch directly (void
  call) instead of bumping a nonce through an effect — removes the nonce
  state, fqnRef, and the two associated effects entirely.
- The team-list effect depends on [fqn, hasViewPermission,
  fetchAllTeamsBasicDetails]: fqn/permission changes trigger navigation
  refetches; fetchAllTeamsBasicDetails identity changes when showDeletedTeam
  flips (it closes over it), so the deleted-toggle refetch works without a
  dedicated effect.
- The team-details effect now lists all deps honestly: [hasViewPermission,
  fqn, fetchTeamBasicDetails, loadAdvancedDetails].
- applyAllTeamsData uses a functional setChildTeams updater on the expand
  path so it doesn't close over childTeams and can stay stable.
- createNewTeam explicitly refreshes the list after a create (void
  fetchAllTeamsBasicDetails) since navigation/toggle no longer cover it.

No behaviour change. 13/13 tests pass. Zero eslint-disable lines remain.
…ponses

A basic fetch from a previous fqn could resolve late, overwrite the list
with the old parent's teams, and chain an advanced fetch that bumps
advancedFetchIdRef — causing the in-flight advanced fetch for the current
fqn to be dropped as superseded. Add basicFetchIdRef alongside
advancedFetchIdRef and drop the response (and the chained advanced call)
if a newer basic fetch has already started.
@gitar-bot

gitar-bot Bot commented Oct 5, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 4 closed / 4 findings

🟡 Medium risk · Team creation and navigation now trigger guarded asynchronous list refreshes.

Fixes the flaky Teams breadcrumb E2E by replacing a boolean flag with a monotonic nonce to reliably trigger the advanced teams fetch after create operations. Resolved overlapping advanced fetches overwriting the list with stale data, duplicate fetches on fqn changes, expand operations clearing the full-refresh skeleton flag mid-flight, and stale basic fetch responses after navigation. No issues found.

✅ 4 closed
✅ Bug: Overlapping advanced fetches can overwrite list with stale data

📄 openmetadata-ui/src/main/resources/ui/src/pages/TeamsPage/TeamsPage.tsx:135 📄 openmetadata-ui/src/main/resources/ui/src/pages/TeamsPage/TeamsPage.tsx:155-169 📄 openmetadata-ui/src/main/resources/ui/src/pages/TeamsPage/TeamsPage.tsx:556-560
The nonce now lets a second advanced fetch start while the first one is still running. This is exactly the case the PR describes: the slow mount fetch is still in flight when the user creates a team. Neither fetch checks whether a newer request has started. If the older request (sent before the create) finishes last, it calls setChildTeams with a list that doesn't include the new team. The first fetch's finally also sets isFetchAllTeamAdvancedDetails to false while the newer fetch is still loading, so the count skeletons disappear too early. Fix: tag each fetch with the nonce or a request-id ref, and only apply results and clear the loading flag when that tag matches the latest request (or cancel the older request with an AbortController).

✅ Performance: fqn change now fires a duplicate advanced teams fetch

📄 openmetadata-ui/src/main/resources/ui/src/pages/TeamsPage/TeamsPage.tsx:556-560
The old boolean was false when idle, so a change to fqn alone didn't run the effect's fetch. With the nonce, advancedFetchNonce > 0 stays true once anything has loaded. Navigating to another team now fires the advanced GET right away from the fqn dependency. Then loadAdvancedDetails → fetchAllTeamsBasicDetails bumps the nonce and sends the same GET a second time. That is two identical fields=… requests per navigation, and they can resolve out of order. Fix: drop fqn from this effect's dependencies and read the latest fqn through a ref, or keep the fqn in state together with the nonce when it is bumped.

✅ Bug: Expand fetch clears full-refresh skeleton flag mid-flight

📄 openmetadata-ui/src/main/resources/ui/src/pages/TeamsPage/TeamsPage.tsx:195 📄 openmetadata-ui/src/main/resources/ui/src/pages/TeamsPage/TeamsPage.tsx:220-224
setIsFetchAllTeamAdvancedDetails(isFullRefresh) sets the flag to false when a row is expanded, not just skips setting it. If a user expands a row while a full refresh is still running (after a create, for example), the count skeletons for the whole table disappear too early and the stale userCount/childrenCount values show until the full refresh comes back. The finally block makes it worse: isLatestFullRefresh() is always true for expand calls, so a finished expand also resets the flag. The fix is to change the flag only on full refreshes, both at the start and in finally.

✅ Edge Case: Stale basic fetch after navigation can replace list with old parent's teams

📄 openmetadata-ui/src/main/resources/ui/src/pages/TeamsPage/TeamsPage.tsx:210-224 📄 openmetadata-ui/src/main/resources/ui/src/pages/TeamsPage/TeamsPage.tsx:587-591
fetchAllTeamsBasicDetails has no staleness guard, and it now chains fetchAllTeamsAdvancedDetails(false, parentTeam) using the parent it was called with. In the previous commit the follow-up read fqnRef.current. Here is how it can go wrong: you navigate A→B while basic(A) is still in flight. basic(B) resolves and starts advanced(B). Then basic(A) resolves late, calls setChildTeams(A's teams) and starts advanced(A), which bumps advancedFetchIdRef. The guard then drops advanced(B) as stale, so B's page shows A's children for good. Before this change, the later advanced fetch always used the latest fqn and corrected the list. To fix it, give the basic fetch its own request id and drop superseded responses before both the setChildTeams call and the chained advanced call.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sonarqubecloud

sonarqubecloud Bot commented Oct 5, 2026

Copy link
Copy Markdown

This branch was previously deployed

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

Labels

safe to test Add this label to run secure Github workflows on PRs UI UI specific issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants