See Ash Code logo See Ash Code

The command finished. My shell runner kept waiting.

Ashlynn Antrobus
• • 3 min read

The command had finished, but agentsh, my AI-assisted shell, was still waiting for it. Pressing Ctrl+C got me back to the REPL.

The trigger was output without a trailing newline. clear can emit terminal escape sequences and stop there. My wrapper printed its completion marker immediately afterwards, putting the marker in the middle of the same line.

The July 18 fix removed the assumption that a completion marker always begins a line.

A dragon uses a magnifying glass to find a red flag among a row of tiles.

Illustration: finding a marker beyond the beginning of a line.

A newline was doing more work than I intended

Here’s a reduced version of the byte sequence, using a teaching marker:

b"\x1b[H\x1b[2JDEMO:nonce:0:/tmp\n"

The first bytes are command output. The rest is the wrapper’s marker, status and directory. startswith("DEMO:nonce:") fails because the line starts with an escape sequence.

In a persistent backend the pipe remains open for future commands. Missing this record leaves the reader waiting for another line rather than seeing EOF and returning.

I replayed the bytes through the archived readers

For a fresh comparison, I fed that fixture into the stream reader immediately before and after the fix. The test stream ends at EOF, making the old behavior observable without leaving a process hung.

ReaderReturned command outputReturned completion record
Before the fixEscape sequences plus the marker textEmpty
After the fixEscape sequences onlyDEMO:nonce:0:/tmp

The repaired reader searches within the line and splits it at the marker. It keeps the preceding bytes as output, subject to the existing output cap. It also looks for the marker while discarding excess output; truncation mustn’t prevent recognizing completion.

Finding a marker isn’t the whole protocol

I also tried a wrong nonce, a malformed status and an incomplete record against the repaired reader:

DEMO:other:0:/tmp       -> ordinary output
DEMO:nonce:oops:/tmp   -> returned as a candidate record
DEMO:nonce:            -> returned as a candidate at EOF

The reader recognizes the expected marker prefix. The backend parser separately checks fields and requires an integer status. The malformed candidate is therefore not a successful completion; in the persistent Bash backend, a failed parse triggers its recovery path.

That boundary matters because the reader returns as soon as it sees the matching prefix, even if a valid record follows later. Substring search fixes this particular hang. It doesn’t by itself guarantee recovery from arbitrary malformed or deliberately forged output. A per-call random marker makes accidental collisions less likely, but a completion protocol still needs parsing, bounded reads and a defined failure path.

I had already seen a marker pushed away from the start of a line by PowerShell’s leading control bytes. Here it took nothing more than a missing newline.

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.