Skip to content

Add /parallel-audit agentic workflow, bump testfx, adopt [ResourceLock] - #55527

Merged
Evangelink merged 5 commits into
mainfrom
dev/amauryleve/resource-lock-agentic-workflow
Aug 3, 2026
Merged

Evangelink merged 5 commits into
mainfrom
dev/amauryleve/resource-lock-agentic-workflow

Conversation

@Evangelink

@Evangelink Evangelink commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Ports microsoft/testfx's parallel-safety audit agentic workflow into this repo, takes the current testfx build, and starts using the [ResourceLock] attribute the audit is about.

1. /parallel-audit agentic workflow

Ported from microsoft/testfx#10252 (.github/workflows/shared/parallel-safety-audit-shared.md @ 7c5348a4). A maintainer comments /parallel-audit on a PR and the agent audits the MSTest tests that PR changes for parallel-safety — process-global state mutation, shared filesystem paths, mismatches between what a test touches and the [ResourceLock]/[DoNotParallelize] it declares, and over-serialization — then posts one ranked, scope-aware, confidence-tagged comment. Read-only and advisory.

  • .github/workflows/parallel-safety-audit-command.md — the /parallel-audit command.
  • .github/workflows/shared/parallel-safety-audit-shared.md — tools, permissions, the deterministic bash pre-extraction, and the prompt.

Upstream's automatic on-open variant is deliberately not ported. I did port it initially, and it failed on this PR's own open event — which is how the constraint surfaced. Every job of a PAT-pool workflow runs in the copilot-pat-pool environment, whose deployment branch policy allows main only; shared/pat_pool.README.md asks for "Protected branches only" precisely so agentic workflows stay on protected branches. A pull_request run is on refs/pull/<n>/merge, so GitHub rejects it before any step executes:

Branch "refs/pull/55527/merge" is not allowed to deploy to copilot-pat-pool
due to environment protection rules.

The only way to get a protected-branch ref for a PR event is pull_request_target, which would hand a privileged token and the PAT pool to a job that checks out untrusted PR head code and runs an agent over it. That is not a trade worth making for an advisory audit, so the audit is maintainer-invoked only. The reasoning is recorded at the top of the workflow so it is not re-added into the same wall. This also happens to settle the cost/noise question: no automatic runs, no per-PR credit burn, and nothing posted unless a human asked.

Adapted to this repo:

  • gh-aw plumbing follows issue-triage.md / add-tactics-template-on-comment.md: PAT-pool import, environment: copilot-pat-pool, engine: copilot, cli-proxy + github: mode: gh-proxy, actions/checkout on the pin already in .github/aw/actions-lock.json.
  • No strategy: centralized — that compiles down to a bare workflow_dispatch and depends on a repository-wide command router (testfx has agentic_commands.yml; this repo does not), so the command would never have fired. The default strategy compiles to a real issue_comment trigger, matching add-tactics-template-on-comment.md.
  • test/TestAssets/ and test/TestPackages/ are excluded from the audit surface — they are test inputs, not test code.
  • Step 0 describes this repo's opt-in model (MSTestParallelizeScope + test/Directory.Build.props), not a hand-written [assembly: Parallelize].
  • MSTEST0074–0077 are described as shipping rules that are build errors here (MSTestAnalysisMode=Recommended + TreatWarningsAsErrors), so the audit's stated value is what the analyzers cannot see: mutations reached through helpers/fixtures, cross-test collision judgement, and runsettings-only opt-ins.
  • Repository-specific fixture guidance: SdkTest, TestAssetsManager identifier: collisions, TestCommand.WithEnvironmentVariable.

The shared file header records the upstream path/commit and the list of adaptations to re-apply when syncing, and the prompt tells the agent to verify repository facts (which projects opt in, MSTestPackageVersion, MSTestAnalysisMode, TreatWarningsAsErrors) against HEAD rather than trusting the prompt text.

2. testfx dependency bump

Ordinary Darc uptake of the current testfx build: Microsoft.Testing.Platform, MSTest and MSTest.Sdk 4.4.0-preview.26376.8 → 4.4.0-preview.26379.6, all three on the same sha per the KEEP IN SYNC comment. [ResourceLock] already existed at the old pin; the payload here is the new parallel-safety analyzers MSTEST0074–0077 (plus MSTEST0078–0080). Happy to split this into its own PR if that makes diagnosis or revert easier.

3. [ResourceLock] adoption and the bugs the bump found

Only three test projects enable parallelization, so only they are analyzer-visible. I built all three.

  • Microsoft.NET.Build.Tests — MSTEST0074 fired on a real latent bug: It_fails_build_on_failed_sdk_resolution set MSBUILDINCLUDEDEFAULTSDKRESOLVER process-wide, which every MSBuild started by a concurrently running test inherits, breaking SDK resolution for those tests. Fixed by elimination — the variable is now scoped to the build under test with TestCommand.WithEnvironmentVariable, so the try/finally restore is no longer needed.
  • DockerDaemonTests — class-level [DoNotParallelize] replaced by [ResourceLock(WellKnownResources.EnvironmentVariables)] on the one test that mutates DOCKER_HOST, so the other 10 tests in the class stop being deferred to the serial tail.
  • AuthHandshakeMessageHandlerTests — keeps [DoNotParallelize]. Parallelizing it fails because the tests are coupled through AuthHandshakeMessageHandler's private static credential cache: a [ResourceLock] can take a custom key for it but cannot reset it between tests. While investigating I found ConfigAuthWithIdentityToken emitting invalid JSON (unquoted identitytoken value), masked because the cache short-circuits the parse — quoted here, root cause tracked in AuthHandshakeMessageHandlerTests are order-dependent through a process-wide static credential cache #55526.
  • test/AGENTS.md — parallel-safety guidance, in priority order: eliminate the shared state → [ResourceLock] → [DoNotParallelize].

Validation

  • gh aw compile — 0 errors, 0 warnings; .github/aw/actions-lock.json left untouched. Verified the compiled workflow carries a real issue_comment trigger.
  • Replayed the extraction bash under Git Bash against this branch: it emits the three changed test files, their exact HEAD-side line ranges, and the revision files.
  • Microsoft.NET.Build.Containers.UnitTests: 292 total, 0 failed, 286 succeeded, 6 skipped (run repeatedly).
  • Microsoft.NET.Build.Tests and dotnet-watch.Tests build clean with TreatWarningsAsErrors after the fix.

Security review of the generated workflow

gh aw compile flagged the COPILOT_PAT_0–COPILOT_PAT_9 secrets as new to this workflow file. They are the repository's existing Copilot PAT pool, consumed through the unmodified shared/pat_pool.md import exactly as issue-triage.md and add-tactics-template-on-comment.md already do; no new secret is introduced to the repository and none is exposed to the agent (the PAT only populates COPILOT_GITHUB_TOKEN for the engine, and per pat_pool.README.md it carries only Copilot-requests read permission). No new actions are introduced: actions/checkout uses the SHA already pinned in .github/aw/actions-lock.json. Permissions stay at contents: read + pull-requests: read + copilot-requests: write; the agent is read-only over the code and its single writing capability is the add-comment safe output. Network is defaults.

Worth a reviewer's explicit attention: this workflow runs on issue_comment (so, on main with secrets available) and checks out the PR head to analyze it. That is deliberate and is what roles: [admin, maintainer, write] gates — a trusted user has to ask for each audit. Auditing fork PRs is supported for the same reason. The residual risk is prompt injection from PR content steering the report, which is bounded by the read-only PAT and the safe-outputs-only write path; the prompt also frames PR content as untrusted. The one item a human should confirm is that the lock file was generated with gh-aw v0.83.1 while the repo's existing locks were generated with v0.82.9 — the compiler version differs, but I reverted the incidental .github/aw/actions-lock.json churn so no shared pin changed.

Notes for reviewers

Reviewed in several rounds; the notable fixes were:

  • The ported prompt referenced ${{ steps.* }} outputs produced in the agent job while gh-aw renders the prompt in the activation job, so the agent received literal unresolved expression text for every input — including the PR number its comment must target. Extraction now writes to fixed files under /tmp/gh-aw/parallel-safety-audit/ that the prompt reads.
  • The prompt told the agent to git diff deleted content but gave it no revision; a bare git diff in a clean checkout prints nothing, which would have silently dropped exactly the "someone removed a [ResourceLock]" findings. It now gets merge-base.txt / head-sha.txt and uses them explicitly.
  • The two activation bugs described above.

Evangelink and others added 3 commits July 29, 2026 19:25
…rceLock]

Ports microsoft/testfx's parallel-safety audit agentic workflow
(microsoft/testfx#10252) into dotnet/sdk and starts using the [ResourceLock]
feature it audits for.

Workflow (.github/workflows/parallel-safety-audit{,-command}.md and
shared/parallel-safety-audit-shared.md):
- Adapted to this repo's gh-aw conventions: PAT-pool import, Copilot engine,
  cli-proxy + github gh-proxy tooling, fork guard, repo-pinned actions/checkout.
- Adapted to this repo's test tree: test/TestAssets and test/TestPackages are
  excluded from the audit surface (they are test inputs, not test code), the
  MSTestParallelizeScope opt-in model and the test/Directory.Build.props default
  are described, and TestAssetsManager identifier collisions are called out.
- MSTEST0074-0077 are described as shipping analyzers (they are now, see below)
  rather than in-flight, including that MSTestAnalysisMode=Recommended plus
  TreatWarningsAsErrors makes them build errors here.

Dependencies: bump Microsoft.Testing.Platform, MSTest and MSTest.Sdk from
4.4.0-preview.26376.8 to *.26379.6 (darc), which brings in the parallel-safety
analyzers MSTEST0073-MSTEST0077.

Findings from the bump:
- MSTEST0074 fired in Microsoft.NET.Build.Tests: It_fails_build_on_failed_sdk_resolution
  set MSBUILDINCLUDEDEFAULTSDKRESOLVER process-wide, which every concurrently
  started MSBuild inherits. Scoped it to the build under test with
  TestCommand.WithEnvironmentVariable instead.
- DockerDaemonTests only needed DOCKER_HOST serialized in one test, so the
  class-level [DoNotParallelize] is replaced by
  [ResourceLock(WellKnownResources.EnvironmentVariables)] on that test, letting
  the other 10 tests run in parallel.
- AuthHandshakeMessageHandlerTests keeps [DoNotParallelize]: it is order-dependent
  through AuthHandshakeMessageHandler's process-wide static credential cache,
  which a resource lock cannot cover. Comment updated to explain why.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: c54ee239-4f8b-4400-af31-01010123c057
…ct guidance

Review round 1 findings.

Critical - the agent never received its inputs. The prompt referenced
`steps.resolve.outputs.*` / `steps.extract.outputs.*` GitHub expressions, but
gh-aw renders and interpolates the prompt in the `activation` job while those
steps run later in the `agent` job, so every one of them reached the agent as
literal, unresolved expression text - including the PR number the `add-comment`
safe output must target (`target: "*"` has no implicit target). The extraction
steps now write their results to fixed paths under
`/tmp/gh-aw/parallel-safety-audit/` (pr-number.txt, audit-mode.txt, the three
file lists and the region TSV) and the prompt hard-codes those paths.
`/tmp/gh-aw` rather than the workspace, because gh-aw runs its own
`Checkout PR branch` step after ours. Verified by replaying the extraction over
this branch: it emits the three changed test files and their exact HEAD-side
line ranges.

High - `[ResourceLock(WellKnownResources.EnvironmentVariables | CurrentDirectory
| Console)]` does not compile: `WellKnownResources` members are `const string`,
not `[Flags]`, and the attribute takes a single resource. Both the prompt and
test/AGENTS.md now show the stacked form, which is what `AllowMultiple = true`
is for.

Trigger and noise:
- Drop `synchronize`. dotnet/sdk sees ~10 PRs/day and ~60% touch `test/**`;
  re-auditing every push multiplied that by commits-per-PR for a report that
  rarely changes. `/parallel-audit` refreshes on demand.
- Guard fork PRs with `head.repo.full_name == github.repository`.
  `repository.fork` describes the base repo, so it only stops runs inside forks
  of dotnet/sdk; `pull_request` runs from forks get no secrets and would fail on
  the PAT pool.
- On an automatic run the agent now stays silent (`noop`) unless it has a
  finding or the PR changed parallelization state. Most test PRs here are
  scope=off, so a "nothing to flag" comment on each would be pure noise.
  `/parallel-audit` always answers.

Drift:
- Record the upstream path/commit and the list of dotnet/sdk adaptations to
  re-apply when syncing.
- Stop hardcoding which projects opt in and asserting the analyzer/warning
  settings; tell the agent to read them at HEAD instead.

Tests:
- `ConfigAuthWithIdentityToken` emitted invalid JSON (an unquoted
  `identitytoken` value). It only passes today because the static credential
  cache short-circuits the parse. Quoted it.
- Correct the `AuthHandshakeMessageHandlerTests` comment: a `[ResourceLock]` can
  take a custom key for the cache, but it cannot reset the cache between tests,
  and the cache is private with no way to clear it - order dependence, not key
  coverage, is why the class stays serialized.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: c54ee239-4f8b-4400-af31-01010123c057
- The prompt told the agent to `git diff` the removed side of deletion-only
  hunks and of deleted config files, but never gave it a revision. Its working
  directory is the PR head with a clean tree, so a bare `git diff <path>` prints
  nothing - silently dropping exactly the findings that matter most (a removed
  `[ResourceLock]`, `[DoNotParallelize]` or `finally` restore). Guessing
  `origin/<base>...HEAD` would not work either, because gh-aw's own
  `Checkout PR branch` step re-fetches shallowly over our full clone. Extraction
  now writes `merge-base.txt` and `head-sha.txt` alongside the other inputs and
  the prompt uses `git diff "$AUDIT_BASE" "$AUDIT_HEAD" -- <path>` everywhere.

- Remove the `has_changed_tests` step output. Nothing consumed it after the
  previous commit dropped the other outputs, and its comment claimed otherwise.

- On an automatic run, suppress readiness-only reports: a finding against an
  assembly whose scope is `off` (or that is not an MSTest suite) no longer
  justifies a comment on its own. Most test PRs here touch only scope=off
  projects, and advice about a suite that does not run in parallel is not worth
  interrupting a PR for. `/parallel-audit` still always answers.

- Point the `AuthHandshakeMessageHandlerTests` comment at the tracking issue
  (#55526) instead of saying "tracked separately", and stop implying
  `[DoNotParallelize]` is an ordering contract - it serializes execution, and
  what these tests rely on is the declaration order that happens to preserve.

- Rename the workflow now that it no longer runs on `synchronize`; the old name
  surfaced in the Actions UI and in the comment footer.

Verified by replaying the extraction bash over this branch: it emits the three
changed test files, their HEAD-side line ranges, and the two new revision files.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: c54ee239-4f8b-4400-af31-01010123c057
Copilot AI review requested due to automatic review settings July 29, 2026 18:37
@Evangelink
Evangelink requested review from a team, lbussell and mthalman as code owners July 29, 2026 18:37
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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 ports the microsoft/testfx parallel-safety audit agentic workflow into dotnet/sdk, bumps the in-repo testfx dependency versions, and adopts MSTest’s [ResourceLock] in a couple of parallelized test areas to address (or better-scope) analyzer findings and reduce unnecessary serialization.

Changes:

  • Add an agentic workflow (automatic + /parallel-audit command) to audit changed MSTest tests for parallel-safety and appropriate locking/parallelization declarations.
  • Update testfx-related dependency pins (Microsoft.Testing.Platform, MSTest, MSTest.Sdk) to 4.4.0-preview.26379.6/2.4.0-preview.26379.6 in the usual version files.
  • Fix/adjust tests for parallel-safety: scope MSBUILDINCLUDEDEFAULTSDKRESOLVER to a child process; replace class-wide [DoNotParallelize] with a method-level [ResourceLock] where appropriate; correct identity-token JSON emission.
Show a summary per file
File Description
test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildWithGlobalJson.cs Scope an env var to the launched build process (avoid process-wide mutation).
test/Microsoft.NET.Build.Containers.UnitTests/DockerDaemonTests.cs Replace class-wide non-parallelization with a targeted [ResourceLock] on the env-var mutating test.
test/Microsoft.NET.Build.Containers.UnitTests/AuthHandshakeMessageHandlerTests.cs Expand rationale for [DoNotParallelize] and fix identity-token JSON quoting.
test/AGENTS.md Add guidance on fixing parallel-safety analyzer findings and choosing [ResourceLock] vs [DoNotParallelize].
global.json Bump MSTest.Sdk MSBuild SDK version.
eng/Version.Details.xml Uptake new testfx dependency versions + sha (KEEP IN SYNC group).
eng/Version.Details.props Update generated version properties for the same testfx bump.
.github/workflows/shared/parallel-safety-audit-shared.md Add shared workflow/prompt body and deterministic extraction logic.
.github/workflows/parallel-safety-audit.md Add the automatic PR-open/ready workflow wiring (imports, permissions, triggers).
.github/workflows/parallel-safety-audit.lock.yml Add the compiled gh-aw lock workflow output.
.github/workflows/parallel-safety-audit-command.md Add /parallel-audit slash-command workflow wiring.

Copilot's findings

  • Files reviewed: 10/12 changed files
  • Comments generated: 1

@Evangelink
Evangelink enabled auto-merge July 30, 2026 11:39
Evangelink and others added 2 commits July 30, 2026 13:43
It guarantees mutual exclusion and deferral (the class runs sequentially,
after the parallelizable set), not a test execution order. Describe what it
actually buys here - preventing concurrent execution, which is what makes the
shared static cache deterministic enough for the suite to pass today - and
keep the emphasis on the real fix, giving each data row its own registry name
(#55526).

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: c54ee239-4f8b-4400-af31-01010123c057
…r command

The audit workflow failed on this PR's own open event, and the command variant
would never have fired at all. Two separate activation bugs, both found by
inspecting run 30480738833.

1. The automatic `pull_request` variant cannot work in a dotnet org repository.
   `pre_activation` failed in 2 seconds with no steps and no runner, and the job
   annotation says:

     Branch "refs/pull/55527/merge" is not allowed to deploy to copilot-pat-pool
     due to environment protection rules.

   Every job of a PAT-pool workflow runs in the `copilot-pat-pool` environment,
   whose deployment branch policy allows `main` only. That restriction is
   deliberate - `shared/pat_pool.README.md` calls for "Protected branches only"
   so agentic workflows are confined to protected branches. A `pull_request` run
   is on `refs/pull/<n>/merge`, so it is rejected before any step executes. This
   is why the repo's existing agentic workflows trigger on `issues` and
   `issue_comment`, which run on `main`.

   The only way to get a protected-branch ref for a PR event is
   `pull_request_target`, which would hand a privileged token and the PAT pool to
   a job that checks out untrusted PR head code and runs an agent over it. Not a
   trade worth making for an advisory audit, so the automatic variant is removed
   and the audit is maintainer-invoked only.

2. `strategy: centralized` was carried over from testfx, which has a
   repository-wide command router (`agentic_commands.yml`). dotnet/sdk has none,
   and centralized compiles the workflow down to a bare `workflow_dispatch`, so
   `/parallel-audit` would never have fired. Removed, so it compiles to a real
   `issue_comment` trigger like `add-tactics-template-on-comment.md`.

Follow-on simplification: with a single maintainer-invoked entry point there is
no "automatic" mode, so the audit always answers. Removed the mode plumbing
(`MODE` output, `audit-mode.txt`, the pull_request branch of the resolve step and
its now-unused event inputs) and the stay-silent branching in the prompt.

The reason the automatic variant is absent is recorded at the top of
parallel-safety-audit-command.md so it is not re-added into the same wall.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: c54ee239-4f8b-4400-af31-01010123c057
@Evangelink Evangelink changed the title Port testfx parallel-safety audit workflow, bump testfx, adopt [ResourceLock] Add /parallel-audit agentic workflow, bump testfx, adopt [ResourceLock] Jul 30, 2026
@Evangelink
Evangelink merged commit 04f3a37 into main Aug 3, 2026
22 checks passed
@Evangelink
Evangelink deleted the dev/amauryleve/resource-lock-agentic-workflow branch August 3, 2026 13:28
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Aug 4, 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