Skip to content

Fix cancellation token race during parser comparison#4280

Merged
ericsciple merged 2 commits intomainfrom
users/ericsciple/26-03-compare
Mar 9, 2026
Merged

Fix cancellation token race during parser comparison#4280
ericsciple merged 2 commits intomainfrom
users/ericsciple/26-03-compare

Conversation

@ericsciple
Copy link
Copy Markdown
Collaborator

@ericsciple ericsciple commented Mar 6, 2026

Working on eliminating differences between old/new copies of the workflow parser/evaluator

@ericsciple ericsciple changed the title Fix cancellation token race in EvaluateAndCompare Fix cancellation token race in parser comparison Mar 6, 2026
@ericsciple ericsciple changed the title Fix cancellation token race in parser comparison Fix cancellation token race during parser comparison Mar 6, 2026
@ericsciple ericsciple force-pushed the users/ericsciple/26-03-compare branch 2 times, most recently from f00dffb to c5ea90f Compare March 6, 2026 20:14
}
}

public ExecutionContext Parent
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Unused

public ExecutionContext Root
IExecutionContext IExecutionContext.Root => Root;

private ExecutionContext Root
Copy link
Copy Markdown
Collaborator Author

@ericsciple ericsciple Mar 6, 2026

Choose a reason for hiding this comment

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

Internally (within this file) we access private members of ExecutionContext.

Publicly, callers only need IExecutionContext

List<string> StepEnvironmentOverrides { get; }

ExecutionContext Root { get; }
ExecutionContext Parent { get; }
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Unused


List<string> StepEnvironmentOverrides { get; }

ExecutionContext Root { get; }
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Switched to IExecutionContext for public callers

@ericsciple ericsciple marked this pull request as ready for review March 6, 2026 20:25
@ericsciple ericsciple requested a review from a team as a code owner March 6, 2026 20:25
Copilot AI review requested due to automatic review settings March 6, 2026 20:25
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

This PR fixes a race condition in PipelineTemplateEvaluatorWrapper.EvaluateAndCompare where a job-level cancellation (which mutates JobContext.Status) occurring between the legacy and new evaluator runs could produce a spurious mismatch. Previously, the step-level CancellationToken was monitored, but this token only fires on step timeout — not on job cancellation. The fix switches to monitoring _context.Root?.CancellationToken (the job-level token) to correctly detect the cancellation race condition.

Changes:

  • ExecutionContext.cs: Promotes Root to the IExecutionContext interface (returning IExecutionContext instead of ExecutionContext), removes the unused Parent property from the interface, and adds an explicit interface implementation that delegates to a private concrete-typed property.
  • PipelineTemplateEvaluatorWrapper.cs: Uses _context.Root?.CancellationToken ?? CancellationToken.None (job-level token) instead of _context.CancellationToken (step-level token) to detect cancellation races.
  • Test file: Updates the existing cancellation test to use _rootTokenSource in line with the new logic, adds a new test verifying that root-level cancellation during the legacy evaluator also suppresses mismatch recording, and wires up a mock root context in Setup().

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Runner.Worker/ExecutionContext.cs Exposes Root on the IExecutionContext interface (as IExecutionContext); removes Parent from the interface; adds explicit interface impl with private concrete property
src/Runner.Worker/PipelineTemplateEvaluatorWrapper.cs Switches cancellation detection to the root (job-level) token; adds using System.Threading
src/Test/L0/Worker/PipelineTemplateEvaluatorWrapperL0.cs Adds _rootTokenSource field/setup/teardown; updates existing test to use root token; adds new test for root cancellation in the legacy evaluator path

@ericsciple ericsciple force-pushed the users/ericsciple/26-03-compare branch from c5ea90f to 9c2ac0a Compare March 9, 2026 15:15
// Job cancellation mutates JobContext.Status which expression functions read,
// so we need the root token to properly detect cancellation between evaluator runs.
var rootCancellationToken = _context.Root?.CancellationToken ?? CancellationToken.None;
var cancellationRequestedBefore = rootCancellationToken.IsCancellationRequested;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This switches to the job-level cancellation token, which correctly reflects job-cancel.

@ericsciple ericsciple enabled auto-merge (squash) March 9, 2026 16:04
@ericsciple ericsciple disabled auto-merge March 9, 2026 16:05
@ericsciple ericsciple enabled auto-merge (squash) March 9, 2026 16:05
@ericsciple ericsciple merged commit 40dd583 into main Mar 9, 2026
11 checks passed
@ericsciple ericsciple deleted the users/ericsciple/26-03-compare branch March 9, 2026 16:10
dawidmalina pushed a commit to dawidmalina/github-runner that referenced this pull request Mar 19, 2026
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