Skip to content

Bound Windows CLI output draining - #76576

Merged
pelikhan merged 4 commits into
mainfrom
copilot/aw-top-10-04-bound-windows-cli-output-draining
Nov 10, 2026
Merged

pelikhan merged 4 commits into
mainfrom
copilot/aw-top-10-04-bound-windows-cli-output-draining

Conversation

Copilot AI commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

After the CLI parent exits, a descendant can keep redirected stdout or stderr open and block the integration helper indefinitely. Bound post-exit draining and cleanup while preserving actionable diagnostics for drain and process timeouts.

  • Drain handling: Read both streams asynchronously, capture partial output, and cap post-exit draining with a configurable timeout.
  • Diagnostics: On drain timeout, report the command, elapsed time, exit code, and captured output.
  • Regression coverage: Exercise ordinary exits, process timeouts, and a parent that exits while a descendant retains redirected pipes.
OUTPUT DRAIN TIMEOUT: 'pwsh ...' exited with code 0; stdout/stderr drain exceeded 500ms after process exit (elapsed 540ms)
Captured output:
parent-drain-marker
...

Copilot AI linked an issue Nov 10, 2026 that may be closed by this pull request
2 tasks
Copilot AI changed the title [WIP] Fix unbounded output drain in Windows CLI integration helper Bound Windows CLI output draining Nov 10, 2026
Copilot AI requested a review from gh-aw-bot November 10, 2026 18:53
@pelikhan
pelikhan marked this pull request as ready for review November 10, 2026 18:58
Copilot AI adaptive review requested due to automatic review settings November 10, 2026 18:58
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

Matt Pocock Skills Reviewer

Outcome: reported_action

The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Matt Pocock Skills Reviewer · routed: haiku55 xhigh · ~8 AIC · ⌖ ~2 AIC · ⊞ 6.6K · ◷

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

PR Specification Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from PR Specification Reviewer · gpt56 · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 1.6K · ◷

Generated by PR Specification Reviewer for #76576

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Ponytail Reviewer · routed: gpt61 medium · ~4 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 181 · ◷

Generated by Ponytail Reviewer for #76576

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

Design Decision Gate 🏗️

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Design Decision Gate 🏗️ · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 8.5K · ◷

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 7.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@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.

Found two blocking correctness issues: the polling drain loop artificially limits output throughput and can time out valid large output, and the new timeout regression test is timing-dependent on cold pwsh startup. Inline comments provide the requested fixes. Static review only; tests were not run per review instructions.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again

Comment thread scripts/windows-cli-matrix.test.ps1 Outdated
$watch = [System.Diagnostics.Stopwatch]::StartNew()
$processTimeoutRejected = $false
try {
Invoke-CliProcess -FilePath $pwsh -ArgumentList @("-NoProfile", "-Command", "Write-Output 'process-timeout-marker'; Start-Sleep -Seconds 30") -TimeoutMs 500 | Out-Null

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.

This regression depends on pwsh starting and emitting process-timeout-marker within the 500 ms process timeout. On a loaded Windows runner, the process can be killed before the marker is captured, making the test flaky independently of the timeout behavior. Synchronize on a readiness signal before applying the timeout, or avoid asserting output that is not guaranteed before 500 ms.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d0ad028: increased the startup-inclusive process timeout to 10 seconds and cleanup budget to 15 seconds. The marker must now appear immediately after Captured output:, so echoed arguments cannot satisfy the assertion. PowerShell regressions pass locally.

if ($processExited -and $stdoutDone -and $stderrDone) { break }
if ($processExited -and $drainWatch.ElapsedMilliseconds -ge $PostExitDrainTimeoutMs) { break }
if ($processTimedOut -and -not $processExited -and $processCleanupWatch.ElapsedMilliseconds -ge 1000) { break }
Start-Sleep -Milliseconds 10

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.

This polling loop only consumes one 4096-character chunk per stream before sleeping 10 ms. That caps draining at roughly 400 KB/s, so the 2-second default can falsely report OUTPUT DRAIN TIMEOUT for legitimate large CLI output and also back-pressure live producers. Please continue consuming available data without the fixed sleep (or use dedicated reader tasks) so the timeout bounds descendants rather than normal output volume.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d0ad028: drain completed reads in bounded batches and skip sleeping while either stream has ready data, preserving fairness and timeout checks. Added an 8 MiB-per-stream regression; it passes with the fix and rejects the original throttled loop.

@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.

Skills-Based Review 🧠

Applied /diagnosing-bugs, /tdd, and /codebase-design. Requesting changes because the new drain loop makes high-output processes about 15x slower.

📋 Key Themes & Highlights

Key Themes

  • Throughput regression: each stream reads one 4 KB chunk per 10 ms tick. On 2 MB of output the helper takes 5.2 s, versus 0.36 s for the pre-PR helper. Draining completed reads in a while loop brings it to about 0.56 s.
  • Timing-sensitive assertion: the 500 ms process-timeout marker check assumes pwsh prints before the kill. This can flake on cold runners.
  • Coverage gaps: no checks for stderr-only drain timeout, nonzero exit combined with drain timeout, or -AllowFailure with the new drain code.
  • Structure: the helper is about 150 lines inside a YAML run: block and is extracted by regex in the test script.

Positive Highlights

  • ✅ The post-exit drain is bounded, and descendant cleanup runs in finally.
  • ✅ Partial output is kept on process-timeout and drain-timeout paths, with explicit markers.
  • ✅ Ordinary-exit, process-timeout, and drain-timeout regression scenarios pass on Linux pwsh 7.6.9. The Windows-only ConPTY section was not run here.

Correction

My inline comment on scripts/windows-cli-matrix.test.ps1 line 112 said the drain-timeout descendant holds only stdout. It inherits both stdout and stderr. The stderr-only gap in the coverage comment still stands.

@copilot please address the review comments above.

Comments that could not be inline-anchored

.github/workflows/windows-cli-integration.yml:199

**[/diagnosing-bugs]** The drain loop reads at most one 4 KB chunk per stream per tick, then sleeps 10 ms. Throughput is capped near 400 KB/s. On a 2 MB child output, this takes 5.2 s versus 0.36 s on the pre-PR helper (about 15x slower). <details> <summary>💡 Suggested fix</summary> Drain all completed reads per tick. Change the two guards at lines 162 and 171 from `if` to `while`, so each completed read is re-issued and consumed until it is not yet complete or reports EOF. With that change, ...

scripts/windows-cli-matrix.test.ps1:84

**[/tdd]** This assertion depends on `pwsh` printing `process-timeout-marker` within the 500 ms budget. On a cold Windows runner, process startup can take seconds, so the marker may never appear and the test becomes flaky. <details> <summary>💡 Suggested fix</summary> Keep the timeout test deterministic. Either start the child, wait for a sentinel file or a stdout line before the kill (for example, have the child write the marker to a file first), or use a longer budget and assert only on the ...

scripts/windows-cli-matrix.test.ps1:112

**[/tdd]** The drain-timeout case covers only a stdout-holding descendant. Other new branches have no regression check: stderr-only drain timeout, nonzero exit combined with a drain timeout, and `-AllowFailure` with the new drain code. <details> <summary>💡 Suggested tests</summary> Add focused cases that expect the `OUTPUT DRAIN TIMEOUT` error and the `<stderr drain timed out after process exit>` marker when only stderr is held open. Add one nonzero-exit case with a held pipe to confirm the e...

.github/workflows/windows-cli-integration.yml:83

**[/codebase-design]** `Invoke-CliProcess` has grown to about 150 lines of process-management logic inside an inline YAML `run:` block. The test script then extracts it by regex and AST parsing, so it is hard to navigate, and it cannot be unit-tested directly. <details> <summary>💡 Suggested refactor</summary> Move the helper into a standalone `.ps1` module, for example `scripts/windows-cli-process.psm1`, and `Import-Module` it from both the workflow and the regression script. The workflow and...

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~8 AIC · ⌖ ~2 AIC · ⊞ 6.6K
Comment /matt to run again

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

Timeout cleanup can leave pipe handles and pending I/O open indefinitely, while the regression test can pass without captured stdout and remains sensitive to slow PowerShell startup.

2 open issues
What changed in this PR

Introduces a post-exit drain deadline in gh-aw’s Windows CLI integration helper, targeting hangs caused by descendants that keep redirected output pipes open.

Changes:

  • Captures stdout and stderr incrementally with a configurable drain timeout.
  • Reports command details, elapsed time, exit status, and partial output on drain timeout.
  • Adds regressions for ordinary exits, process timeouts, and descendant-held pipes.
File Description
scripts/​windows-cli-matrix.test.ps1 Extracts the workflow helper and adds subprocess timeout regressions.
.github/​workflows/​windows-cli-integration.yml Adds bounded output draining, partial capture, and timeout diagnostics.

Review effort: Max (auto)

$stopwatch.Stop()
throw "TIMEOUT: '$FilePath $displayArgs' exceeded ${TimeoutMs}ms (elapsed $($stopwatch.ElapsedMilliseconds)ms)`nCaptured output:`n$stdout`n$stderr"
} finally {
if ($null -ne $proc) { $proc.Dispose() }
Comment thread scripts/windows-cli-matrix.test.ps1 Outdated
Comment on lines +84 to +91
Invoke-CliProcess -FilePath $pwsh -ArgumentList @("-NoProfile", "-Command", "Write-Output 'process-timeout-marker'; Start-Sleep -Seconds 30") -TimeoutMs 500 | Out-Null
} catch {
$message = $_.Exception.ToString()
if ($message -notmatch "TIMEOUT:.*$([regex]::Escape($pwsh))" -or $message -notmatch "elapsed \d+ms" -or $message -notmatch "process-timeout-marker") { throw }
$processTimeoutRejected = $true
}
if (-not $processTimeoutRejected) { throw "CLI process timeout was swallowed" }
if ($watch.ElapsedMilliseconds -gt 5000) { throw "CLI process timeout cleanup exceeded its budget" }
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (scripts/windows-cli-matrix.test.ps1:84): address unresolved feedback - Review comment
  3. Review (.github/workflows/windows-cli-integration.yml:199): address unresolved feedback - Review comment

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "9ff367d1d3280dad2c9340c946e67cc0323cf894",
  "kind": "requested",
  "schema_version": "1",
  "state": "0035acbeed65e6a7a76bd163e9b8e7db5e2fbf32c3de9a20cb02469fee68fa4b",
  "work": [
    "91e5a67bd302526fc7b163d9ab4bd13e67b283ea06734adf214edbaf769243c3",
    "eb192dfe551b2efd5ad142332cf1482ef6329d138039ce5b1dfb699fe549dfcc"
  ],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 xhigh · ~3 AIC · ⌖ ~2 AIC · ⊞ 6.9K · ◷
Comment /souschef to run again

Copilot AI commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:...

Merged latest main with make merge-main in 20388d8 and addressed both linked comments in d0ad028. Build, all 365 workflow compilations, final validation, PowerShell regressions, actionlint, and secret scanning passed. CodeQL timed out; Windows-native execution remains unverified locally. No CI was dispatched and the PR was not merged.

@pelikhan
pelikhan merged commit 96e27b5 into main Nov 10, 2026
60 checks passed
@pelikhan
pelikhan deleted the copilot/aw-top-10-04-bound-windows-cli-output-draining branch November 10, 2026 21:45
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.3

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.

[AW Top 10] 04 Bound Windows CLI output draining

4 participants