← Back to Pull requests

Forward SOS/PM/APC strings verbatim on the ConPTY input path #20953

Closed
unknown closed this pull request without merging on Nov 30, 2026 22:31 UTC
View on GitHub
unknown unknown commented on Nov 22, 2026 21:19 UTC
Author

Fixes #20952.

Summary

Problem. ConPTY's input path forwards DCS strings verbatim (SIXEL, tmux DCS tmux; payloads) via the _expectingStringTerminator →FlushToTerminal → ActionPassThroughString mechanism, and since the VtEngine removal the output path relays the client's raw byte stream including every image-protocol escape (#19926 confirmed this for APC).
But an APC string (ESC _ … ESC \) written into the ConPTY input pipe is silently dropped: it shares the SosPmApcString state with SOS/PM, whose event handler is _ActionIgnore(), and the accumulated run is discarded when the terminator dispatches. The practical consequence: the kitty graphics protocol's request/response loop cannot work over ConPTY — a program hosted in a pane can emit a graphics request on output (relayed fine), but the terminal's APC acknowledgement (ESC _ i=… ESC \) written back into the ConPTY input never reaches it. Multiplexers and ConPTY hosts that pipe bytes through (tmux-style, rmux, terminal desktops) hit exactly this.
Evidence (measured live, Windows 11 build 26200.6584, ConPTY = OpenConsole 1.25.2609.30003 via pywinpty 3.1.0's conpty.dll, CreatePseudoConsole flags 0):

Output direction (child → ConPTY output pipe, verbatim survival):

| Sequence | Result |
| --- | --- |
| CSI SGR ESC[31m X ESC[0m | relayed verbatim |
| SIXEL DCS ESC P0;1q … ESC \ | relayed verbatim |
| OSC 1337 (iTerm2) ESC]1337;…BEL | relayed verbatim |
| APC kitty ESC_G…ESC \ | relayed verbatim |
| tmux DCS ESC Ptmux;…ESC \ | relayed verbatim |

Input direction (parent → ConPTY input pipe → child stdin, raw bytes):

| Sequence | Result |
| --- | --- |
| SIXEL DCS intact | arrives verbatim (26/26 bytes) |
| OSC 1337 intact / split | arrives verbatim |
| tmux DCS wrap | arrives verbatim |
| APC kitty intact | dropped — nothing arrives |
| APC kitty split mid-body | dropped |
| DCS DECRQSS $q, OSC 10;?, CSI DA1 | dropped — host answers them (correct) |
| CSI SGR as input | dropped — parsed as keys (correct) |

The asymmetry (DCS forwarded, APC dropped; output relays APC, input drops it) is what this PR fixes, by giving SOS/PM/APC the exact treatment DCS already gets. Dropping queries the host answers is correct and untouched.

Design

Mirror the DCS path, no new engine surface:

1. StateMachine::ProcessCharacter, from-anywhere ESC branch: when the ESC that terminates a SosPmApcString arrives on the input path (gated on the existing _isEngineForInput), set_pendingSosPmApcFlush.
2. _ActionEscDispatch: if the flag is set and the dispatched escape is the ST (ESC \), flush the pending run verbatim through FlushToTerminal() (which routes through ActionPassThroughString → InteractDispatch::WriteStringRaw, the same path DCS uses) and suppress the spurious Alt+\ key dispatch. If anything but ST follows, the string was aborted and stays dropped.
3. CAN/SUB and _EnterGround clear the flag (abort semantics, same as DCS's terminator handling).
4. The output engine is untouched: OutputStateMachineEngine::ActionPassThroughString remains a no-op, and ConPTY's output side already relays the raw client stream in WriteCharsVT.

No opt-in flag is proposed here because the output side already relays these sequences unconditionally — this only makes input consistent with output. (If reviewers prefer an opt-in gate, the natural place is the existing parser Mode enum; happy to rework.)

Tests

New, in src/terminal/parser/ut_parser/StateMachineTest.cpp (TAEF):

  • InputApcStringFlushedVerbatim — intact kitty-graphics-shaped APC reaches WriteStringRaw byte-identical.

  • InputSosStringFlushedVerbatim — SOS shares the state; same outcome.

  • InputApcStringAbortedByCsiStaysDropped — abort (CSI instead of ST) stays dropped, no flush leak.

  • OutputApcStringNotPassedThrough — output engine unchanged.
  • Verification performed on the contributor's machine

  • Parser.UnitTests.vcxproj (Debug x64) builds clean; full parser DLL:

  • 763/764 passed, 0 failed (the one skip is the pre-existing self-skipped InputEngineTest::RoundTripTest, TODO GH#4405).
  • Adapter.UnitTests.vcxproj builds and runs clean: 413/413.

  • The four new tests pass individually and as part of the suite.

  • TerminalCore unit tests could not be built standalone here (Windows SDK retarget required outside the .slnx build); CI covers them.
  • Live end-to-end behavior after a fix lands can be verified with any ConPTY host that writes raw bytes into the input pipe (pywinpty /winpty-rs harnesses) by writing ESC _ i=… ESC \ and observing the child receive it.

    Limitations

  • Sequences whose bytes arrive split across reads while the parser sits inside the string state are dropped mid-body, exactly as DCS strings are today (the cacheUnusedRun exclusion covers SosPmApcString, DcsPassThrough,DcsIgnore alike). Intact sequences — the common case for terminal-originated ACKs — are fully covered. If reviewers want, caching for the input path can be added for all three states as a follow-up.

  • When Windows Terminal itself is the ConPTY parent it sends encoded win32-input-mode data, not raw bytes; this fix matters for raw-byte parents (multiplexers, pty libraries) — the same audience the DCS passthrough already serves.
  • Upstream context / prior discussion

  • #1173 — ConPTY passthrough mode (closed by the VtEngine-removal refactor #17510; this continues the direction it enabled on the input side).

  • #19926 — confirmed output-side APC relay + cursor desync; fixed by #20009 ("Send a CPR request on every unknown sequence", 1.26).

  • The kitty graphics protocol's ACK flow is what breaks without this: app emits APC request on output (relayed), terminal answers with APC on input (dropped today).
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: DHowett Review duration: 11592m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #20953"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%