Skip to content

Add legacy Helix runner compatibility shim - #17573

Merged
wfurt merged 9 commits into
dotnet:mainfrom
wfurt:wfurt/helix-legacy-runner-compat
Sep 25, 2026
Merged

wfurt merged 9 commits into
dotnet:mainfrom
wfurt:wfurt/helix-legacy-runner-compat

Conversation

@wfurt

@wfurt wfurt commented Sep 16, 2026

Copy link
Copy Markdown
Member

Summary

  • package a dependency-free Python compatibility shim with Microsoft.DotNet.Helix.JobSender
  • copy the shim beside legacy RunnerScripts/scriptrunner/scriptrunner.py through a build-transitive target
  • stage result files and script logs under HELIX_WORKITEM_UPLOAD_ROOT so the machine-side Helix client retains ownership of credentials and uploads
  • preserve legacy queues by using a namespace package without helix/__init__.py
  • document the shim as temporary and explicitly exclude credential-dependent continuationrunner.py

Motivation

New AOT Helix queues no longer install the legacy Python helix package. Existing JobSender consumers can still submit payloads that invoke scriptrunner.py, causing ModuleNotFoundError before their tests run and preventing their expected script logs and TestResults.zip from being published.

This keeps public Arcade independent from the internal machine-client implementation. The shim only implements the submitted runner surface; the Helix client continues to own storage authentication, retries, uploads, and event publication.

Validation

  • dotnet test src/Microsoft.DotNet.Helix/JobSender.Tests/Microsoft.DotNet.Helix.JobSender.Tests.csproj --no-restore — 6 passed
  • exercised the AppCompat scriptrunner.py shape end to end with a synthetic RunMstest.cmd
  • verified stdout and stderr are logged
  • verified TestResults.zip is staged under HELIX_WORKITEM_UPLOAD_ROOT
  • packed Microsoft.DotNet.Helix.JobSender.12.0.0-dev and verified all compatibility files are present
  • verified a consuming build copies the files to RunnerScripts/scriptrunner

Follow-up

The AOT client change that emits legacy Logs events for staged .helix-logs files and fails work items on upload/event-publication failures is being handled in dotnet-helix-machines.

Package a dependency-free Python compatibility surface for existing JobSender consumers and stage result uploads for the AOT Helix client.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 1878358f-1e80-41bf-a8d5-4b3d0e13d7f9
Copilot AI lite review requested due to automatic review settings September 16, 2026 23:41

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.

🟡 Changes recommended

There are correctness/resiliency issues in the new compatibility logging/test execution code that should be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR adds a dependency-free Python compatibility shim that can be packaged with Microsoft.DotNet.Helix.JobSender to keep legacy scriptrunner.py payloads working on newer Helix queues that no longer install the legacy helix Python package. The shim stages logs and result artifacts under HELIX_WORKITEM_UPLOAD_ROOT so the machine-side Helix client remains responsible for credentials and uploads.

Changes:

  • Package legacy-runner Python compatibility modules (namespace-package style, no helix/__init__.py) and a build-transitive targets file to copy them into consuming outputs under RunnerScripts/scriptrunner/helix.
  • Implement minimal helix.* runner surfaces (logging, process execution, cmdline parsing, staging “uploads” to HELIX_WORKITEM_UPLOAD_ROOT).
  • Add tests (Python unittest + C# process-driven runner) validating import surface and staging behavior; document the compatibility shim and explicitly exclude continuationrunner.py.
File summaries
File Description
src/Microsoft.DotNet.Helix/JobSender/Readme.md Documents the legacy runner shim behavior, limits, and opt-out property.
src/Microsoft.DotNet.Helix/JobSender/Microsoft.DotNet.Helix.JobSender.csproj Packs the shim files and buildTransitive targets into the JobSender NuGet.
src/Microsoft.DotNet.Helix/JobSender/legacy-runner/README.md Adds a focused README describing what the shim is and when it can be removed.
src/Microsoft.DotNet.Helix/JobSender/legacy-runner/helix/settings.py Provides environment-backed settings used by legacy runner code paths.
src/Microsoft.DotNet.Helix/JobSender/legacy-runner/helix/saferequests.py Adds an import-compatible placeholder for unused safe-requests functionality.
src/Microsoft.DotNet.Helix/JobSender/legacy-runner/helix/proc.py Implements minimal subprocess execution with output logging.
src/Microsoft.DotNet.Helix/JobSender/legacy-runner/helix/logs.py Implements logging configuration + staged log file behavior under upload root.
src/Microsoft.DotNet.Helix/JobSender/legacy-runner/helix/helixio.py Adds basic file/path helpers and directory copy utilities.
src/Microsoft.DotNet.Helix/JobSender/legacy-runner/helix/cmdline.py Implements legacy-style command-line parsing and settings overrides.
src/Microsoft.DotNet.Helix/JobSender/legacy-runner/helix/azure_storage.py Replaces direct uploads with staging under HELIX_WORKITEM_UPLOAD_ROOT.
src/Microsoft.DotNet.Helix/JobSender/legacy-runner/helix_test_execution.py Provides compatibility HelixTestExecution used by AppCompat runners.
src/Microsoft.DotNet.Helix/JobSender/buildTransitive/Microsoft.DotNet.Helix.JobSender.targets Copies shim files into consuming project output/publish under legacy runner paths.
src/Microsoft.DotNet.Helix/JobSender.Tests/Microsoft.DotNet.Helix.JobSender.Tests.csproj Adds shim files + test runner script to test output for execution.
src/Microsoft.DotNet.Helix/JobSender.Tests/LegacyRunnerCompatTests.py Adds Python behavior tests validating staging, logging, and import surface.
src/Microsoft.DotNet.Helix/JobSender.Tests/LegacyRunnerCompatProcessTests.cs Runs the Python behavior tests from xUnit as part of the test suite.
src/Microsoft.DotNet.Helix/JobSender.Tests/LegacyRunner/scriptrunner.py Provides a legacy-shaped runner script used by the compatibility tests.
Review details

Suppressed comments (1)

src/Microsoft.DotNet.Helix/JobSender/legacy-runner/helix/logs.py:51

  • set_logfile() adds a FileHandler without ensuring the destination directory exists. If HELIX_LOG_ROOT points to a non-existent directory, this will raise and prevent the runner from emitting any results/logs.
def set_logfile(path):
    _configure()
    _add_handler(logging.FileHandler(path))
  • Files reviewed: 16/16 changed files
  • Comments generated: 2
  • Review effort level: Lite

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

The Python compatibility tests inherited the ambient Helix work-item environment, so on a legacy queue the child imported the installed helix package (which wins over this namespace shim) and uploaded using real result-container tokens instead of staging. Child processes now run with a sanitized environment and skip with an explicit reason when an installed helix takes precedence.

Also emit true UTC log timestamps, create the log directory in set_logfile, and make the xUnit wrapper fall back to another interpreter name and time out instead of hanging.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 1878358f-1e80-41bf-a8d5-4b3d0e13d7f9
Copilot AI review requested due to automatic review settings September 17, 2026 04:30

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.

🔵 Needs a closer look

The new xUnit test fails outright when Python isn’t installed, making the test suite environment-dependent.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

src/Microsoft.DotNet.Helix/JobSender.Tests/LegacyRunnerCompatProcessTests.cs:84

  • This test hard-fails when no Python interpreter is present, which can make dotnet test for the repo environment-dependent (e.g., developer machines or constrained CI images). Consider skipping the test when Python isn't available, since the compatibility behavior can only be validated when an interpreter exists.
  • Files reviewed: 16/16 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@wfurt

wfurt commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

ping for review...

Copilot AI review requested due to automatic review settings September 21, 2026 18:16

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

🟡 Changes recommended

The shim has a couple of robustness gaps (path validation error handling and log file encoding) that can cause avoidable runtime failures on some environments.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 Medium severity

Open (3)

Staged logs used the machine's locale encoding. Under a non-UTF-8 locale (cp1252 on many Windows images, where AppCompat runs) logging silently dropped every non-ASCII line, so the restored script log could arrive empty.

Also accept text streams when staging, since legacy payloads may pass either stream type, and report a name that cannot be compared against the upload root as the same traversal error instead of leaking commonpath's own message.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 1878358f-1e80-41bf-a8d5-4b3d0e13d7f9
Copilot AI review requested due to automatic review settings September 21, 2026 19: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

🔵 Needs a closer look

There are correctness/reliability issues in the compatibility runner logging and the process-based tests’ interpreter resolution that should be addressed before merging.

Review effort: Lite
Findings: None

Resolved since last review (3)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Use HELIX_PYTHONPATH for reliable Python discovery

src/​Microsoft.DotNet.Helix/​JobSender.Tests/​LegacyRunnerCompatProcessTests.cs:27

The test only probes python/python3 on PATH, but Helix work items guarantee a Python executable via HELIX_PYTHONPATH (see src/Microsoft.DotNet.Helix/Sdk/Readme.md). Prefer HELIX_PYTHONPATH when present so the test runs reliably in Helix environments even if PATH doesn’t include python.

Medium severity Convert command arguments to strings before logging

src/​Microsoft.DotNet.Helix/​JobSender/​legacy-runner/​helix/​proc.py:18

run_and_log_output logs the command with " ".join(args), which will raise a TypeError if any argument is not already a str (e.g., pathlib.Path or other path-like objects that subprocess.Popen accepts). Convert items to string for logging so the compatibility runner doesn’t fail before launching the process.

mmitche
mmitche previously approved these changes Sep 22, 2026

@mmitche mmitche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this looks reasonable.

The precedence probe imported helix.logs, but the installed legacy package reads HELIX_CONFIG_ROOT and HELIX_LOG_ROOT at import time and raises without them. Since the probe deliberately runs with a sanitized environment, it crashed on legacy queues and the tests failed instead of skipping.

Resolve the module with importlib.util.find_spec, which reports which file would load without executing it, and include the child's output when resolution genuinely fails.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 1878358f-1e80-41bf-a8d5-4b3d0e13d7f9
Copilot AI review requested due to automatic review settings September 23, 2026 02:21

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

🟡 Changes recommended

Unresolved critical Python 3.4 compatibility and moderate test and credential-boundary issues block approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Use HELIX_PYTHONPATH interpreter before PATH fallbacks

src/​Microsoft.DotNet.Helix/​JobSender.Tests/​LegacyRunnerCompatProcessTests.cs:26

This test only tries python/python3 from PATH, but the documented Helix contract exposes the interpreter through HELIX_PYTHONPATH (src/Microsoft.DotNet.Helix/Sdk/Readme.md:562-574), which need not be on PATH. On a supported queue with only that configured interpreter, the test fails with “No Python interpreter was found” before exercising the shim; prefer the environment-provided executable before keeping the local fallbacks.

os.path.commonpath was added in Python 3.5, but Helix only guarantees Python >= 3.4 on the client. On such a machine every staged upload raised AttributeError, so TestResults.zip could not be staged at all. Use a relpath-based containment check, which keeps the same traversal rejection.

Also resolve helix.logs with PathFinder in the tests. importlib.util.find_spec imports the parent package first, so a legacy 'helix' package with any import-time side effect would break the probe rather than skip.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 1878358f-1e80-41bf-a8d5-4b3d0e13d7f9
Copilot AI review requested due to automatic review settings September 23, 2026 04:35

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

🟡 Changes recommended

Unresolved credential exposure and compatibility issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (2)
Previously missed (3)

In code that hasn't changed since last review

Medium severity Forward legacy --args values into script execution

src/​Microsoft.DotNet.Helix/​JobSender.Tests/​LegacyRunner/​scriptrunner.py:28

The declared --args option is only logged here; it is never added to execution_args, which is built from the positional leftovers. Any legacy payload that supplies its script arguments through --args therefore runs the script without those arguments. Pass the parsed option through using the legacy quoting semantics and cover that path in the end-to-end test.

Medium severity Use HELIX_PYTHONPATH to locate the test interpreter

src/​Microsoft.DotNet.Helix/​JobSender.Tests/​LegacyRunnerCompatProcessTests.cs:26

The test runner searches only for python/python3, but Helix guarantees the interpreter through HELIX_PYTHONPATH (see src/Microsoft.DotNet.Helix/Sdk/Readme.md:574) and that executable is not required to be on PATH. On queues exposing only the documented variable, this test fails with "No Python interpreter was found" before exercising the shim; prefer that environment variable and keep the name-based fallback for local runs.

Medium severity Replace incompatible subprocess.run usage for Python 3.4

src/​Microsoft.DotNet.Helix/​JobSender.Tests/​LegacyRunnerCompatTests.py:96

subprocess.run was added in Python 3.5, and the capture_output/text arguments require newer Python versions, but this compatibility test is run with the Helix interpreter whose documented minimum is Python 3.4. On that minimum runtime this helper raises before checking module resolution; use a Popen/communicate compatibility helper instead (and apply it to the other subprocess.run calls below).

Record why HELIX_RESULTS_CONTAINER_* is not stripped here: legacy helix.proc inherits the whole environment, the Helix client already exports those variables to the work item command that calls this, and legacy payloads may use them to upload directly. Narrowing them is a client-side decision for the whole work item.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 1878358f-1e80-41bf-a8d5-4b3d0e13d7f9
Copilot AI review requested due to automatic review settings September 23, 2026 20:45

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

🟡 Changes recommended

Address the Python 3.4 test incompatibility and the --args forwarding and HELIX_PYTHONPATH issues.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Python discovery ignores HELIX_PYTHONPATH

src/​Microsoft.DotNet.Helix/​JobSender.Tests/​LegacyRunnerCompatProcessTests.cs:26

This test is run as part of the Helix work-item test suite, where the documented Python contract is HELIX_PYTHONPATH (the executable may not be on PATH; see src/Microsoft.DotNet.Helix/Sdk/Readme.md:572-579). Searching only the bare python/python3 names can therefore fail with "No Python interpreter was found" on a supported AOT image even though the required interpreter is available. Try Environment.GetEnvironmentVariable("HELIX_PYTHONPATH") before the fallback names.

Helix only guarantees Python >= 3.4 on the client, but this suite used subprocess.run (3.5, with capture_output and text from 3.7), pathlib read_text/write_text/read_bytes (3.5), and importlib.util.module_from_spec (3.5). It therefore could not run on the interpreter the shim has to support, so it could not verify the shim there either.

Replace those with equivalents available in 3.4 and add a guard that parses the shipped shim, the runner fixture, and this suite, failing with an exact file, line, and version when anything newer appears. That is the check that would have caught the os.path.commonpath regression, which made every staged upload raise AttributeError.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 1878358f-1e80-41bf-a8d5-4b3d0e13d7f9
Copilot AI review requested due to automatic review settings September 23, 2026 21:23

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

🟡 Changes recommended

Unresolved critical and moderate review findings must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Use HELIX_PYTHONPATH before PATH interpreter fallbacks

src/​Microsoft.DotNet.Helix/​JobSender.Tests/​LegacyRunnerCompatProcessTests.cs:27

The test only probes python/python3 on PATH, but Helix guarantees the interpreter through HELIX_PYTHONPATH and does not guarantee either alias is present. Because this project is submitted as a Helix work item, an image exposing only the documented executable variable will report that no interpreter was found and fail before exercising the shim. Try HELIX_PYTHONPATH first, then retain the PATH fallbacks.

The Helix SDK readme has claimed HELIX_PYTHONPATH is only guaranteed to be >= 3.4 since 2020, a year after 3.4 reached end of life. No queue has been anywhere near it for years: Windows installs 3.13/3.14, and the oldest system interpreter in the fleet is 3.9 on AzureLinux 3 and Raspbian 11. The stale number forced hand-written stand-ins for os.path.commonpath, subprocess.run, pathlib read_text/write_text/read_bytes, and module_from_spec, which added noise without protecting any real machine.

Document 3.9, which is what the images actually provide, and drop the workarounds and the version guard that only existed to satisfy 3.4. The genuine fixes stay: UTF-8 log staging, text-stream support, UTC timestamps, directory creation in set_logfile, PathFinder resolution, and the drive-mismatch ValueError.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 1878358f-1e80-41bf-a8d5-4b3d0e13d7f9
Copilot AI review requested due to automatic review settings September 23, 2026 21:47

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

🔵 Needs a closer look

The process test should check HELIX_PYTHONPATH before PATH-based Python fallbacks.

Review effort: Lite
Findings: 1 High severity

Open (1)

@wfurt

wfurt commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

/azp run arcade-pr

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@wfurt

wfurt commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

please take another look @mmitche. As we discussed yesterday I did take a look at the Python versions. The legacy already used construct that needs at least 3.9 e.g. the 3.4 in docs was just an obsolete statement. A3 uses 3.9.4 and that seems the oldest we have in the queues.

@wfurt
wfurt merged commit 89377f4 into dotnet:main Sep 25, 2026
17 checks passed
@wfurt
wfurt deleted the wfurt/helix-legacy-runner-compat branch September 25, 2026 20:51
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 27, 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