Repository navigation
Conversation
|
Status note: the red I split the benchmark fixture fix into #2596, which replaces the httpbin curl benchmark with local |
Adopts the design from upstream rtk-ai#2581: collapse_terminal_control rewrites carriage-return progress redraws and backspace overwrites to the final line state before captured output reaches the filters, on both run_streaming and exec_capture. For a token-saving, model-facing tool this is better than emitting every transient redraw frame (the earlier LineChunks approach this replaces): the model sees 'Downloading 100%' once, not every percent. Supersedes this fork's prior LineChunks commit; see brief 003. Real CRLF line endings are preserved.
The adopted collapse (rtk-ai#2581) parses \r/\b/\n but has no CSI awareness, so an erase-in-line sequence (ESC[K) — exactly how programs do a *shrinking* redraw (\r + erase a longer previous frame) — was overlaid as literal characters: the escape bytes leaked into output AND the stale tail survived (e.g. 'Downloading 100%\r\x1b[KDone' rendered 'x1b[KDoneding 100%' instead of 'Done'). Root cause: escape bytes and printable bytes went through different write paths. Fix: parse a CSI sequence as a unit; honor ESC[K (0/1/2) against the cursor; overlay every other CSI (SGR colour, motion) through the SAME shared write path as printable text, so colour still passes through to the filters unchanged (prior contract) and a later \r redraw overwrites prior escape bytes cell-for-cell instead of shifting them. A bare \r with no erase still faithfully overlays (Downloading 100%\rDone -> Doneloading 100%), matching a real terminal. Scope boundary: models the cursor, not per-cell colour attributes (a full VT emulator, out of scope). Tests: ESC[K to-EOL + mid-line, SGR passthrough, coloured \r-redraw overlay, bare-\r faithful overlay, progress bar, backspace, plain/CRLF unchanged. Delta over upstream rtk-ai#2581 — offer back as a review comment (see brief 003).
…an't hang capture When the direct child exits but a detached descendant keeps the captured pipe open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild), reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming with background reader threads plus a bounded post-exit drain: once the direct child is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still blocked on a descendant-held pipe. Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581): readers accumulate raw bytes, collapse_terminal_control is applied to the final buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation. This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the exec_capture half only. See brief 004 (issue rtk-ai#2320).
Adopts the design from upstream rtk-ai#2581: collapse_terminal_control rewrites carriage-return progress redraws and backspace overwrites to the final line state before captured output reaches the filters, on both run_streaming and exec_capture. For a token-saving, model-facing tool this is better than emitting every transient redraw frame (the earlier LineChunks approach this replaces): the model sees 'Downloading 100%' once, not every percent. Supersedes this fork's prior LineChunks commit; see brief 003. Real CRLF line endings are preserved.
The adopted collapse (rtk-ai#2581) parses \r/\b/\n but has no CSI awareness, so an erase-in-line sequence (ESC[K) — exactly how programs do a *shrinking* redraw (\r + erase a longer previous frame) — was overlaid as literal characters: the escape bytes leaked into output AND the stale tail survived (e.g. 'Downloading 100%\r\x1b[KDone' rendered 'x1b[KDoneding 100%' instead of 'Done'). Root cause: escape bytes and printable bytes went through different write paths. Fix: parse a CSI sequence as a unit; honor ESC[K (0/1/2) against the cursor; overlay every other CSI (SGR colour, motion) through the SAME shared write path as printable text, so colour still passes through to the filters unchanged (prior contract) and a later \r redraw overwrites prior escape bytes cell-for-cell instead of shifting them. A bare \r with no erase still faithfully overlays (Downloading 100%\rDone -> Doneloading 100%), matching a real terminal. Scope boundary: models the cursor, not per-cell colour attributes (a full VT emulator, out of scope). Tests: ESC[K to-EOL + mid-line, SGR passthrough, coloured \r-redraw overlay, bare-\r faithful overlay, progress bar, backspace, plain/CRLF unchanged. Delta over upstream rtk-ai#2581 — offer back as a review comment (see brief 003).
…an't hang capture When the direct child exits but a detached descendant keeps the captured pipe open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild), reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming with background reader threads plus a bounded post-exit drain: once the direct child is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still blocked on a descendant-held pipe. Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581): readers accumulate raw bytes, collapse_terminal_control is applied to the final buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation. This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the exec_capture half only. See brief 004 (issue rtk-ai#2320).
Adopts the design from upstream rtk-ai#2581: collapse_terminal_control rewrites carriage-return progress redraws and backspace overwrites to the final line state before captured output reaches the filters, on both run_streaming and exec_capture. For a token-saving, model-facing tool this is better than emitting every transient redraw frame (the earlier LineChunks approach this replaces): the model sees 'Downloading 100%' once, not every percent. Supersedes this fork's prior LineChunks commit; see brief 003. Real CRLF line endings are preserved.
The adopted collapse (rtk-ai#2581) parses \r/\b/\n but has no CSI awareness, so an erase-in-line sequence (ESC[K) — exactly how programs do a *shrinking* redraw (\r + erase a longer previous frame) — was overlaid as literal characters: the escape bytes leaked into output AND the stale tail survived (e.g. 'Downloading 100%\r\x1b[KDone' rendered 'x1b[KDoneding 100%' instead of 'Done'). Root cause: escape bytes and printable bytes went through different write paths. Fix: parse a CSI sequence as a unit; honor ESC[K (0/1/2) against the cursor; overlay every other CSI (SGR colour, motion) through the SAME shared write path as printable text, so colour still passes through to the filters unchanged (prior contract) and a later \r redraw overwrites prior escape bytes cell-for-cell instead of shifting them. A bare \r with no erase still faithfully overlays (Downloading 100%\rDone -> Doneloading 100%), matching a real terminal. Scope boundary: models the cursor, not per-cell colour attributes (a full VT emulator, out of scope). Tests: ESC[K to-EOL + mid-line, SGR passthrough, coloured \r-redraw overlay, bare-\r faithful overlay, progress bar, backspace, plain/CRLF unchanged. Delta over upstream rtk-ai#2581 — offer back as a review comment (see brief 003).
…an't hang capture When the direct child exits but a detached descendant keeps the captured pipe open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild), reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming with background reader threads plus a bounded post-exit drain: once the direct child is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still blocked on a descendant-held pipe. Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581): readers accumulate raw bytes, collapse_terminal_control is applied to the final buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation. This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the exec_capture half only. See brief 004 (issue rtk-ai#2320).
Adopts the design from upstream rtk-ai#2581: collapse_terminal_control rewrites carriage-return progress redraws and backspace overwrites to the final line state before captured output reaches the filters, on both run_streaming and exec_capture. For a token-saving, model-facing tool this is better than emitting every transient redraw frame (the earlier LineChunks approach this replaces): the model sees 'Downloading 100%' once, not every percent. Supersedes this fork's prior LineChunks commit; see brief 003. Real CRLF line endings are preserved.
The adopted collapse (rtk-ai#2581) parses \r/\b/\n but has no CSI awareness, so an erase-in-line sequence (ESC[K) — exactly how programs do a *shrinking* redraw (\r + erase a longer previous frame) — was overlaid as literal characters: the escape bytes leaked into output AND the stale tail survived (e.g. 'Downloading 100%\r\x1b[KDone' rendered 'x1b[KDoneding 100%' instead of 'Done'). Root cause: escape bytes and printable bytes went through different write paths. Fix: parse a CSI sequence as a unit; honor ESC[K (0/1/2) against the cursor; overlay every other CSI (SGR colour, motion) through the SAME shared write path as printable text, so colour still passes through to the filters unchanged (prior contract) and a later \r redraw overwrites prior escape bytes cell-for-cell instead of shifting them. A bare \r with no erase still faithfully overlays (Downloading 100%\rDone -> Doneloading 100%), matching a real terminal. Scope boundary: models the cursor, not per-cell colour attributes (a full VT emulator, out of scope). Tests: ESC[K to-EOL + mid-line, SGR passthrough, coloured \r-redraw overlay, bare-\r faithful overlay, progress bar, backspace, plain/CRLF unchanged. Delta over upstream rtk-ai#2581 — offer back as a review comment (see brief 003).
…an't hang capture When the direct child exits but a detached descendant keeps the captured pipe open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild), reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming with background reader threads plus a bounded post-exit drain: once the direct child is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still blocked on a descendant-held pipe. Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581): readers accumulate raw bytes, collapse_terminal_control is applied to the final buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation. This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the exec_capture half only. See brief 004 (issue rtk-ai#2320).
|
Thanks for this — I picked it up while working on the same capture path and it's the right approach (collapse to the final rendered line, on both
Root cause is that escape bytes and printable bytes go through different write paths. The fix that worked for me: parse a CSI sequence ( A couple of cases I'd suggest adding as regression tests (all pass with the fix):
One observation while validating, not a criticism: rtk captures over a pipe, and I measured that tools suppress I have the fix implemented and tested on my fork — commit |
|
Fixed in What changed:
Regression coverage added for:
Local verification:
|
Adopts the design from upstream rtk-ai#2581: collapse_terminal_control rewrites carriage-return progress redraws and backspace overwrites to the final line state before captured output reaches the filters, on both run_streaming and exec_capture. For a token-saving, model-facing tool this is better than emitting every transient redraw frame (the earlier LineChunks approach this replaces): the model sees 'Downloading 100%' once, not every percent. Supersedes this fork's prior LineChunks commit; see brief 003. Real CRLF line endings are preserved.
The adopted collapse (rtk-ai#2581) parses \r/\b/\n but has no CSI awareness, so an erase-in-line sequence (ESC[K) — exactly how programs do a *shrinking* redraw (\r + erase a longer previous frame) — was overlaid as literal characters: the escape bytes leaked into output AND the stale tail survived (e.g. 'Downloading 100%\r\x1b[KDone' rendered 'x1b[KDoneding 100%' instead of 'Done'). Root cause: escape bytes and printable bytes went through different write paths. Fix: parse a CSI sequence as a unit; honor ESC[K (0/1/2) against the cursor; overlay every other CSI (SGR colour, motion) through the SAME shared write path as printable text, so colour still passes through to the filters unchanged (prior contract) and a later \r redraw overwrites prior escape bytes cell-for-cell instead of shifting them. A bare \r with no erase still faithfully overlays (Downloading 100%\rDone -> Doneloading 100%), matching a real terminal. Scope boundary: models the cursor, not per-cell colour attributes (a full VT emulator, out of scope). Tests: ESC[K to-EOL + mid-line, SGR passthrough, coloured \r-redraw overlay, bare-\r faithful overlay, progress bar, backspace, plain/CRLF unchanged. Delta over upstream rtk-ai#2581 — offer back as a review comment (see brief 003).
…an't hang capture When the direct child exits but a detached descendant keeps the captured pipe open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild), reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming with background reader threads plus a bounded post-exit drain: once the direct child is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still blocked on a descendant-held pipe. Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581): readers accumulate raw bytes, collapse_terminal_control is applied to the final buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation. This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the exec_capture half only. See brief 004 (issue rtk-ai#2320).
Adopts the design from upstream rtk-ai#2581: collapse_terminal_control rewrites carriage-return progress redraws and backspace overwrites to the final line state before captured output reaches the filters, on both run_streaming and exec_capture. For a token-saving, model-facing tool this is better than emitting every transient redraw frame (the earlier LineChunks approach this replaces): the model sees 'Downloading 100%' once, not every percent. Supersedes this fork's prior LineChunks commit; see brief 003. Real CRLF line endings are preserved.
The adopted collapse (rtk-ai#2581) parses \r/\b/\n but has no CSI awareness, so an erase-in-line sequence (ESC[K) — exactly how programs do a *shrinking* redraw (\r + erase a longer previous frame) — was overlaid as literal characters: the escape bytes leaked into output AND the stale tail survived (e.g. 'Downloading 100%\r\x1b[KDone' rendered 'x1b[KDoneding 100%' instead of 'Done'). Root cause: escape bytes and printable bytes went through different write paths. Fix: parse a CSI sequence as a unit; honor ESC[K (0/1/2) against the cursor; overlay every other CSI (SGR colour, motion) through the SAME shared write path as printable text, so colour still passes through to the filters unchanged (prior contract) and a later \r redraw overwrites prior escape bytes cell-for-cell instead of shifting them. A bare \r with no erase still faithfully overlays (Downloading 100%\rDone -> Doneloading 100%), matching a real terminal. Scope boundary: models the cursor, not per-cell colour attributes (a full VT emulator, out of scope). Tests: ESC[K to-EOL + mid-line, SGR passthrough, coloured \r-redraw overlay, bare-\r faithful overlay, progress bar, backspace, plain/CRLF unchanged. Delta over upstream rtk-ai#2581 — offer back as a review comment (see brief 003).
…an't hang capture When the direct child exits but a detached descendant keeps the captured pipe open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild), reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming with background reader threads plus a bounded post-exit drain: once the direct child is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still blocked on a descendant-held pipe. Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581): readers accumulate raw bytes, collapse_terminal_control is applied to the final buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation. This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the exec_capture half only. See brief 004 (issue rtk-ai#2320).
Adopts the design from upstream rtk-ai#2581: collapse_terminal_control rewrites carriage-return progress redraws and backspace overwrites to the final line state before captured output reaches the filters, on both run_streaming and exec_capture. For a token-saving, model-facing tool this is better than emitting every transient redraw frame (the earlier LineChunks approach this replaces): the model sees 'Downloading 100%' once, not every percent. Supersedes this fork's prior LineChunks commit; see brief 003. Real CRLF line endings are preserved.
The adopted collapse (rtk-ai#2581) parses \r/\b/\n but has no CSI awareness, so an erase-in-line sequence (ESC[K) — exactly how programs do a *shrinking* redraw (\r + erase a longer previous frame) — was overlaid as literal characters: the escape bytes leaked into output AND the stale tail survived (e.g. 'Downloading 100%\r\x1b[KDone' rendered 'x1b[KDoneding 100%' instead of 'Done'). Root cause: escape bytes and printable bytes went through different write paths. Fix: parse a CSI sequence as a unit; honor ESC[K (0/1/2) against the cursor; overlay every other CSI (SGR colour, motion) through the SAME shared write path as printable text, so colour still passes through to the filters unchanged (prior contract) and a later \r redraw overwrites prior escape bytes cell-for-cell instead of shifting them. A bare \r with no erase still faithfully overlays (Downloading 100%\rDone -> Doneloading 100%), matching a real terminal. Scope boundary: models the cursor, not per-cell colour attributes (a full VT emulator, out of scope). Tests: ESC[K to-EOL + mid-line, SGR passthrough, coloured \r-redraw overlay, bare-\r faithful overlay, progress bar, backspace, plain/CRLF unchanged. Delta over upstream rtk-ai#2581 — offer back as a review comment (see brief 003).
Adopts the design from upstream rtk-ai#2581: collapse_terminal_control rewrites carriage-return progress redraws and backspace overwrites to the final line state before captured output reaches the filters, on both run_streaming and exec_capture. For a token-saving, model-facing tool this is better than emitting every transient redraw frame (the earlier LineChunks approach this replaces): the model sees 'Downloading 100%' once, not every percent. Supersedes this fork's prior LineChunks commit; see brief 003. Real CRLF line endings are preserved.
The adopted collapse (rtk-ai#2581) parses \r/\b/\n but has no CSI awareness, so an erase-in-line sequence (ESC[K) — exactly how programs do a *shrinking* redraw (\r + erase a longer previous frame) — was overlaid as literal characters: the escape bytes leaked into output AND the stale tail survived (e.g. 'Downloading 100%\r\x1b[KDone' rendered 'x1b[KDoneding 100%' instead of 'Done'). Root cause: escape bytes and printable bytes went through different write paths. Fix: parse a CSI sequence as a unit; honor ESC[K (0/1/2) against the cursor; overlay every other CSI (SGR colour, motion) through the SAME shared write path as printable text, so colour still passes through to the filters unchanged (prior contract) and a later \r redraw overwrites prior escape bytes cell-for-cell instead of shifting them. A bare \r with no erase still faithfully overlays (Downloading 100%\rDone -> Doneloading 100%), matching a real terminal. Scope boundary: models the cursor, not per-cell colour attributes (a full VT emulator, out of scope). Tests: ESC[K to-EOL + mid-line, SGR passthrough, coloured \r-redraw overlay, bare-\r faithful overlay, progress bar, backspace, plain/CRLF unchanged. Delta over upstream rtk-ai#2581 — offer back as a review comment (see brief 003).
…an't hang capture When the direct child exits but a detached descendant keeps the captured pipe open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild), reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming with background reader threads plus a bounded post-exit drain: once the direct child is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still blocked on a descendant-held pipe. Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581): readers accumulate raw bytes, collapse_terminal_control is applied to the final buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation. This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the exec_capture half only. See brief 004 (issue rtk-ai#2320).
Adopts the design from upstream rtk-ai#2581: collapse_terminal_control rewrites carriage-return progress redraws and backspace overwrites to the final line state before captured output reaches the filters, on both run_streaming and exec_capture. For a token-saving, model-facing tool this is better than emitting every transient redraw frame (the earlier LineChunks approach this replaces): the model sees 'Downloading 100%' once, not every percent. Supersedes this fork's prior LineChunks commit; see brief 003. Real CRLF line endings are preserved.
The adopted collapse (rtk-ai#2581) parses \r/\b/\n but has no CSI awareness, so an erase-in-line sequence (ESC[K) — exactly how programs do a *shrinking* redraw (\r + erase a longer previous frame) — was overlaid as literal characters: the escape bytes leaked into output AND the stale tail survived (e.g. 'Downloading 100%\r\x1b[KDone' rendered 'x1b[KDoneding 100%' instead of 'Done'). Root cause: escape bytes and printable bytes went through different write paths. Fix: parse a CSI sequence as a unit; honor ESC[K (0/1/2) against the cursor; overlay every other CSI (SGR colour, motion) through the SAME shared write path as printable text, so colour still passes through to the filters unchanged (prior contract) and a later \r redraw overwrites prior escape bytes cell-for-cell instead of shifting them. A bare \r with no erase still faithfully overlays (Downloading 100%\rDone -> Doneloading 100%), matching a real terminal. Scope boundary: models the cursor, not per-cell colour attributes (a full VT emulator, out of scope). Tests: ESC[K to-EOL + mid-line, SGR passthrough, coloured \r-redraw overlay, bare-\r faithful overlay, progress bar, backspace, plain/CRLF unchanged. Delta over upstream rtk-ai#2581 — offer back as a review comment (see brief 003).
…an't hang capture When the direct child exits but a detached descendant keeps the captured pipe open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild), reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming with background reader threads plus a bounded post-exit drain: once the direct child is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still blocked on a descendant-held pipe. Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581): readers accumulate raw bytes, collapse_terminal_control is applied to the final buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation. This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the exec_capture half only. See brief 004 (issue rtk-ai#2320).
…an't hang capture When the direct child exits but a detached descendant keeps the captured pipe open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild), reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming with background reader threads plus a bounded post-exit drain: once the direct child is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still blocked on a descendant-held pipe. Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581): readers accumulate raw bytes, collapse_terminal_control is applied to the final buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation. This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the exec_capture half only. See brief 004 (issue rtk-ai#2320).
Adopts the design from upstream rtk-ai#2581: collapse_terminal_control rewrites carriage-return progress redraws and backspace overwrites to the final line state before captured output reaches the filters, on both run_streaming and exec_capture. For a token-saving, model-facing tool this is better than emitting every transient redraw frame (the earlier LineChunks approach this replaces): the model sees 'Downloading 100%' once, not every percent. Supersedes this fork's prior LineChunks commit; see brief 003. Real CRLF line endings are preserved.
The adopted collapse (rtk-ai#2581) parses \r/\b/\n but has no CSI awareness, so an erase-in-line sequence (ESC[K) — exactly how programs do a *shrinking* redraw (\r + erase a longer previous frame) — was overlaid as literal characters: the escape bytes leaked into output AND the stale tail survived (e.g. 'Downloading 100%\r\x1b[KDone' rendered 'x1b[KDoneding 100%' instead of 'Done'). Root cause: escape bytes and printable bytes went through different write paths. Fix: parse a CSI sequence as a unit; honor ESC[K (0/1/2) against the cursor; overlay every other CSI (SGR colour, motion) through the SAME shared write path as printable text, so colour still passes through to the filters unchanged (prior contract) and a later \r redraw overwrites prior escape bytes cell-for-cell instead of shifting them. A bare \r with no erase still faithfully overlays (Downloading 100%\rDone -> Doneloading 100%), matching a real terminal. Scope boundary: models the cursor, not per-cell colour attributes (a full VT emulator, out of scope). Tests: ESC[K to-EOL + mid-line, SGR passthrough, coloured \r-redraw overlay, bare-\r faithful overlay, progress bar, backspace, plain/CRLF unchanged. Delta over upstream rtk-ai#2581 — offer back as a review comment (see brief 003).
…an't hang capture When the direct child exits but a detached descendant keeps the captured pipe open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild), reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming with background reader threads plus a bounded post-exit drain: once the direct child is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still blocked on a descendant-held pipe. Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581): readers accumulate raw bytes, collapse_terminal_control is applied to the final buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation. This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the exec_capture half only. See brief 004 (issue rtk-ai#2320).
Adopts the design from upstream rtk-ai#2581: collapse_terminal_control rewrites carriage-return progress redraws and backspace overwrites to the final line state before captured output reaches the filters, on both run_streaming and exec_capture. For a token-saving, model-facing tool this is better than emitting every transient redraw frame (the earlier LineChunks approach this replaces): the model sees 'Downloading 100%' once, not every percent. Supersedes this fork's prior LineChunks commit; see brief 003. Real CRLF line endings are preserved.
The adopted collapse (rtk-ai#2581) parses \r/\b/\n but has no CSI awareness, so an erase-in-line sequence (ESC[K) — exactly how programs do a *shrinking* redraw (\r + erase a longer previous frame) — was overlaid as literal characters: the escape bytes leaked into output AND the stale tail survived (e.g. 'Downloading 100%\r\x1b[KDone' rendered 'x1b[KDoneding 100%' instead of 'Done'). Root cause: escape bytes and printable bytes went through different write paths. Fix: parse a CSI sequence as a unit; honor ESC[K (0/1/2) against the cursor; overlay every other CSI (SGR colour, motion) through the SAME shared write path as printable text, so colour still passes through to the filters unchanged (prior contract) and a later \r redraw overwrites prior escape bytes cell-for-cell instead of shifting them. A bare \r with no erase still faithfully overlays (Downloading 100%\rDone -> Doneloading 100%), matching a real terminal. Scope boundary: models the cursor, not per-cell colour attributes (a full VT emulator, out of scope). Tests: ESC[K to-EOL + mid-line, SGR passthrough, coloured \r-redraw overlay, bare-\r faithful overlay, progress bar, backspace, plain/CRLF unchanged. Delta over upstream rtk-ai#2581 — offer back as a review comment (see brief 003).
…an't hang capture When the direct child exits but a detached descendant keeps the captured pipe open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild), reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming with background reader threads plus a bounded post-exit drain: once the direct child is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still blocked on a descendant-held pipe. Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581): readers accumulate raw bytes, collapse_terminal_control is applied to the final buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation. This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the exec_capture half only. See brief 004 (issue rtk-ai#2320).
Adopts the design from upstream rtk-ai#2581: collapse_terminal_control rewrites carriage-return progress redraws and backspace overwrites to the final line state before captured output reaches the filters, on both run_streaming and exec_capture. For a token-saving, model-facing tool this is better than emitting every transient redraw frame (the earlier LineChunks approach this replaces): the model sees 'Downloading 100%' once, not every percent. Supersedes this fork's prior LineChunks commit; see brief 003. Real CRLF line endings are preserved.
The adopted collapse (rtk-ai#2581) parses \r/\b/\n but has no CSI awareness, so an erase-in-line sequence (ESC[K) — exactly how programs do a *shrinking* redraw (\r + erase a longer previous frame) — was overlaid as literal characters: the escape bytes leaked into output AND the stale tail survived (e.g. 'Downloading 100%\r\x1b[KDone' rendered 'x1b[KDoneding 100%' instead of 'Done'). Root cause: escape bytes and printable bytes went through different write paths. Fix: parse a CSI sequence as a unit; honor ESC[K (0/1/2) against the cursor; overlay every other CSI (SGR colour, motion) through the SAME shared write path as printable text, so colour still passes through to the filters unchanged (prior contract) and a later \r redraw overwrites prior escape bytes cell-for-cell instead of shifting them. A bare \r with no erase still faithfully overlays (Downloading 100%\rDone -> Doneloading 100%), matching a real terminal. Scope boundary: models the cursor, not per-cell colour attributes (a full VT emulator, out of scope). Tests: ESC[K to-EOL + mid-line, SGR passthrough, coloured \r-redraw overlay, bare-\r faithful overlay, progress bar, backspace, plain/CRLF unchanged. Delta over upstream rtk-ai#2581 — offer back as a review comment (see brief 003).
…an't hang capture When the direct child exits but a detached descendant keeps the captured pipe open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild), reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming with background reader threads plus a bounded post-exit drain: once the direct child is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still blocked on a descendant-held pipe. Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581): readers accumulate raw bytes, collapse_terminal_control is applied to the final buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation. This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the exec_capture half only. See brief 004 (issue rtk-ai#2320).
Adopts the design from upstream rtk-ai#2581: collapse_terminal_control rewrites carriage-return progress redraws and backspace overwrites to the final line state before captured output reaches the filters, on both run_streaming and exec_capture. For a token-saving, model-facing tool this is better than emitting every transient redraw frame (the earlier LineChunks approach this replaces): the model sees 'Downloading 100%' once, not every percent. Supersedes this fork's prior LineChunks commit; see brief 003. Real CRLF line endings are preserved.
The adopted collapse (rtk-ai#2581) parses \r/\b/\n but has no CSI awareness, so an erase-in-line sequence (ESC[K) — exactly how programs do a *shrinking* redraw (\r + erase a longer previous frame) — was overlaid as literal characters: the escape bytes leaked into output AND the stale tail survived (e.g. 'Downloading 100%\r\x1b[KDone' rendered 'x1b[KDoneding 100%' instead of 'Done'). Root cause: escape bytes and printable bytes went through different write paths. Fix: parse a CSI sequence as a unit; honor ESC[K (0/1/2) against the cursor; overlay every other CSI (SGR colour, motion) through the SAME shared write path as printable text, so colour still passes through to the filters unchanged (prior contract) and a later \r redraw overwrites prior escape bytes cell-for-cell instead of shifting them. A bare \r with no erase still faithfully overlays (Downloading 100%\rDone -> Doneloading 100%), matching a real terminal. Scope boundary: models the cursor, not per-cell colour attributes (a full VT emulator, out of scope). Tests: ESC[K to-EOL + mid-line, SGR passthrough, coloured \r-redraw overlay, bare-\r faithful overlay, progress bar, backspace, plain/CRLF unchanged. Delta over upstream rtk-ai#2581 — offer back as a review comment (see brief 003).
…an't hang capture When the direct child exits but a detached descendant keeps the captured pipe open (e.g. dotnet's build server, or `ng build`'s esbuild --service grandchild), reading until pipe EOF blocks forever. Replace the unbounded reads in run_streaming with background reader threads plus a bounded post-exit drain: once the direct child is reaped, only drain briefly (idle-grace + hard cap), and never join a reader still blocked on a descendant-held pipe. Re-derived on top of the collapse-to-final CRLF handling (003 / upstream rtk-ai#2581): readers accumulate raw bytes, collapse_terminal_control is applied to the final buffers. Tests cover both capture and streaming paths plus fast-exit no-truncation. This is the run_streaming half of the orphaned-pipe hang; upstream rtk-ai#2322 fixes the exec_capture half only. See brief 004 (issue rtk-ai#2320).
|
The CSI-as-a-unit rewrite in Provenance: AI-assisted source audit, human-directed. Source read at
|
|
Thanks — this still looks like the right layer for the fix. I rechecked the capture path on Reproduction with the generic capture path: The Source path on current
The direction in this PR — collapse before line splitting, model
One process note: |
Adapted from ftlpickleball/rtk d98ffa4 (Apache-2.0), which reworks rtk-ai#2581. Only filter input is collapsed: raw output, the tee and rtk recall keep the exact bytes, and CRLF endings are kept.
Summary
exec_captureandrun_streamingcapture/filter pathsFixes #2230
Verification
cargo +1.93.0 fmt --checkgit diff --checkcargo +1.93.0 test core::stream::tests -- --nocapturecargo +1.93.0 clippy --all-targetscargo +1.93.0 test --all -- --skip small_grep_not_worse_than_plain