Skip to content

refactor: streamline orchestration event handling and improve state management#115

Open
torosent wants to merge 7 commits intomainfrom
torosent/code-simplify
Open

refactor: streamline orchestration event handling and improve state management#115
torosent wants to merge 7 commits intomainfrom
torosent/code-simplify

Conversation

@torosent
Copy link
Member

Summary

What changed?

  • Refactored orchestration event handling in orchestration-executor.ts and history-event-converter.ts for cleaner, more maintainable code
  • Simplified tracing logic in trace-helper.ts by reducing complexity and improving readability
  • Streamlined credential factory and options in durabletask-js-azuremanaged
  • Cleaned up pb-helper.util.ts for improved protobuf helper patterns
  • Removed unnecessary code from runtime-orchestration-context.ts

Why is this change needed?

  • Reduces code complexity and improves maintainability across core orchestration and event handling modules
  • Makes the codebase easier to understand and contribute to

Issues / work items

  • N/A

Project checklist

  • Release notes are not required for the next release
  • Backport is not required
  • All required tests have been added/updated (unit tests, E2E tests)
  • Breaking change?
    • No breaking changes. This is a pure refactor with no API or behavior changes.

AI-assisted code disclosure (required)

Was an AI tool used? (select one)

  • No
  • Yes, AI helped write parts of this PR (e.g., GitHub Copilot)
  • Yes, an AI agent generated most of this PR

If AI was used:

  • Tool(s): GitHub Copilot CLI
  • AI-assisted areas/files: All files in this PR
  • What you changed after AI output: Reviewed all changes

AI verification (required if AI was used):

  • I understand the code and can explain it
  • I verified referenced APIs/types exist and are correct
  • I reviewed edge cases/failure paths (timeouts, retries, cancellation, exceptions)
  • I reviewed concurrency/async behavior
  • I checked for unintended breaking or behavior changes

Testing

Automated tests

  • Result: Pending CI

Manual validation (only if runtime/behavior changed)

  • N/A (pure refactor, no behavior changes)

Notes for reviewers

  • This is a code simplification refactor across 9 files touching orchestration execution, event handling, tracing, and protobuf utilities.
  • No functional or behavioral changes are intended.

…anagement

- Simplified the handling of various orchestration events by extracting logic into dedicated methods for better readability and maintainability.
- Updated the StateShim class to use a more concise null check for state presence.
- Enhanced error handling for entity operations and task failures, ensuring clearer logging and state recovery.
- Removed commented-out code in RuntimeOrchestrationContext's setFailed method to clarify intent and functionality.
Copilot AI review requested due to automatic review settings February 28, 2026 00:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors core Durable Task JS orchestration execution/event handling and related utilities to reduce complexity while keeping behavior consistent across workers, tracing, and Azure Managed configuration.

Changes:

  • Split OrchestrationExecutor.processEvent’s large switch into focused handler methods and shared helpers for completed/failed tasks.
  • Introduced parseJsonField and reduced duplication in protobuf helper utilities (including entity message action wrapping).
  • Simplified/standardized small patterns in tracing, paging, entity state checks, and Azure Managed options/credential construction.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/durabletask-js/src/worker/runtime-orchestration-context.ts Removes dead/commented code in failure handling path.
packages/durabletask-js/src/worker/orchestration-executor.ts Refactors orchestration history event processing into dedicated handlers and shared task helpers; switches JSON parsing to parseJsonField.
packages/durabletask-js/src/worker/entity-executor.ts Simplifies null/undefined checks for entity state serialization.
packages/durabletask-js/src/utils/pb-helper.util.ts Adds parseJsonField and refactors entity message action construction to use a shared wrapper.
packages/durabletask-js/src/utils/history-event-converter.ts Replaces monolithic switch with per-event converter functions and a dispatch map.
packages/durabletask-js/src/tracing/trace-helper.ts Consolidates entity call/signal span emission into a shared helper.
packages/durabletask-js/src/orchestration/page.ts Simplifies hasMoreResults continuation token check.
packages/durabletask-js-azuremanaged/src/options.ts Minor string construction cleanup for endpoint parsing.
packages/durabletask-js-azuremanaged/src/credential-factory.ts Streamlines Workload Identity credential option building.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

torosent and others added 5 commits February 27, 2026 16:06
- ajv: upgraded to fix ReDoS vulnerability (GHSA-2g4f-4pwh-qvx6)
- minimatch: upgraded to fix ReDoS vulnerabilities (GHSA-3ppc-4f35-3m26, GHSA-7r86-cg39-jmmj, GHSA-23c5-xmqv-rm74)
- tar: upgraded to fix arbitrary file read/write vulnerability (GHSA-83g3-92jg-28cx)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Node.js >=22 is required, so ES2022 features like Error cause,
top-level await, and Array.at() are safe to use. This also restores
the { cause: err } option in parseJsonField() that was previously
removed due to the old target.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove --runInBand from E2E test script to enable parallel file
  execution across Jest workers (~29 min → ~10 min estimated)
- Add timeout-minutes: 20 to DTS E2E test step to prevent runaway tests
- Switch npm install to npm ci for deterministic, faster CI installs
- Fix Node.js version from 18.x to 22.x in pr-validation lint job
  to match the project's engines.node >= 22.0.0 requirement

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

3 participants