Skip to content

fix(windows): drain owned-process output without the 25ms idle delay - #2784

Closed
sx4im wants to merge 16 commits into
morluto:mainfrom
sx4im:fix/2722-windows-output-drain
Closed

sx4im wants to merge 16 commits into
morluto:mainfrom
sx4im:fix/2722-windows-output-drain

Conversation

@sx4im

@sx4im sx4im commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

On Windows, inspect-wasm-artifact fails with provider_timeout for modules whose WAT output is larger than about 7.9 MB, even though the child process itself finishes in about a second. #2722 measured capture at ~262 KB/s through the Windows owned-process path.

Root cause: WindowsOwnedProcess re-polls the native process_poll on a fixed 25ms timer, and each poll pulls a single chunk from the pipe. That caps capture at roughly one chunk per poll interval no matter how much data is waiting, so the 30s deadline always fires before large outputs finish draining.

Changed src/windows/WindowsOwnedProcess.ts: #schedule now takes a delay, and #poll passes 0 when the last poll returned stdout or stderr data, 25 when the child was idle. Capture now drains at pipe speed while the child produces output and still backs off when there is nothing to read. The 25ms default is unchanged for the launch and cleanup paths.

Verified with a new test in src/windows/WindowsOwnedProcess.test.ts that replays 10 full 8 KiB stdout polls plus a settle poll against a mock native authority under fake timers: on the old code only 4 polls complete in 100ms of simulated time (the test fails); with the fix all 11 complete. Full src/windows suite: 30/30 pass. tsc --noEmit clean, oxlint 0 errors (1 pre-existing warning).

Caveat: I can't run the Windows native side here, so this is verified at the TS polling layer against the mocked authority, which is where the throttle lived. The native readOutput already returns up to 64 KiB per call; it just wasn't being called often enough.

Fixes #2722

WindowsOwnedProcess polled the native process_poll on a fixed 25ms
cadence, so output capture topped out around one pipe chunk per poll
(~262 KB/s measured), tripping provider_timeout on large WAT output.
When a poll returns data the next poll is now scheduled immediately;
the 25ms delay only applies when the child is idle.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T18:34:12.849335Z fb2b8a9 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] No separate new blocking finding was established; the existing paused-output cleanup thread still needs attention.

Summary

Windows output polls now run immediately after receiving data and keep the 25ms delay when idle.

  • Windows process output drains immediately while data keeps arriving.
  • Process snapshots flag output lost from a blocked stream.

Whether another PR supersedes this one could not be checked because GitHub access was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Poll owned process] --> B[Write stdout and stderr]
  B --> C{Reader blocked?}
  C -->|Yes| D[Wait for drain or close]
  D --> A
  C -->|No| E{Job exited and pipes ended?}
  E -->|Yes| F[Release native handle]
  E -->|No| G{Received output?}
  G -->|Yes| H[Schedule immediately]
  G -->|No| I[Schedule after 25ms]
  H --> A
  I --> A
Loading

Reviews (11) · Last reviewed commit: "Merge branch 'main' into fix/2722-window..." · Reviewed by Greptile

Comment thread src/windows/WindowsOwnedProcess.test.ts Resolved
Greptile review noted the drain test only exercised stdout-with-data
polls, leaving the idle 25ms backoff and stderr-only fast drain
unprotected. Add a timing test for each side of the scheduling rule:
an idle poll must not be repolled before the 25ms delay elapses, and
a stderr-only poll must schedule its successor immediately.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0785cfd48a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/windows/WindowsOwnedProcess.ts Resolved
@morluto morluto added bug Something isn't working performance Performance regressions, scaling limits, and bounded-resource work area: runtime Process capture and runtime observation P2: medium Medium priority issue labels Oct 13, 2026
@sx4im

sx4im commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Heads up @morluto — commit 0785cfd (kaoru0822-kitauji's fix for #2720, pushed onto this branch with you as committer) landed here by mistake, so I've reset the branch back to bdd5f69, which keeps only this PR's changes. Nothing else was touched.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Comment thread src/windows/WindowsOwnedProcess.test.ts Resolved
Comment thread src/windows/WindowsOwnedProcess.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 34421f75a2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/windows/WindowsOwnedProcess.ts Resolved
Comment thread src/windows/WindowsOwnedProcess.ts Resolved
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Source fixes and publication evidence for the review findings below. Tests and executable checks were skipped at the maintainer's request. Findings that still require a decision or execution evidence remain open.

review thread

The live contributor's 25ms backoff still polled indefinitely when write() returned false, so it merely slowed unbounded buffering. WindowsOwnedProcess now owns blocked-stream state and refuses further native polls while either stream is backpressured. A stream's drain event clears its state, and polling resumes only when both consumers accept output. The old cadence assertion is replaced by an actual paused stdout/stderr fixture that remains at one native read across a long interval, keeps polling stopped after only one consumer drains, then resumes after both drain. Cleanup retains the existing Job Object when output cannot settle; ownership is not discarded.

Published at 34421f75a2b4ce7021186a846c5a855c3c2d36e7. Validation was producer/consumer source inspection, targeted formatting with two threads and Git diff review only. Tests, compilation, builds, lint, typechecking, provider execution and CI reruns were skipped at the user's explicit request. Regression sources have not been executed and no real-provider proof or performance measurement is claimed. No directly related source cleanup remains from this finding.

morluto and others added 4 commits October 14, 2026 01:03
* fix(comparison): preserve incomplete function call evidence

Keep missing, unknown, partial and unresolved call relationships unknown in function comparisons and reconstruction claims. Aggregate IDA caller and callee coverage without overwriting uncertainty.

Validate with 144 focused tests, typecheck/lint, docs checks and test discovery. Real providers were not verified; the full headless IDA session suite requires unavailable Windows native controls.

* fix(comparison): recheck historical calls-only changes

---------

Co-authored-by: morluto <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 17d2e46bc7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/windows/WindowsOwnedProcess.ts Outdated
let timer: NodeJS.Timeout | undefined;
try {
const signaled = this.kill();
this.#discardOutput = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve unblocked output while stopping the job

When a Windows provider is stopped while its native pipes still contain data (notably after a timeout or cancellation), this unconditional flag causes every later process_poll chunk to be dropped even when both consumers are flowing. That violates ProviderProcessSupervisor's complete-per-stream retention contract (src/process/ProviderProcess.ts:239-241), and runOwnedCommand takes its diagnostic snapshot only after supervisor.stop() (src/process/OwnedCommand.ts:207-230), so the child's final stdout/stderr can disappear from the returned failure evidence; discard only output that is actually blocking cleanup while continuing to forward bytes accepted by consumers.

AGENTS.md reference: AGENTS.md:L13-L13

Useful? React with 👍 / 👎.

Comment thread src/windows/WindowsOwnedProcess.ts Resolved
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Source fixes and publication evidence for the review findings below. Tests and executable checks were skipped at the maintainer's request. Findings that still require a decision or execution evidence remain open.

review thread

The blocked state suppressed all timers, so the native handle had no event-loop liveness owner while callers awaited close. It now schedules a referenced non-polling wake timer while blocked; WindowsOwnedProcess.ref/unref update that timer together with polling timers. The timer never reads native output, preserving the backpressure memory bound. Change is in 17d2e46 (src/windows/WindowsOwnedProcess.ts). Published as 17d2e46; pinned formatting and diff-check only, tests not run.

review thread

A destroyed PassThrough cannot emit drain. The owner now listens for close as well as drain, removes that stream from the blocked set, and ignores future output for destroyed streams so lifecycle polling resumes. Added a destroy regression in 17d2e46 (src/windows/WindowsOwnedProcess.ts and test). Published as 17d2e46; pinned formatting and diff-check only, tests not run.

Comment thread src/windows/WindowsOwnedProcess.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb2b8a9b97

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +374 to +375
if (stream.write(bytes)) return;
this.#blockedOutput.add(stream);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Discard streams that backpressure after cleanup starts

On Windows, if cleanup() begins before a stream is backpressured but a termination-drain poll then makes write() return false (for example after JadxMcpTransport.#stop detaches its stdout reader), this adds a blocker after the one-shot #discardBlockedOutput() has already run. This one-shot ordering is fresh evidence in the revised code: with no remaining consumer, #schedule() stays suppressed until the 5-second cleanup timeout, so the native job is reported unclean; keep forwarding accepted bytes but discard a stream that first backpressures while cleanup is active.

AGENTS.md reference: AGENTS.md:L27-L27

Useful? React with 👍 / 👎.

morluto added a commit that referenced this pull request Oct 14, 2026
Retain unresolved process identity and launch evidence through retryable cleanup. Share capture path normalization and preserve failed filesystem observations. Bound child output and drain Windows pipes without one-chunk throttling.

Reviewed fixes include #1628, #2632, #2644, #2784, #2928, #2931, #2965, #2992, and #3011.

Validation: 92 focused source tests passed; four platform-specific skips. Real Windows and Hopper lifecycle coverage was not rerun.
@sx4im

sx4im commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded — 599a8ee carries the same drain fix on main (verified the file matches) with additional coverage. Thanks for taking it the rest of the way.

@sx4im sx4im closed this Oct 14, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks @sx4im for measuring how one-chunk-per-poll Windows pipe reads throttled large child output. Main’s owned-process path drains output without that fixed idle delay and preserves the blocked-stream lifecycle (main).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working P2: medium Medium priority issue performance Performance regressions, scaling limits, and bounded-resource work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] inspect-wasm-artifact on Windows: output capture ~262 KB/s causes provider_timeout for WAT > ~7.9 MB

3 participants