Skip to content

[copilot] Improve agent instructions and skills from session analysis - #13521

Merged
jonathanpeppers merged 9 commits into
mainfrom
simonrozsival-copilot-setup-session-analysis
Nov 13, 2026
Merged

jonathanpeppers merged 9 commits into
mainfrom
simonrozsival-copilot-setup-session-analysis

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Context: https://platform.claude.com/docs/en/agents-and-tools/agent-skills/best-practices

A review of recent Copilot agent sessions in this repository found that agents lost most of their time to the build and device environment and to over-engineered first attempts, not to the code changes themselves. Agents repeatedly rediscovered the same build workarounds and spent many turns coordinating builds and emulators with each other.

Build entry point

copilot-instructions.md and the tests skill prescribed make prepare && make all. make all skips BuildExtraApiLevels (compare Makefile with build-tools/scripts/BuildEverything.mk), so ConfigureLocalWorkload fails; 32 sessions rediscovered make leeroy, which CI and copilot-setup-steps.yml already use via make jenkins. All references now use make prepare && make leeroy.

A new local-build skill records what sessions kept rediscovering and relaying to each other by hand:

  • Pass extra flags with MSBUILD_ARGS; overriding MSBUILD_FLAGS drops -p:Configuration.
  • dotnet-local.sh uses bin/Release whenever it exists, regardless of CONFIGURATION.
  • After one full build, rebuild only Xamarin.Android.Build.Tasks.csproj, which outputs directly into the local SDK.
  • Stalled builds with idle MSBuild nodes (10 sessions): retry with DOTNET_CLI_USE_MSBUILD_SERVER=0 MSBUILDDISABLENODEREUSE=1 ... MSBUILD_ARGS='-nr:false -m:1 -p:UseSharedCompilation=false'.
  • SourceLink Repository has no commit in fresh worktrees (21 sessions), which breaks -warnaserror baselines.
  • Rules for parallel sessions on one host: at most one or two full builds at a time, queue heavy work instead of inventing lease protocols, and never kill processes another session started.

Devices

62 sessions hand-rolled AVD, emulator, and ADB management. A new android-devices skill uses Google's android CLI, which ships in the repo-pinned cmdline-tools ($(CommandLineToolsFolder)), so it is available after make prepare. android emulator start --headless <avd> waits for a full boot and prints the serial, and android emulator stop <serial> leaves the ADB server running. CI's Emulator.csproj targets remain documented only for reproducing a CI lane, because ReleaseAndroidTarget runs adb kill-server and disconnects every session on the host. The skill also covers targeting (-p:Device=, ADB_TARGET), sharing, IncludeCategories, and the PublishAot Debug/CoreCLR trap.

Fewer follow-up iterations

The most common follow-ups on agent output were requests to simplify, to reuse an existing mechanism instead of building a new one, to drop files nobody asked for (such as a new .editorconfig or a test for a sync script), and to avoid redoing work already done in another session or PR. A new "Working Principles" section covers these cases: check for existing work first, reuse before inventing, keep it simple, ask before adding new artifacts, measure performance claims, and validate proportionally. The tests skill gains a "smallest sufficient validation" table by change area, and the code-review AI pitfalls now flag unrequested artifacts and unmeasured performance claims.

Tool failures

Local session logs explain the two highest tool failure rates:

  • 20 of 87 PR-creation calls failed, 18 with 422 Unprocessable Entity ... field: head, code: invalid because the branch had not been pushed yet. Every one succeeded after git push.
  • 132 of 160 web_fetch failures were 404s on guessed URLs: dotnet/runtime, dotnet/msbuild, and dotnet/dotnet sources at wrong tags or paths, dnceng feed indexes under guessed GUIDs, and invented learn.microsoft.com pages.

The pull-request skill says to push first, and the Working Principles now say to search the VMR at the Sha in eng/Version.Details.xml, to query NuGet.config feeds with dotnet package search, and to use microsoft_docs_search.

pull-request skill

PRs are squash-merged, so the PR description becomes the commit message. A new pull-request skill summarizes Documentation/workflow/commit-messages.md and recent practice: [Component] Summary titles, Context:/Fixes:/Changes: lines, why before what, verbatim evidence, and validation results. Instead of templates, it points to real commits as examples (a3b7c32, 39cc235, 99e88d8).

All new content was condensed following the skill-authoring guidance above: the three new skills went from ~2,400 to ~1,260 words with the same information.

Validation

This PR changes only documentation and agent instructions, so no SDK build or tests were run. The commands the docs prescribe were checked locally:

  • make -n leeroy CONFIGURATION=Release MSBUILD_ARGS='-nr:false -m:1': all three steps receive -p:Configuration=Release and the extra arguments; make -n jenkins includes BuildExtraApiLevels.
  • .../cmdline-tools/23.0/bin/android emulator start --headless medium_phone: booted as emulator-5554 in ~26s. android emulator stop emulator-5554 left the ADB server PID unchanged.
  • The $(CommandLineToolsFolder) path snippet resolves the CLI.
  • gh search code --repo dotnet/dotnet TaskFactoryUtilities and dotnet package search Microsoft.NET.Sdk.Android.Manifest-12.0.100-alpha.1 --exact-match --prerelease --source <dotnet12> both return the expected results.

The android CLI was verified on macOS only.

simonrozsival and others added 5 commits November 12, 2026 12:43
An analysis of ~230 recent Copilot sessions in this repository found that most wasted time came from the build and device environment and from over-engineered first attempts, not from the code changes themselves:

  * 32 sessions rediscovered that `make all` skips `BuildExtraApiLevels`, so `ConfigureLocalWorkload` fails; the instructions and `tests` skill prescribed `make all`, while CI and `copilot-setup-steps.yml` use `make jenkins` (prepare + leeroy).
  * Recurring local issues (stalled MSBuild task-host/nodes, SourceLink "Repository has no commit" in fresh worktrees, disk space) were rediscovered and relayed manually between sessions.
  * 62 sessions hand-rolled emulator/AVD/ADB management even though `build-tools/scripts/TestApks.targets` (`AcquireAndroidTarget`) already does this for CI.
  * Parallel sessions each ran full SDK builds and their own emulators, saturating the host and producing large amounts of ad-hoc lease/scheduling chatter.
  * Work was repeated across sessions ("Let's not redo work we've already done in other github sessions!"), and many correction turns asked to simplify, reuse an existing mechanism, or drop unrequested files.

Changes:

  * `copilot-instructions.md`: use `make prepare && make leeroy`; add a "Working Principles" section (check for existing work, reuse before inventing, keep changes simple, ask before adding new artifacts, measure perf claims, escalate validation deliberately); add host-sharing rules for parallel sessions; note the `PublishAot` Debug/CoreCLR pitfall.
  * New `local-build` skill: entry points, `MSBUILD_ARGS` usage, `dotnet-local.sh` Release preference, per-project inner loops (`Xamarin.Android.Build.Tasks.csproj` writes directly into the local SDK pack), known issues with fixes, and host-load rules.
  * New `android-devices` skill: reuse vs. create, starting emulators via `Emulator.csproj` like CI, its hazards (fixed port 5570, forced AVD re-creation, `ReleaseAndroidTarget` runs `adb kill-server`), targeting via `-p:Device=`/`ADB_TARGET`, device sharing, `IncludeCategories`, and crash diagnosis.
  * `tests` skill: fix build commands, add a "Smallest sufficient validation" table, document device targeting.
  * `code-review` AI pitfalls: flag unrequested artifacts and unmeasured performance claims.

Co-authored-by: Copilot App <[email protected]>
Context: Documentation/workflow/commit-messages.md

PRs are squash-merged, so the PR title and description become the commit message on `main`.  Agents had no skill for writing them, so descriptions drifted toward file lists and "This PR…" summaries instead of the repository's established `[Component] Summary` + `Context:`/`Fixes:` + narrative style.

Add a `pull-request` skill that summarizes the existing commit-message guide and the conventions visible in recent history: why before what, a symptom → cause → fix story with verbatim errors, topic-named sections for multi-part changes, measurements with their configuration, and the validation commands and results that `.github/PULL_REQUEST_TEMPLATE.md` asks for.  It also records where recent practice differs from the guide: paragraphs are not hard-wrapped, and Markdown tables and code blocks are used.

Reference the skill from `copilot-instructions.md`.

Co-authored-by: Copilot App <[email protected]>
The repo-pinned Android command-line tools (`$(CommandLineToolsFolder)` = `23.0`) ship Google's `android` CLI, so every machine that ran `make prepare` already has it at `~/android-toolchain/sdk/cmdline-tools/23.0/bin/android`.  It is a better fit for local sessions than the CI `AcquireAndroidTarget`/`ReleaseAndroidTarget` targets:

  * `android emulator start --headless <avd>` blocks until the device is fully booted and prints its serial; a local test booted `medium_phone` as `emulator-5554` in ~26s.
  * `android emulator stop <serial>` stops only that emulator; the adb server PID was unchanged afterwards.  `ReleaseAndroidTarget` runs `adb kill-server`, disconnecting every other session.
  * There is no fixed port (the CI targets always use 5570) and no forced AVD re-creation.

`android emulator create <profile>` cannot choose the API level, ABI, or AVD name, so the skill uses `avdmanager create avd` for specific images and concurrent AVDs, then starts them with the CLI.  The MSBuild targets remain documented only for reproducing a CI lane's exact emulator configuration.

The skill also asks sessions to remove AVDs they create; ~20 leftover per-session AVDs had accumulated in the shared `~/.android/avd`.

Co-authored-by: Copilot App <[email protected]>
Context: https://platform.claude.com/docs/en/agents-and-tools/agent-skills/best-practices

Every skill and instruction token competes with the session's working context once loaded.  Apply the skill-authoring guidance to the setup added in the previous commits, keeping the same information at about half the length (the new skills went from ~2,400 to ~1,260 words):

  * State only what an agent can't infer; drop explanatory prose.
  * Give one default with an escape hatch: the `android` CLI first, then `avdmanager` for specific images, then CI's `Emulator.csproj` targets only to match a CI lane exactly.
  * Use exact commands for fragile steps.  The `android` CLI path is now derived from `$(CommandLineToolsFolder)` in `Configuration.props` instead of a hard-coded `23.0`.  Source line-number citations, which go stale, are removed.
  * Turn the PR workflow into a short checklist, and point to real squash commits as examples (`a3b7c32f1b`, `39cc235cd3`, `99e88d8a378d`) instead of describing the style with templates.

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

Context: 66fba66

The session analysis flagged high failure rates for the PR-creation tool and `web_fetch`.  Local session logs from the last 30 days explain both.

### PR creation

20 of 87 `create_pull_request` calls failed; 18 failed with:

	GitHub API request failed (422 Unprocessable Entity): Validation Failed: resource: PullRequest, field: head, code: invalid

In 19 of 20 failures, the session had not pushed the branch yet; each then ran `git push` and the retry succeeded.  The cost is a wasted call and turn, not a lost PR.  The `pull-request` skill now says to push before creating the PR and quotes the error.

### `web_fetch`

160 of 1,417 `web_fetch` calls failed, 132 with HTTP 404 on guessed URLs:

  * Source files in `dotnet/runtime`, `dotnet/msbuild`, and `dotnet/dotnet` at guessed tags and paths (69 on raw.githubusercontent.com).  For example, `dotnet/msbuild/main/src/Tasks/TaskFactoryUtilities.cs` lives at `src/msbuild/src/Framework/Utilities/` in the VMR.
  * Package indexes on dnceng feeds under guessed feed GUIDs (20 on pkgs.dev.azure.com).
  * Guessed learn.microsoft.com URLs (19).

The working instructions now say to search the VMR at the `Sha` pinned in `eng/Version.Details.xml` (`gh search code`, `gh api .../contents?ref=`), to query feeds from `NuGet.config` with `dotnet package search`, and to use `microsoft_docs_search` for MS Learn.  The VMR search and the `dotnet12` feed query were both verified locally.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 12, 2026 12:12

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

The instructions use an incompatible hardcoded SDK path, an unescaped MSBuild category separator, and a rebuild command that can leave Release tests using a stale task assembly.

3 open issues
What changed in this PR

Updates .NET for Android’s Copilot guidance using lessons from recent sessions to reduce repeated build/device setup problems and unnecessary work. The changes affect documentation and agent instructions only.

Changes:

  • Standardizes local SDK builds on make prepare && make leeroy and adds build troubleshooting and device-management skills.
  • Adds PR-writing guidance and principles for reusing existing solutions, controlling scope, and supporting performance claims with measurements.
  • Introduces change-based validation guidance and additional review checks.
File Description
.github/​skills/​tests/​SKILL.md Updates build prerequisites, validation scope, and device targeting.
.github/​skills/​tests/​references/​test-catalog.md Corrects full-build setup commands.
.github/​skills/​pull-request/​SKILL.md Adds PR creation and commit-message guidance.
.github/​skills/​local-build/​SKILL.md Documents SDK builds, incremental rebuilds, troubleshooting, and shared-host practices.
.github/​skills/​code-review/​references/​ai-pitfalls.md Adds checks for unrequested artifacts and unmeasured performance claims.
.github/​skills/​android-devices/​SKILL.md Documents emulator management, targeting, sharing, and runtime diagnostics.
.github/​copilot-instructions.md Consolidates working principles and links the new skills.

Review effort: Balanced

Comment thread .github/skills/android-devices/SKILL.md Resolved
Comment thread .github/skills/android-devices/SKILL.md Resolved
Comment thread .github/skills/local-build/SKILL.md Resolved
…tion

Context: #13521

Address review feedback on the new skills:

  * `android-devices` built the cmdline-tools path from `~/android-toolchain/sdk` and a text-parsed `$(CommandLineToolsFolder)`.  That is wrong whenever the SDK is overridden: `copilot-setup-steps.yml` provisions `/mnt/android-toolchain`, and `ANDROID_SDK_ROOT` redirects `$(AndroidSdkDirectory)` (`Configuration.props`).  Resolve `$(CommandLineToolsBinPath)` via `dotnet msbuild Emulator.csproj -getProperty:CommandLineToolsBinPath` instead; on a machine with `ANDROID_SDK_ROOT` set, it returned `~/Library/Android/sdk/cmdline-tools/23.0/bin`, and its `android` CLI ran.
  * `-p:IncludeCategories=A,B` fails, because MSBuild treats the comma as a property separator.  `-p:IncludeCategories=A%2CB` evaluates to `A,B`.
  * The `Xamarin.Android.Build.Tasks.csproj` rebuild omitted `-c`, so it defaulted to Debug (`Directory.Build.props`) even when `dotnet-local.sh` uses the Release SDK, leaving Release tests on a stale task assembly.  Pass the matching configuration.

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

Copy link
Copy Markdown
Member

/review

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13521

@github-actions github-actions Bot 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 Changes

Findings: 0 errors, 1 warning, 1 suggestion, both posted inline. The validation table's blanket .github/ exemption conflicts with its CI-YAML requirement and should be narrowed. The other comment is a small shell-path robustness improvement.

The make leeroy guidance matches BuildEverything.mk, the Release preference matches dotnet-local.sh, and the NativeAOT Debug caveat matches the runtime-selection condition. The previously reported SDK-path lookup, category escaping, and rebuild-configuration issues are addressed in this revision. Separating build, device, and PR-writing guidance into focused skills keeps the main instructions easier to use.

CI: All 40 reported GitHub checks succeeded, including the aggregate dotnet-android check for Azure build 1677627. Independent Azure build-result verification was blocked because az devops invoke requires authentication in this environment.

Local verification limits: dotnet msbuild src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Emulator.csproj -getProperty:CommandLineToolsBinPath failed with MSB4242 during NuGet SDK-resolver initialization; make -n leeroy CONFIGURATION=Release MSBUILD_ARGS='-nr:false -m:1' was denied by the execution environment. Neither is being attributed to this PR. No SDK compilation or device tests were run for these documentation-only changes.

Generated by Android PR Reviewer for #13521 · copilot · gpt61 · 37.8 AIC · ⌖ 7.92 AIC · ⊞ 19.5K
Comment /review to run again

Comment thread .github/skills/tests/SKILL.md Resolved
Comment thread .github/skills/android-devices/SKILL.md Resolved
Context: #13521 (review)

Address two review comments on the new skills:

  * The `tests` skill exempted all of `.github/` from validation, but `.github/workflows/` holds executable workflows and local actions such as `copilot-setup-steps.yml` and `log-disk-space`, so a workflow change matched both the `None` row and the CI row.  The exemption now covers only docs and Markdown instructions/skills, and workflow or script changes require running the affected step or command locally.
  * The `android-devices` commands used unquoted `$B/android` and `$B/avdmanager`, which word-split when the SDK path contains spaces.  Every command derived from `B`, and the `B=$(...)` assignment, is now quoted.  With `B` pointing at a directory named `sdk with space`, unquoted `$B/android emulator list` failed with `No such file or directory`, while the quoted form listed AVDs and `"$B/avdmanager" list device -c` listed `pixel_9_pro`.

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

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13521

@github-actions github-actions Bot 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 Changes

0 errors · 1 warning · 0 suggestions. Reviewed all seven changed files at 19b7d0c3eca0ca0a678ce8feb57893acd5f955ab against the surrounding build and device infrastructure. One inline warning identifies an incomplete direct-SDK invocation workaround: selecting the executable alone does not configure discovery of the locally built Android workload.

The make leeroy correction matches BuildEverything.mk, the Debug/NativeAOT caveat matches runtime selection, and the explicit device-targeting and shared-host guidance are useful improvements. No product code changes are included, so no SDK build or tests were run for this review.

CI: All 40 GitHub checks report success, including the aggregate dotnet-android check for Azure build 1679209. The independent Azure build-status query required authentication and could not run, so the Azure result/timeline was not independently verified.

Generated by Android PR Reviewer for #13521 · copilot · gpt61 · 43.7 AIC · ⌖ 8.21 AIC · ⊞ 19.5K
Comment /review to run again

Comment thread .github/skills/local-build/SKILL.md Resolved
Context: #13521 (comment)

The `local-build` skill suggested calling `bin/<cfg>/dotnet/dotnet` directly to avoid `dotnet-local.sh` preferring Release.  That selects the executable but not the workload: `dotnet-local.sh` also sets `DOTNETSDK_WORKLOAD_MANIFEST_ROOTS` to `bin/<cfg>/lib/sdk-manifests` and `DOTNETSDK_WORKLOAD_PACK_ROOTS` to `bin/<cfg>/lib`, which is where `ConfigureLocalWorkload` installs the locally built workload.  In a local Debug build, the `12.0.100-alpha.1` `microsoft.net.sdk.android` manifest and 25 Android packs exist only under `bin/Debug/lib`, while `bin/Debug/dotnet` contains an older `11.0.100-rc.1` manifest and one Android pack.

Document setting both variables when invoking the binary directly.

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

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13521

@github-actions github-actions Bot 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 Changes

0 errors · 1 warning · 1 suggestion, posted inline. The remaining warning concerns incremental native/bindings rebuilds defaulting to Debug while subsequent tests can still use the existing Release SDK. The suggestion fixes a reference to a nonexistent skill.

The make leeroy entry point matches the build implementation, the workload-root workaround matches dotnet-local.sh, and the earlier review findings are addressed. The device-targeting and proportional-validation guidance are useful improvements.

CI: All 40 reported GitHub checks are successful, including the aggregate dotnet-android check for Azure build 1679383. An independent Azure build-result query was blocked by the CLI's authentication requirement; I did not bypass it.

Reviewed all seven full committed files and relevant build/device implementations. No SDK build or device tests were needed for this documentation-only change. The attempted make -n command checks were denied by execution permissions, so the configuration finding is based on Makefile and msbuild.mk, not an executed dry run.

Generated by Android PR Reviewer for #13521 · copilot · gpt61 · 38.1 AIC · ⌖ 4.67 AIC · ⊞ 19.5K
Comment /review to run again

Comment thread .github/skills/local-build/SKILL.md Resolved
Comment thread .github/skills/local-build/SKILL.md Resolved
Context: #13521 (review)

Address two review comments on the `local-build` skill:

  * The incremental `make leeroy` row and the stalled-build retry omitted `CONFIGURATION`, which the `Makefile` defaults to Debug.  After a Release build, they rebuilt Debug while `dotnet-local.sh` kept using the stale Release SDK.  Both now pass `CONFIGURATION=<cfg>`; `make -n leeroy CONFIGURATION=Release` forwards `-p:Configuration=Release` to all three steps.
  * The binlog hint pointed to an `msbuild` skill that does not exist in `.github/skills/`.  It now shows a `binlogtool search` command and links to "Analysis commands" in `.github/skills/ci-status/references/binlog-analysis.md`.

Co-authored-by: Copilot App <[email protected]>
@jonathanpeppers
jonathanpeppers merged commit aa840db into main Nov 13, 2026
40 checks passed
@jonathanpeppers
jonathanpeppers deleted the simonrozsival-copilot-setup-session-analysis branch November 13, 2026 18:57
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