Skip to content

x.copilot.instructions.md file, with an & gets HTML encoded to &amp, truncating the instructions. #1085

@ChrisGuzak

Description

@ChrisGuzak

Describe the bug

copilot diagnosed its own bug!

❯ help me figure out why you did not find that automatically, did I
misspell the directory name?

✓ Grep ".github/instructions|instructions.md"
...
✓ List directory ~\source\repos\OSClient.github\instructions
└ 1 file found

● I see the issue now. Looking at my system prompt, I actually was
given the content from osclient-build.instructions.md - it's embedded
at the bottom of my context (starting with the YAML frontmatter
description: "Build workflow for OSClient repository..."). However,
it appears truncated - it cuts off mid-sentence at:

 & $msbuild

So the instructions file was automatically loaded into my context,
but:

 - It got truncated, missing the actual build command parameters
 - Because it was incomplete, I relied on the AGENTS.md file instead
which had more complete instructions

The directory name .github/instructions is correct - no misspelling.
The issue is the automatic injection of that file was truncated
before I could see the full build command.

❯ is there something in that file that caused the trucation?

✓ Read ~\source\repos\OSClient.github\instructions\osclient-build.instr
uctions.md
└ 141 lines read

● Yes! I see the issue. Looking at the injected content in my system
prompt vs the actual file:

In my system prompt, the NuGet restore command shows:

 & {REPO_ROOT}\Src\DeveloperProductivity\UESNugetRestore.ps1

The actual file has:

 & {REPO_ROOT}\Src\DeveloperProductivity\UESNugetRestore.ps1

The & character was HTML-encoded to & during injection. The
truncation happened at line 62 where there's:

 & $msbuild

In my system prompt, I see it just cuts off after & $msbuild without
the rest of the command parameters. The file uses & (PowerShell call
operator) throughout, and something in the injection pipeline is
encoding these as & which may be causing parsing issues or
truncation.

The culprit is likely the & characters - either the HTML encoding is
causing issues, or there's a length limit being hit around that point
in the injection.

❯ what do you suggest? can I update the content to avoid this, using
"." instead? is this a bug in your injection code?

● This is a bug in the injection/rendering pipeline - the & character
is being HTML-encoded to &, and something is causing truncation
around that point.

You can't use . as a replacement - they have different semantics in
PowerShell:

 - & (call operator) - executes an external command or script in a

child scope
- . (dot-sourcing) - runs a script in the current scope, and
doesn't work with executables like MSBuild.exe

Workarounds you could try:

 - Use Start-Process or Invoke-Command:  Start-Process -FilePath

$msbuild -ArgumentList "..." -NoNewWindow -Wait
- Spell out the ampersand: # Use Invoke-Expression (less ideal but
avoids &)
Invoke-Expression "$msbuild /t:Build ..."
- Just use the variable directly (works when no spaces in path):
$msbuild /t:Build ...

However, this is really a bug that should be fixed in the injection
code - the HTML encoding of & to & shouldn't happen for markdown code
blocks, and it definitely shouldn't cause truncation. I'd recommend
filing this as a bug against the Copilot CLI/instructions injection
feature.

Would you like me to help you rewrite the instructions file using one
of these workarounds for now?

Affected version

0.0.392 Commit: cefb35e

Steps to reproduce the behavior

create .github\instructions\foo.instructions.md with contents like this

$vsPath = vswhere.exe -latest -property installationPath
$msbuild = Join-Path $vsPath "MSBuild\Current\Bin\MSBuild.exe"

& $msbuild <path-to-vcxproj> /t:Build /p:Configuration=Debug /p:Platform=x64 /p:UES_SolutionDir=<solution-directory> /v:minimal

the line with & $msbuild ... is the problem as described above.

Expected behavior

expected: these instructions to apply

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions