-
Notifications
You must be signed in to change notification settings - Fork 52
Extended sessions for entities in .NET isolated #507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
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 extends the extended sessions feature to entities in .NET isolated, bringing entities to feature parity with orchestrations. The implementation refactors shared logic between GrpcOrchestrationRunner and GrpcEntityRunner into a new utility class and applies the same extended session caching pattern to entities.
Key Changes:
- Introduced
GrpcInstanceRunnerUtilsto share request property parsing and cache initialization logic - Added extended sessions support to
GrpcEntityRunnerwith state caching capabilities - Updated parameter naming from
IncludePastEventstoIncludeStatethroughout tests for consistency
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Worker/Grpc/GrpcInstanceRunnerUtils.cs | New utility class containing shared logic for parsing request properties and initializing extended sessions cache |
| src/Worker/Grpc/GrpcEntityRunner.cs | Added new overload with extended sessions support and implemented entity state caching logic |
| src/Worker/Grpc/GrpcOrchestrationRunner.cs | Refactored to use shared utility for request property parsing and cache initialization |
| test/Worker/Grpc.Tests/GrpcEntityRunnerTests.cs | New comprehensive test suite covering extended sessions scenarios for entities |
| test/Worker/Grpc.Tests/GrpcOrchestrationRunnerTests.cs | Updated tests to use IncludeState parameter naming and improved variable naming consistency |
Comments suppressed due to low confidence (1)
src/Worker/Grpc/GrpcOrchestrationRunner.cs:210
- Variable extendedSessions may be null at this access as suggested by this null check.
Variable extendedSessions may be null at this access as suggested by this null check.
extendedSessions.Set<ExtendedSessionState>(
| /// </summary> | ||
| /// <remarks> | ||
| /// If any request property is missing or invalid (i.e. the key is misspelled or the value is of the wrong type), | ||
| /// extended sessions are not enabled and default values are assigned are assigned to the returns. |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate word "are assigned" in the documentation. Should be "extended sessions are not enabled and default values are assigned to the returns."
| /// extended sessions are not enabled and default values are assigned are assigned to the returns. | |
| /// extended sessions are not enabled and default values are assigned to the returns. |
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text; |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused using statement for System.Text. This namespace appears to be included but not used anywhere in the file.
| using System.Text; |
| byte[] requestBytes = entityRequest.ToByteArray(); | ||
| string requestString = Convert.ToBase64String(requestBytes); | ||
| string responseString = await GrpcEntityRunner.LoadAndRunAsync(requestString, new SimpleEntity(), extendedSessions); | ||
| Protobuf.OrchestratorResponse response = Protobuf.OrchestratorResponse.Parser.ParseFrom(Convert.FromBase64String(responseString)); |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect response type used. The test parses the response as Protobuf.OrchestratorResponse when it should be Protobuf.EntityBatchResult (as used in the other tests).
| Protobuf.OrchestratorResponse response = Protobuf.OrchestratorResponse.Parser.ParseFrom(Convert.FromBase64String(responseString)); | |
| Protobuf.EntityBatchResult response = Protobuf.EntityBatchResult.Parser.ParseFrom(Convert.FromBase64String(responseString)); |
| addToExtendedSessions = true; | ||
|
|
||
| // If an entity state was provided, even if we already have one stored, we always want to use the provided state. | ||
| if (!entityStateIncluded && extendedSessions.TryGetValue(request.InstanceId, out string? entityState)) |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing null check for cached entity state. If a null value is stored in the cache (similar to the scenario tested in GrpcOrchestrationRunnerTests.NullExtendedSessionStored_Means_NeedsExtendedSessionNotUsed), this code will incorrectly set stateCached = true and use the null state. The orchestration runner has an explicit && extendedSessionState is not null check on line 149 of GrpcOrchestrationRunner.cs that should be mirrored here. The condition should be:
if (!entityStateIncluded && extendedSessions.TryGetValue(request.InstanceId, out string? entityState) && entityState is not null)| if (!entityStateIncluded && extendedSessions.TryGetValue(request.InstanceId, out string? entityState)) | |
| if (!entityStateIncluded && extendedSessions.TryGetValue(request.InstanceId, out string? entityState) && entityState is not null) |
| return entityBatchRequest; | ||
| } | ||
|
|
||
| class SimpleEntity : TaskEntity<int?> |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Private test class should be sealed. According to the coding guidelines, "Ensure that all private classes, that do not serve as base classes, are sealed." This class should be declared as sealed class SimpleEntity : TaskEntity<int?>.
|
|
||
| if (addToExtendedSessions) | ||
| { | ||
| extendedSessions.Set( |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable extendedSessions may be null at this access as suggested by this null check.
Variable extendedSessions may be null at this access as suggested by this null check.
| extendedSessions.Set( | |
| extendedSessions?.Set( |
| byte[] requestBytes = entityRequest.ToByteArray(); | ||
| string requestString = Convert.ToBase64String(requestBytes); | ||
| string responseString = await GrpcEntityRunner.LoadAndRunAsync(requestString, new SimpleEntity(), extendedSessions); | ||
| Protobuf.OrchestratorResponse response = Protobuf.OrchestratorResponse.Parser.ParseFrom(Convert.FromBase64String(responseString)); |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to response is useless, since its value is never read.
| Protobuf.OrchestratorResponse response = Protobuf.OrchestratorResponse.Parser.ParseFrom(Convert.FromBase64String(responseString)); |
| string stringResponse = GrpcOrchestrationRunner.LoadAndRun(requestString, new SimpleOrchestrator(), extendedSessions); | ||
| Protobuf.OrchestratorResponse response = Protobuf.OrchestratorResponse.Parser.ParseFrom(Convert.FromBase64String(stringResponse)); | ||
| string responseString = GrpcOrchestrationRunner.LoadAndRun(requestString, new SimpleOrchestrator(), extendedSessions); | ||
| Protobuf.OrchestratorResponse response = Protobuf.OrchestratorResponse.Parser.ParseFrom(Convert.FromBase64String(responseString)); |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to response is useless, since its value is never read.
| Protobuf.OrchestratorResponse response = Protobuf.OrchestratorResponse.Parser.ParseFrom(Convert.FromBase64String(responseString)); |
This PR introduces the extended sessions feature for entities in .NET isolated. It essentially copies what was done to enable extended sessions for orchestrations in the
GrpcOrchestrationRunnerinto theGrpcEntityRunner, and introduces a new class for shared logic between the two.