Skip to content

Add getParent() API to TaskOrchestrationContext for parent instance support#284

Open
bachuv wants to merge 5 commits into
mainfrom
vabachu/parent-instance
Open

Add getParent() API to TaskOrchestrationContext for parent instance support#284
bachuv wants to merge 5 commits into
mainfrom
vabachu/parent-instance

Conversation

@bachuv
Copy link
Copy Markdown
Contributor

@bachuv bachuv commented May 5, 2026

Issue describing the changes in this PR

Adds getParent() API to TaskOrchestrationContext, bringing the Java SDK to parity with .NET's TaskOrchestrationContext.Parent property. This allows sub-orchestrations to discover their parent orchestration's name and instance ID at runtime.

Changes:

  • New class ParentOrchestrationInstance — immutable model with getName() and getInstanceId()
  • New default method getParent() on TaskOrchestrationContext — returns null for standalone orchestrations (non-breaking, backward-compatible)
  • Wiring in TaskOrchestrationExecutor — populates parent from ExecutionStartedEvent.parentInstance protobuf field
  • 7 unit tests covering: parent present, parent absent, exact value preservation, empty fields, default method compatibility, replay stability, and equals/hashCode
  • ParentInstanceSample — runnable sample demonstrating both sub-orchestration (parent detected) and standalone (null parent) scenarios

Pull request checklist

  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes are added to the CHANGELOG.md
  • I have added all required tests (Unit tests, E2E tests)

Additional information

  • Uses a default interface method to avoid breaking existing TaskOrchestrationContext implementers
  • The protobuf ParentInstanceInfo fields (taskScheduledId, version) used for internal completion routing are intentionally not exposed, matching .NET's public API surface
  • Verified end-to-end against the DTS emulator — both sub-orchestration and standalone paths work correctly
  • Run the sample: ./gradlew runParentInstanceSample

@bachuv bachuv requested a review from a team as a code owner May 5, 2026 05:31
Copilot AI review requested due to automatic review settings May 5, 2026 05:31
Copy link
Copy Markdown
Contributor

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

Adds parent-orchestration discovery for sub-orchestrations by introducing a TaskOrchestrationContext#getParent() API (modeled after .NET), wiring it from the ExecutionStartedEvent.parentInstance protobuf field, and providing tests + a runnable sample to demonstrate parent-present vs standalone behavior.

Changes:

  • Introduces ParentOrchestrationInstance (name + instanceId) and a non-breaking default TaskOrchestrationContext#getParent() method (returns null when absent).
  • Populates parent instance info in TaskOrchestrationExecutor during EXECUTIONSTARTED event processing.
  • Adds unit tests and a new sample + Gradle run task to validate and demonstrate the feature.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
samples/src/main/java/io/durabletask/samples/ParentInstanceSample.java New runnable sample demonstrating ctx.getParent() for sub-orchestrations vs standalone runs.
samples/build.gradle Adds runParentInstanceSample JavaExec task to run the new sample.
client/src/test/java/com/microsoft/durabletask/TaskOrchestrationExecutorTest.java Adds unit tests covering parent present/absent, replay stability, and model equality.
client/src/main/java/com/microsoft/durabletask/TaskOrchestrationExecutor.java Wires parent instance extraction from ExecutionStartedEvent.parentInstance into context implementation.
client/src/main/java/com/microsoft/durabletask/TaskOrchestrationContext.java Adds default getParent() API returning null when not a sub-orchestration.
client/src/main/java/com/microsoft/durabletask/ParentOrchestrationInstance.java Adds the new immutable parent instance model type.

@bachuv bachuv force-pushed the vabachu/parent-instance branch from 5a4752b to 56523d7 Compare May 7, 2026 17:19
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