← Back to Pull requests

Repeat the whole surrogate pair in REP #20999

Open
unknown opened this pull request with 307 lines diff across 3 files
View on GitHub
unknown unknown commented on Dec 01, 2026 03:30 UTC
Author

Summary of the Pull Request

REP (CSI Ps b) remembered only the last UTF-16 code unit that was printed. For characters outside the BMP, that is the trailing half of a surrogate pair. So for example printf '\U0001FB81\e[3b' printed one U+1FB81 followed by three lone trailing surrogates.

The output engine now stores the last code point (1 or 2 code units), and REP repeats all of it.

Detailed description of the pull request

  • OutputStateMachineEngine keeps the last printed character as std::array<wchar_t, 2> plus a size, instead of a single wchar_t.

  • A new _StashLastChar uses til::utf16_iterate_prev to store the last code point of each print.

  • If a leading surrogate arrives alone in one print call and a trailing surrogate arrives alone in the next, they are joined. This follows the _leadingSurrogate pattern in TerminalInput.

  • Unpaired surrogates are repeated as before.

  • Any other action still clears the stored character, so a pair that is interrupted is not joined.
  • Open question: should unpaired surrogates be dropped instead of repeated? I kept the old behavior to keep the change minimal.

    Validation Steps Performed

  • Added StateMachineExternalTest::TestRepeatCharacterSupplementaryPlane. It covers a pair in one string, a pair then REP in a separate write, text ending in a pair, a pair split across writes, a pair fed with ProcessCharacter, a trailing surrogate after other text, and plain characters.

  • CI on my fork passed: x86, x64 and arm64 builds, all Unit, Feature and Local test passes, Check Formatting, and Static Analysis (AuditMode). StateMachineExternalTest::TestRepeatCharacterSupplementaryPlane and TextBufferTests::TestRepeatCharacter both pass on x86, x64 and arm64.

  • Ran the parser sources through a local edge-case suite (split writes, unpaired surrogates, large counts, OSC/DCS in between). Plain text with no surrogates gave the same output before and after.
  • Before / After

    The left half shows REP printing only the trailing surrogate (D83E DF81 DF81 DF81 DF81). The right half shows it repeating the whole pair (D83E DF81 x4).

    https://github.com/user-attachments/assets/3969013f-5652-4278-b950-55f75fb5371a

    AI disclosure: I used an AI assistant to help write and test this fix. I reviewed, understood and tested the change myself.

    PR Checklist


  • Closes #15390

  • Tests added/passed

  • Documentation updated: not needed

  • Schema updated: not needed
  • Diff: 307 lines (+230 / -77) across 3 files Reviewer: lhecker Review duration: 3070m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.40) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 307 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.343
    Real PR Conversation Timeline
    1 comments
    "Review active on #20999"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% 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: 40.2% (MEDIUM) · Higher = larger blast radius
    40.2%
    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: 43.0% · Lower = rushed or shallow review
    43.0%
    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: 22.9% · Safe to merge
    22.9%