Skip to content

fix(ui): prevent duplicate TI summary stream refreshes after mutations#67892

Open
durgaprasadml wants to merge 1 commit into
apache:mainfrom
durgaprasadml:clean-fix-ui-freeze
Open

fix(ui): prevent duplicate TI summary stream refreshes after mutations#67892
durgaprasadml wants to merge 1 commit into
apache:mainfrom
durgaprasadml:clean-fix-ui-freeze

Conversation

@durgaprasadml
Copy link
Copy Markdown

Summary

Closes #67884

This fixes a UI freeze regression introduced after #67212 where Task Instance mutation actions (Mark success/failed, etc.) triggered multiple overlapping TI summary stream refreshes and excessive React state updates.

Previously:

  • multiple query invalidations could trigger multiple stream restarts
  • overlapping NDJSON streams emitted duplicate updates
  • each streamed line caused an individual React state update
  • expensive grid/task-instance rendering amplified the render pressure
  • the UI became temporarily unresponsive for several seconds after mutation actions

This update introduces deterministic refresh coalescing, active stream deduplication, and NDJSON state batching to significantly reduce render churn while preserving query freshness and the stale badge fix introduced in #67212.


Root Cause

The cache subscriber added in #67212 relied on a fragile timing-based debounce using setTimeout(..., 0).

Under mutation-heavy invalidation flows:

  • multiple query invalidations emitted separate cache notifications
  • refresh scheduling could execute multiple times
  • multiple TI summary streams became active simultaneously
  • every NDJSON line triggered a separate setSummariesByRunId update

This resulted in dozens of rapid re-renders on already expensive UI surfaces.


Changes

Deterministic Refresh Coalescing

  • replaced the fragile timeout-based refresh scheduling
  • introduced frame-based refresh coalescing using requestAnimationFrame
  • collapses multiple invalidation notifications into a single refresh cycle

Active Stream Deduplication

  • stale streams are now aborted correctly
  • aborted streams immediately stop processing NDJSON updates
  • prevents obsolete stream instances from updating React state

NDJSON State Batching

  • buffered streamed summaries per read chunk
  • applied updates in a single batched state update instead of once-per-line
  • significantly reduced render frequency and Map cloning overhead

Tests Added

Added comprehensive tests covering:

  • multiple invalidations collapsing into one refresh
  • stale stream abort handling
  • NDJSON batching behavior
  • stable mount behavior
  • prevention of duplicate refresh scheduling

Verification

Validated with:
bash npx vitest run src/queries/useGridTISummaries.test.tsx pnpm lint

No lint or type errors remain.

@boring-cyborg boring-cyborg Bot added the area:UI Related to UI/UX. For Frontend Developers. label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:UI Related to UI/UX. For Frontend Developers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI: Task Instance page freezes after Mark-as on main (post-#67212)

1 participant