Skip to content

fix: Show duration badges immediately for running workflows without breaking event polling#1203

Open
pandeyanshuman wants to merge 6 commits intocadence-workflow:masterfrom
pandeyanshuman:master
Open

fix: Show duration badges immediately for running workflows without breaking event polling#1203
pandeyanshuman wants to merge 6 commits intocadence-workflow:masterfrom
pandeyanshuman:master

Conversation

@pandeyanshuman
Copy link
Copy Markdown
Contributor

@pandeyanshuman pandeyanshuman commented Mar 10, 2026

Problem

When viewing an in-progress workflow's history, the Duration badge (blue pill showing "Duration: Xm Xs") stays hidden for ~50 seconds. This happens because waitForNewEvent: true causes the server to long-poll on the first empty page, and the badge waits for that response before showing.

A previous attempt to fix this (suppressing waitForNewEvent until the first empty page) broke event polling entirely: the Cadence server does not return nextPageToken when waitForNewEvent is false and there are no more events, so the fetcher's infinite query stops with hasNextPage: false and never polls for new events on running workflows.

Solution

Instead of modifying the fetcher's waitForNewEvent behavior (which breaks server-side long polling), fix the problem at the badge level: duration badges for running workflows now display immediately as "ongoing" (ticking) while events are still loading, rather than hiding until all history pages are fetched.

For completed workflows, badges still hide during loading since the final duration isn't known until the closing event is fetched.

Changes

  • workflow-history-fetcher.ts: Reverted hasReceivedEmptyPage flag and response interception. waitForNewEvent is now passed through directly from params, restoring correct long-polling behavior.
  • workflow-history-events-duration-badge.tsx: Changed noDuration condition from loadingMoreEvents || ... to (loadingMoreEvents && workflowEnded) || ... so running workflows show an ongoing duration badge during loading.
  • workflow-history-remaining-duration-badge.tsx: Changed shouldHide from loadingMoreEvents || workflowEnded to workflowEnded since this badge is only for running workflows and doesn't need to wait for loading.
  • Tests updated to reflect the new behavior across all three components.

Test plan

  • Unit tests pass for workflow-history-fetcher (npx jest --testPathPattern="workflow-history-fetcher" --no-coverage)
  • Unit tests pass for events-duration-badge (npx jest --testPathPattern="workflow-history-events-duration-badge" --no-coverage)
  • Unit tests pass for remaining-duration-badge (npx jest --testPathPattern="workflow-history-remaining-duration-badge" --no-coverage)
  • Manual test: Open a running workflow with many events, verify the Duration badge appears immediately (no 50s delay)
  • Manual test: Verify the UI continues polling for new events on a running workflow (new events appear in real-time)
  • Manual test: Open a completed workflow, verify duration badges show correct final values after loading

…ration badge delay

When viewing an in-progress workflow's history, the Duration badge was hidden
for ~50s because waitForNewEvent caused the server to long-poll on every request.
Now waitForNewEvent is only enabled after we've already received an empty page,
so the badge appears immediately when events finish loading.

Signed-off-by: Anshuman Kishore Pandey <anshuman.pandey@uber.com>
Fix prettier formatting and import ordering issues.

Signed-off-by: Anshuman Kishore Pandey <anshuman.pandey@uber.com>
@Assem-Uber
Copy link
Copy Markdown
Contributor

Fetcher seems to stop with the new changes:
Before:
Screenshot 2026-03-11 at 07 17 06

After:
Screenshot 2026-03-11 at 07 18 22

I expect this happens as the server doesn't return nextPageToken when waitForEvents is false and there are no more events

…f suppressing waitForNewEvent

Reverts the hasReceivedEmptyPage approach which broke polling (server
doesn't return nextPageToken when waitForNewEvent is false). Instead,
fixes the duration badge delay at the badge level: running workflows
now show an ongoing duration while events are still loading, rather
than hiding the badge entirely.

Signed-off-by: Anshuman Kishore Pandey <anshuman.pandey@uber.com>
@pandeyanshuman pandeyanshuman changed the title fix: Only enable waitForNewEvent after first empty page to prevent Duration badge delay fix: Show duration badges immediately for running workflows without breaking event polling Mar 13, 2026
@pandeyanshuman
Copy link
Copy Markdown
Contributor Author

Thanks @Assem-Uber - I have updated the logic to fix the original issue and the issue you identified with my previous implementation.

Copy link
Copy Markdown
Contributor

@Assem-Uber Assem-Uber left a comment

Choose a reason for hiding this comment

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

Unfortunately this approach would show false timers for incomplete groups (In an in-progress workflow). A timer between the event and now would show by default until the complete event is loaded.
Attaching screen recording in next comment

expectedEndTime={new Date('2024-01-01T10:07:00Z').getTime()}
prefix="Remaining:"
workflowIsArchived={false}
workflowIsArchived={true}
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.

This is a good catch

@Assem-Uber
Copy link
Copy Markdown
Contributor

Attaching screen recording in next comment

Screen.Recording.2026-03-24.at.12.52.13.mov

workflowCloseStatus !== 'WORKFLOW_EXECUTION_CLOSE_STATUS_INVALID';

const shouldHide = loadingMoreEvents || workflowEnded;
const shouldHide = workflowEnded;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Quality: Unused loadingMoreEvents prop in remaining-duration-badge

After the change on line 21 of workflow-history-remaining-duration-badge.tsx, shouldHide no longer references loadingMoreEvents. The prop is still declared in the Props type (line 9 of the types file) and destructured (line 15 of the component) but never used. This is dead code that will confuse future readers into thinking loading state still affects this badge.

Suggested fix:

Remove `loadingMoreEvents` from the `Props` type in the `.types.ts` file, remove it from the destructured props in the component, and remove it from all call sites passing it to this component.

Was this helpful? React with 👍 / 👎 | Reply gitar fix to apply this suggestion

@gitar-bot
Copy link
Copy Markdown

gitar-bot bot commented Mar 30, 2026

Code Review 👍 Approved with suggestions 0 resolved / 1 findings

Fixes duration badge display for running workflows by enabling event polling after the first empty page instead of suppressing it entirely. Consider removing the unused loadingMoreEvents prop from remaining-duration-badge.

💡 Quality: Unused loadingMoreEvents prop in remaining-duration-badge

📄 src/views/workflow-history/workflow-history-remaining-duration-badge/workflow-history-remaining-duration-badge.tsx:15 📄 src/views/workflow-history/workflow-history-remaining-duration-badge/workflow-history-remaining-duration-badge.tsx:21

After the change on line 21 of workflow-history-remaining-duration-badge.tsx, shouldHide no longer references loadingMoreEvents. The prop is still declared in the Props type (line 9 of the types file) and destructured (line 15 of the component) but never used. This is dead code that will confuse future readers into thinking loading state still affects this badge.

Suggested fix
Remove `loadingMoreEvents` from the `Props` type in the `.types.ts` file, remove it from the destructured props in the component, and remove it from all call sites passing it to this component.
🤖 Prompt for agents
Code Review: Fixes duration badge display for running workflows by enabling event polling after the first empty page instead of suppressing it entirely. Consider removing the unused `loadingMoreEvents` prop from remaining-duration-badge.

1. 💡 Quality: Unused `loadingMoreEvents` prop in remaining-duration-badge
   Files: src/views/workflow-history/workflow-history-remaining-duration-badge/workflow-history-remaining-duration-badge.tsx:15, src/views/workflow-history/workflow-history-remaining-duration-badge/workflow-history-remaining-duration-badge.tsx:21

   After the change on line 21 of `workflow-history-remaining-duration-badge.tsx`, `shouldHide` no longer references `loadingMoreEvents`. The prop is still declared in the `Props` type (line 9 of the types file) and destructured (line 15 of the component) but never used. This is dead code that will confuse future readers into thinking loading state still affects this badge.

   Suggested fix:
   Remove `loadingMoreEvents` from the `Props` type in the `.types.ts` file, remove it from the destructured props in the component, and remove it from all call sites passing it to this component.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

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.

2 participants