Passed-through sequences can get lost during a flush #18484

Open
opened 2026-01-31 06:15:31 +00:00 by claunia · 0 comments
Owner

Originally created by @zadjii-msft on GitHub (Sep 16, 2022).

446ef22044/src/renderer/vt/state.cpp (L140-L167)

Look at that. That's running on the renderer thread. If the VT thread is running at this exact time, then it's possible for

  1. VT to trigger a flush
  2. Renderer to start flushing, call WriteFile (L152)
  3. VT to append some passed thru seq to the _buffer
  4. Renderer to call _buffer.clear() L153
    • 🫥 the sequence is gone now.

Testing with

function prompt {
  $loc = $($executionContext.SessionState.Path.CurrentLocation);
  # IMPORTANT: Make sure there's a printable charater _last_ in the prompt.
  # Otherwise, PSReadline is gonna use the terminating `\` here and colorize
  # that if it detects a syntax error
  $out += "$([char]27)]133;A;$([char]27)\";
  $out += "$([char]27)]9;9;`"$loc`"$([char]27)\";
  $out = "PS $loc$('>' * ($nestedPromptLevel + 1)) ";
  $out += "$([char]27)]133;B;$([char]27)\";
  return $out
}

You only get the command started sequence, but the first one is gonzo.

Originally created by @zadjii-msft on GitHub (Sep 16, 2022). https://github.com/microsoft/terminal/blob/446ef2204454b3997da9103cbe86473fdab41c62/src/renderer/vt/state.cpp#L140-L167 Look at that. That's running on the renderer thread. If the VT thread is running at this exact time, then it's possible for 1. VT to trigger a flush 2. Renderer to start flushing, call `WriteFile` (L152) 3. VT to append some passed thru seq to the `_buffer` 4. Renderer to call `_buffer.clear()` L153 - 🫥 the sequence is gone now. Testing with ```pwsh function prompt { $loc = $($executionContext.SessionState.Path.CurrentLocation); # IMPORTANT: Make sure there's a printable charater _last_ in the prompt. # Otherwise, PSReadline is gonna use the terminating `\` here and colorize # that if it detects a syntax error $out += "$([char]27)]133;A;$([char]27)\"; $out += "$([char]27)]9;9;`"$loc`"$([char]27)\"; $out = "PS $loc$('>' * ($nestedPromptLevel + 1)) "; $out += "$([char]27)]133;B;$([char]27)\"; return $out } ``` You only get the command started sequence, but the first one is gonzo.
claunia added the Needs-TriageNeeds-Tag-Fix labels 2026-01-31 06:15:31 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#18484