Repository navigation
preview-controller: output-stall watchdog measures progress, not frame start (#774) - #788
Merged
Merged
Conversation
#774) Root cause, confirmed against this branch's own repro (20 `yes` processes, 18-core machine): the per-write stall watchdog judged a frame's write by elapsed time since the write *started*, using a single write_all() through the process's buffered Stdout. Under reader backpressure a large reply (500KB+) legitimately takes longer than any fixed threshold to drain, but looks identical to a truly stuck pipe from that vantage point -- so PR #775's "raise 2s to 10s" only delays the same failure to a bigger payload or a busier machine, it doesn't fix the underlying blind spot. Fix: the writer thread now writes to the raw stdout fd (bypassing the LineWriter, which would otherwise swallow a whole line-terminated frame into one opaque blocking call) in bounded WRITE_CHUNK pieces, resetting the watchdog's clock on every chunk that makes forward progress. A blocking pipe write does not return a short count under backpressure, so chunking the *request* is what keeps control returning to the watchdog periodically. A slow-but-alive reader now keeps resetting the clock indefinitely; a reader that never drains anything still trips OUTPUT_STALL_TIMEOUT exactly as before. Verified against the pre-existing intentionally-never-read tests (now recalibrated to the shared 10s bound, matching PR #772's family), plus a new test that reads a 2.2MB reply in artificially slow, steadily-paced chunks totaling ~16s -- longer than the watchdog bound -- and asserts the helper stays alive and delivers the reply byte-exact. Also ran LargeDocumentEditorTests.testLargePasteSelectionAndTypingEndDurableThroughTheRealHelper 3x under real 20-process CPU contention with this branch's preview-controller and the fix681 compiler: all three passed (6.8s/7.3s/7.2s), no stalls. crates/preview-controller/STDIO.md updated to describe the progress-based bound instead of the stale "two seconds" line. Implementation-Agent: claude-sonnet-5 subagent of daniel-parent (Commander) Commit-Executor: daniel-parent subagent Co-authored-by: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #774. Supersedes #775, which only raised the timeout from 2 s to 10 s.
Problem
The stdout writer's stall watchdog timed each frame from the moment its
write_allbegan. Under a slow but live reader, a reply of 500 KB or more legitimately takes longer than any fixed bound, and the watchdog killed the helper with "output stalled; delivery uncertain".LargeDocumentEditorTestshit this under CPU contention.Fix
LineWriterthat turned a whole frame into one opaque blocking call.write(2)is at most 64 KB, and every accepted chunk resets the watchdog clock.OUTPUT_STALL_TIMEOUTis 10 s with no forward progress. A slow reader survives; a stuck one still trips the watchdog.STDIO.mdis updated.Tests
cargo test --releaseincrates/preview-controller: 89 passed, 0 failed, 4 ignored.slow_but_progressing_reader_survives_a_reply_far_longer_than_the_watchdogpaces a 2.2 MB reply over about 16 s and checks it arrives byte-exact.LargeDocumentEditorTests.testLargePasteSelectionAndTypingEndDurableThroughTheRealHelperpassed 3 of 3 times with this helper, with 20 CPU-bound processes running alongside.Attribution
Implemented by a Claude Sonnet 5 lane under daniel-parent (Commander).
🤖 Generated with Claude Code