See Ash Code logo See Ash Code

PowerShell added a parser error and some invisible bytes

Ashlynn Antrobus
• • 2 min read

PowerShell gave my shell runner two reasons to wait for a completion marker that it couldn’t recognize. One stopped the marker statement from parsing. The other put bytes in front of it.

Both were in the July 11 fix. Fixing either one alone left the other failure in place.

A PowerShell 7.5 session displays version information and runs a small function.

A separate PowerShell session, not the recorded failure: PowerShell 7.5 by Refresh100, MIT license; unmodified.

The wrapper has to be valid PowerShell

After a command runs, the backend prints a marker containing its exit code and working directory. Here’s a reduced example of the original interpolation:

$__ec = 0
"DEMO:$__ec:/tmp"

The colon immediately after $__ec isn’t harmless punctuation to the parser. PowerShell has scoped variable syntax, such as $env:PATH, and the bare variable followed by a colon creates an invalid reference here.

Braces delimit the variable name:

$__ec = 0
"DEMO:${__ec}:/tmp"

In a fresh reduced check with pwsh -NoProfile -NonInteractive -Command -, the first script produced a ParserError and no stdout. The second printed DEMO:0:/tmp followed by a newline. Interestingly, both invocations returned process status zero in that check. Looking only at the process status would have hidden the missing protocol record.

The marker can be present and still fail the reader

The other bug was specific to the recorded piped-stdin invocation. PowerShell emitted DECCKM terminal-control sequences before output. The historical regression fixtures represent the bytes like this:

b"\x1b[?1h\x1b[?1lMARKER:0:/tmp\n"

A reader checking whether the line starts with MARKER: sees an escape byte instead. To a person looking at the rendered output, the line can appear fine.

My fresh reduced parser check didn’t emit those prefixes, so that check doesn’t establish that every PowerShell version and environment does. The archived failure and its byte fixtures are the evidence for this part of the repair.

Noise removal has to happen before recognition

The stream reader already had an output transform, but that ran on text it was keeping. It couldn’t fix the earlier decision about whether a line was the completion marker.

The repair added a strip_noise hook before marker recognition and before retaining output. PowerShell supplies a narrowly scoped expression matching the observed leading sequences:

r"^(?:\x1b\[\?1[hl])+"

Other backends leave the hook unset. A regression fixture also checks that a real leading color code survives after the control noise is removed. A broad escape-sequence scrubber would have changed legitimate command output.

PowerShell could keep the persistent pipe once the wrapper parsed and the reader could recognize the marker. The same arrangement hadn’t worked for Fish.

AA

Written by Ashlynn Antrobus

Software developer, author, and builder. Sharing technical lessons learned from building tools like Ebook2Text, IndexedDict, and rag-mcp, and navigating life as a programmer with dyslexia.