Skip to content

fix(workflow): return errors instead of panicking in history readers (EN-1226) - #189

Closed
flemzord wants to merge 1 commit into
mainfrom
fix/history-handler-panics
Closed

fix(workflow): return errors instead of panicking in history readers (EN-1226)#189
flemzord wants to merge 1 commit into
mainfrom
fix/history-handler-panics

Conversation

@flemzord

Copy link
Copy Markdown
Member

Problem (H6 — HIGH)

ReadInstanceHistory and ReadStageHistory run inside HTTP handlers but:

  • panic(err) on json.Unmarshal failures of history payloads (3 sites),
  • panic(err) on any DescribeWorkflowExecution error other than NotFound (Temporal unreachable, deadline, permission),
  • index Input.Payloads[0] / Result.Payloads[0] with no length check ⇒ index-out-of-range when started with no payload.

chi's Recoverer turned each into an opaque 500 with no schema-conformant body and lost the error context.

Fix

  • Add unmarshalFirstPayload() — tolerates a nil/empty payload set and returns the decode error instead of panicking.
  • Replace all four panic sites with wrapped returned errors. The DescribeWorkflowExecution NotFound case still maps to ErrInstanceNotFound.

Test

TestUnmarshalFirstPayload covers nil / empty / malformed / well-formed payloads.

Severity: HIGH.

Note: edits internal/workflow/manager.go (different functions than the other manager.go PRs in this series); independent.

ReadInstanceHistory and ReadStageHistory ran inside HTTP handlers but
panicked on json.Unmarshal failures and on any DescribeWorkflowExecution
error other than NotFound, and indexed Input.Payloads[0] / Result.Payloads[0]
without a length check (index out of range when a workflow/activity was
started with no payload). chi's Recoverer turned each into an opaque 500.

- Add unmarshalFirstPayload(), which tolerates a nil/empty payload set and
  returns the decode error instead of panicking.
- Replace all four panic sites with wrapped returned errors; the
  DescribeWorkflowExecution NotFound case still maps to ErrInstanceNotFound.

Adds TestUnmarshalFirstPayload (nil/empty/malformed/well-formed).

Note: overlaps internal/workflow/manager.go with other PRs in this series
(different functions); independent.
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@flemzord, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 5 minutes and 57 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 49ddfc32-4c75-4775-ba6d-f6e8bd6f465a

📥 Commits

Reviewing files that changed from the base of the PR and between 271bf8d and e01eaae.

📒 Files selected for processing (2)
  • internal/workflow/manager.go
  • internal/workflow/manager_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/history-handler-panics

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@flemzord

flemzord commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

Tracked in Jira: EN-1226 (Epic EN-1217).

@flemzord flemzord changed the title fix(workflow): return errors instead of panicking in history readers fix(workflow): return errors instead of panicking in history readers (EN-1226) Jun 11, 2026
@flemzord

flemzord commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

Superseded by #199, which consolidates this change with the related reliability and safety fixes on top of the current main branch.

@flemzord flemzord closed this Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant