Skip to content

fix(sticky): checking get workflow history when sticky decision task#631

Open
yux0 wants to merge 1 commit intocadence-workflow:masterfrom
yux0:check-history-empty
Open

fix(sticky): checking get workflow history when sticky decision task#631
yux0 wants to merge 1 commit intocadence-workflow:masterfrom
yux0:check-history-empty

Conversation

@yux0
Copy link
Copy Markdown
Contributor

@yux0 yux0 commented Aug 24, 2021

We see NPE in ReplayDecider with line: decisionTask.getHistory().getEvents().get(0).getWorkflowExecutionStartedEventAttributes();

In ReplayDecisionTaskHandler, we have special handling for sticky decision task that has a partial history. But we do not check the returned history. So add a check to get workflow history when sticky decision task

@yux0 yux0 requested review from a team and meiliang86 August 24, 2021 17:46
@yux0 yux0 marked this pull request as draft August 24, 2021 17:50
@shijiesheng shijiesheng changed the title Checking get workflow history when sticky decision task fix(sticky): checking get workflow history when sticky decision task May 1, 2026
@shijiesheng shijiesheng marked this pull request as ready for review May 1, 2026 18:08
.setExecution(decisionTask.getWorkflowExecution());
GetWorkflowExecutionHistoryResponse getHistoryResponse =
service.GetWorkflowExecutionHistory(getHistoryRequest);
if (getHistoryResponse.getHistory().getEventsSize() == 0) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Bug: Potential NPE on getHistoryResponse.getHistory() not guarded

The new check calls getHistoryResponse.getHistory().getEventsSize() but does not guard against getHistory() itself returning null. The original NPE described in the PR was on a similar chain (decisionTask.getHistory().getEvents().get(0)...). If the server returns a response with a null History field, this new code will throw an NPE instead of the intended RuntimeException.

Additionally, the same null risk exists on line 268 (decisionTask.getHistory().getEvents()) before the sticky check — if decisionTask.getHistory() is null, the method crashes before ever reaching the new guard. This is pre-existing, but worth noting since the PR aims to harden this path.

Suggested fix:

if (getHistoryResponse == null
    || getHistoryResponse.getHistory() == null
    || getHistoryResponse.getHistory().getEventsSize() == 0) {
  throw new RuntimeException("Failed to get workflow execution history for replay");
}

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

@gitar-bot
Copy link
Copy Markdown

gitar-bot Bot commented May 1, 2026

Code Review ⚠️ Changes requested 0 resolved / 1 findings

Adds a check for sticky decision tasks to prevent NPEs in ReplayDecider, but the implementation fails to guard against potential null values returned by getHistoryResponse.getHistory().

⚠️ Bug: Potential NPE on getHistoryResponse.getHistory() not guarded

📄 src/main/java/com/uber/cadence/internal/replay/ReplayDecisionTaskHandler.java:277

The new check calls getHistoryResponse.getHistory().getEventsSize() but does not guard against getHistory() itself returning null. The original NPE described in the PR was on a similar chain (decisionTask.getHistory().getEvents().get(0)...). If the server returns a response with a null History field, this new code will throw an NPE instead of the intended RuntimeException.

Additionally, the same null risk exists on line 268 (decisionTask.getHistory().getEvents()) before the sticky check — if decisionTask.getHistory() is null, the method crashes before ever reaching the new guard. This is pre-existing, but worth noting since the PR aims to harden this path.

Suggested fix
if (getHistoryResponse == null
    || getHistoryResponse.getHistory() == null
    || getHistoryResponse.getHistory().getEventsSize() == 0) {
  throw new RuntimeException("Failed to get workflow execution history for replay");
}
🤖 Prompt for agents
Code Review: Adds a check for sticky decision tasks to prevent NPEs in ReplayDecider, but the implementation fails to guard against potential null values returned by getHistoryResponse.getHistory().

1. ⚠️ Bug: Potential NPE on getHistoryResponse.getHistory() not guarded
   Files: src/main/java/com/uber/cadence/internal/replay/ReplayDecisionTaskHandler.java:277

   The new check calls `getHistoryResponse.getHistory().getEventsSize()` but does not guard against `getHistory()` itself returning null. The original NPE described in the PR was on a similar chain (`decisionTask.getHistory().getEvents().get(0)...`). If the server returns a response with a null `History` field, this new code will throw an NPE instead of the intended `RuntimeException`.
   
   Additionally, the same null risk exists on line 268 (`decisionTask.getHistory().getEvents()`) before the sticky check — if `decisionTask.getHistory()` is null, the method crashes before ever reaching the new guard. This is pre-existing, but worth noting since the PR aims to harden this path.

   Suggested fix:
   if (getHistoryResponse == null
       || getHistoryResponse.getHistory() == null
       || getHistoryResponse.getHistory().getEventsSize() == 0) {
     throw new RuntimeException("Failed to get workflow execution history for replay");
   }

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.

1 participant