Skip to content

Keep output that arrived before a stream timeout, per stream - #66

Merged
HalRiveria-Bot merged 2 commits into
mainfrom
fix/keep-partial-output
Nov 17, 2026
Merged

HalRiveria-Bot merged 2 commits into
mainfrom
fix/keep-partial-output

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

When a program a program started (a compiler server, say) kept stdout or stderr open past -StreamTimeoutMs, StreamTimedOut was set as designed, but that stream came back $null: ReadToEndAsync has nothing to give until the stream ends. A build step whose helper outlived it lost its whole log, not just the end of it.

What changed

  • The output is read in chunks by PkStreamReadTask, a Task<string> whose text so far can be taken at any time, under a lock against the reader still appending. Used on both start paths (created in the Job Object, and the Process.Start fallback).
  • On a timeout, Complete-PkProcess gives each stream what had arrived: the held one cut short, the other whole. StreamTimedOut still means either stream timed out.
  • The reader's decoder keeps a character split across two reads for the next one, so the cut never breaks a character.
  • The program's end (exit code) and the output's end (streams closed, or the timeout) are kept apart in Complete-PkProcess.
  • The held stream's read carries on in the background until the leftover program lets go of the pipe. That program is in the kit's Job Object, so it ends when PowerShell exits at the latest. This was already the case before (the old read task stayed alive the same way); the README and help now say so.
  • StdoutTask and StderrTask are still Task<string> (a subclass), so code reading .Result works as before. A finished reader drops its buffer, so the text isn't held twice.
  • The start result's four keys and their two copies (the dispatcher's and the batch's default starters) now name each other.

One side effect: on PowerShell 7 the reads now block a thread-pool thread per stream, as they always did on 5.1. The kit already raises the pool's minimum for that.

The compiled types changed again (types version 7), so start a new PowerShell window after updating.

Testing

  • New harness section AX, on both start paths, using a small compiled program that writes "out" and "err" and leaves a copy of itself holding exactly one of the two pipes for 3 s (started with a handle list, since start /b and even .NET's Process.Start hand a child both):
    • With stdout held, and with stderr held, past a 1 s stream timeout, both streams keep their text.
    • The held read is still going when the result is handed over, and ends once the copy lets go.
    • Output cut off in the middle of a UTF-8 character keeps the whole characters before it.
    • A character written in two parts, 300 ms apart, comes through whole.
  • The three keep-the-text checks failed on the old code, on both paths (the held stream came back empty), and pass now.
  • Full harness passes in fresh processes on Windows PowerShell 5.1 and PowerShell 7 (545 assertions each).

🤖 Generated with Claude Code

HalRiveria and others added 2 commits November 17, 2026 18:27
When a program a program started held stdout or stderr open past
-StreamTimeoutMs, that stream came back $null: ReadToEndAsync has nothing
to give until the stream ends, so a build step whose helper outlived it
lost its whole log. The output is now read in chunks (PkStreamReadTask, a
Task<string> whose text so far can be taken at any time, under a lock),
on both start paths. On a timeout each stream comes back with what had
arrived: the held one cut short, the other whole. The reader's decoder
keeps a character split across reads for the next one, so the cut never
breaks a character. The read carries on until the holder lets go of the
pipe, at the latest when PowerShell exits (the holder is in the Job
Object). StdoutTask and StderrTask are still Task<string>.

The start result's four keys and their two copies (the dispatcher's and
the batch's starters) now name each other.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria-Bot
HalRiveria-Bot merged commit 016dfc6 into main Nov 17, 2026
2 checks passed
@HalRiveria-Bot
HalRiveria-Bot deleted the fix/keep-partial-output branch November 17, 2026 23:39
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.

2 participants