Skip to content

feat: expose activity request name and version in context - #370

Merged
wangbill (YunchuWang) merged 1 commit into
mainfrom
yunchuwang-activity-context-metadata
Sep 23, 2026
Merged

wangbill (YunchuWang) merged 1 commit into
mainfrom
yunchuwang-activity-context-metadata

Conversation

@YunchuWang

Copy link
Copy Markdown
Member

Summary

What changed?

  • Activities can now read readonly ctx.name and ctx.version, populated from the actual activity request. Logical aliases and version casing are preserved, including when an unversioned registration handles a versioned request.
  • Keep new ActivityContext(orchestrationId, taskId) compatible by adding optional trailing name/version arguments. Missing metadata defaults to ""; a null version from JavaScript also becomes "". Existing IDs are unchanged.
  • Add focused context/executor and real loopback-gRPC coverage, API JSDoc, and core release notes.

Why is this change needed?

  • Before: activity code could inspect only its orchestration/task IDs, not the requested task identity. After: it can distinguish requests using ctx.name and ctx.version without depending on the implementation function name, registration version, or worker default.
  • Match .NET TaskActivityContext.Name / Version and the TaskActivityShim request mapping.

Issues / work items


Project checklist

  • Release notes are not required for the next release
    • Otherwise: Notes added to CHANGELOG.md
  • Backport is not required
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • All required tests have been added/updated (unit tests, E2E tests)
  • Breaking change?
    • If yes:
      • Impact: N/A; additive getters and optional trailing constructor parameters.
      • Migration guidance: N/A.

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.
  • AI-assisted areas/files: Activity context, executor context construction, two focused test files, and changelog.
  • What you changed after AI output: Human edits/review have not been asserted; human verification boxes remain unchecked.

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: Passed. TDD first produced 11 runtime missing-metadata failures (not compilation failures); all 63 tests across the five focused suites then passed.
  • npm test -w @microsoft/durabletask-js -- --runTestsByPath test\activity_executor.spec.ts test\versioned-dispatch-grpc.spec.ts test\versioned-dispatch.spec.ts test\versioned-in-memory.spec.ts test\worker-activity-response.spec.ts
  • npm run build:core and npm run build -w @microsoft/durabletask-js-export-history passed; the latter checks an existing ActivityContext-typed consumer.
  • Scoped ESLint on the four changed TypeScript files, scoped Prettier, and git diff --check passed. The executor test file retains existing CRLF and pre-existing formatting outside the new test region.
  • No full-suite, live Azure, emulator, or Functions-host validation was run. Hosted CI is separate from this local evidence.

Manual validation (only if runtime/behavior changed)

  • Environment (OS, Node.js version, components): Windows, Node.js v24.14.0; in-process grpc-js server bound to loopback.
  • Steps + observed results:
    1. Automated gRPC fixture streams actual serialized ActivityRequests through TaskHubGrpcWorker and receives ActivityResponses.
    2. Activity code receives the request alias, original-case version, and unchanged IDs; fallback, missing, and explicit-empty versions are covered with a distinct worker default.
    3. No separate manual service validation.
  • Evidence (optional): Local RED/GREEN/build/lint logs retained in the Copilot session artifacts.

Notes for reviewers

  • Only two production files change. Registration, acceptance/filtering, version inheritance, retries, protocol, serialization, and backends are unchanged.
  • Empty defaults preserve legacy manual construction without inventing metadata; the executor supplies the authoritative values for actual invocations.

Preserve request identity through versioned dispatch and legacy fallback while retaining two-argument ActivityContext construction.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e0af01a5-0dfa-4e71-a660-c4186e65d7e0
Copilot AI lite review requested due to automatic review settings September 23, 2026 16:22

Copilot AI left a comment

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.

Copilot review overview

🟢 Approval recommended

No unresolved review issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Adds request-level activity name and version metadata to ActivityContext while preserving compatibility and version casing.

Changes:

  • Adds readonly name and version getters with empty defaults.
  • Populates metadata from activity requests.
  • Adds unit, executor, gRPC, and changelog coverage.
File Description
packages/​durabletask-js/​test/​versioned-dispatch-grpc.spec.ts Verifies metadata propagation over gRPC.
packages/​durabletask-js/​test/​activity_executor.spec.ts Tests compatibility and metadata behavior.
packages/​durabletask-js/​src/​worker/​activity-executor.ts Populates context from activity requests.
packages/​durabletask-js/​src/​task/​context/​activity-context.ts Adds activity metadata getters and defaults.
CHANGELOG.md Documents the new API.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@YunchuWang
wangbill (YunchuWang) merged commit 6505acd into main Sep 23, 2026
31 checks passed
@YunchuWang
wangbill (YunchuWang) deleted the yunchuwang-activity-context-metadata branch September 23, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants