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

Closed
opened 2026-01-31 06:15:36 +00:00 by claunia · 3 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:36 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Sep 16, 2022):

Hmm wait something else might be going on here. This might be a nothingburger. The Flush is on the same thread as the EndPaint for VT, and that's on the VT thread.

I'm not even hitting AdaptDispatch::DoFinalTermAction with A; as a param here. I must have messed up my pwsh profile.... somehow.

@zadjii-msft commented on GitHub (Sep 16, 2022): Hmm wait something else might be going on here. This might be a nothingburger. The Flush is on the same thread as the EndPaint for VT, and that's _on the VT_ thread. I'm not even hitting `AdaptDispatch::DoFinalTermAction` with `A;` as a param here. I must have messed up my `pwsh` profile.... somehow.
Author
Owner

@zadjii-msft commented on GitHub (Sep 16, 2022):

  $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)\";

image

image

i don't want to talk about it.

@zadjii-msft commented on GitHub (Sep 16, 2022): ```pwsh $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)\"; ``` ![image](https://user-images.githubusercontent.com/18356694/190690394-cc0d6395-fa6a-48af-bf79-ea9c236d4127.png) ![image](https://user-images.githubusercontent.com/18356694/190690453-e2d68fd5-2e09-4775-941d-19978b3f6f9b.png) i don't want to talk about it.
Author
Owner

@DHowett commented on GitHub (Sep 16, 2022):

🤣

@DHowett commented on GitHub (Sep 16, 2022): 🤣
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#18486