Skip to content

fix: read protobuf StringValue activity input with getValue#280

Open
YunchuWang wants to merge 1 commit into
mainfrom
copilot-finds/bug/fix-protobuf-tostring-activity-input
Open

fix: read protobuf StringValue activity input with getValue#280
YunchuWang wants to merge 1 commit into
mainfrom
copilot-finds/bug/fix-protobuf-tostring-activity-input

Conversation

@YunchuWang

Copy link
Copy Markdown
Member

Summary

Fixes #223

…activity execution

Replace incorrect .toString() call on protobuf StringValue with the correct
.getValue() API in _executeActivityInternal. The toString() method on protobuf
Message objects calls the base class implementation which relies on internal
array representation, not the documented field accessor.

Also remove redundant .toString() on the activity result (already a string).

Add tests verifying activity input extraction and result serialization.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 18, 2026 17:15

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.

Pull request overview

This PR fixes activity input extraction in the gRPC worker by using the documented protobuf StringValue.getValue() accessor instead of relying on toString()’s incidental behavior, aligning the worker with stable protobuf APIs and the rest of the SDK’s wrapper usage. It also updates the activity result handling to avoid redundant string coercion and adds tests around input/output behavior.

Changes:

  • Read ActivityRequest.input via req.getInput()?.getValue() instead of toString().
  • Remove redundant .toString() when setting the activity result StringValue.
  • Add worker-level tests for activity input deserialization and result serialization.

Reviewed changes

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

File Description
packages/durabletask-js/src/worker/task-hub-grpc-worker.ts Uses StringValue.getValue() for activity input and avoids redundant output string coercion.
packages/durabletask-js/test/worker-activity-response.spec.ts Adds tests for activity input extraction and ActivityResponse result encoding/empty-result behavior.

Comment on lines +114 to +125
const mockStub = createMockStub();
const testInput = { key: "value", nested: { arr: [1, 2, 3] } };
const req = createActivityRequest("inputCapturingActivity", JSON.stringify(testInput));

// Act
await (worker as any)._executeActivityInternal(req, COMPLETION_TOKEN, mockStub.stub);

// Assert — the activity must receive the deserialized input object
expect(receivedInput).toEqual(testInput);
expect(mockStub.capturedResponse).not.toBeNull();
expect(mockStub.capturedResponse!.getResult()?.getValue()).toBe(JSON.stringify("done"));
});
Comment on lines +127 to +150
it("should pass empty string as input when protobuf StringValue is not set", async () => {
// Arrange
const worker = new TaskHubGrpcWorker({
logger: new NoOpLogger(),
});

let receivedInput: unknown = "sentinel";
const inputCapturingActivity = (_ctx: ActivityContext, input: unknown) => {
receivedInput = input;
return "done";
};

worker.addActivity(inputCapturingActivity);

const mockStub = createMockStub();
// Create request WITHOUT setting input — simulates no input from sidecar
const req = createActivityRequest("inputCapturingActivity");

// Act
await (worker as any)._executeActivityInternal(req, COMPLETION_TOKEN, mockStub.stub);

// Assert — no input means the activity receives undefined (empty string is parsed as falsy by executor)
expect(receivedInput).toBeUndefined();
});
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.

[copilot-finds] Bug: _executeActivityInternal uses toString() instead of getValue() on protobuf StringValue, relying on undocumented internal behavior

3 participants