← Back to Pull requests

Fix repeated alt-buffer entry using the stale main viewport size #20825

Merged
Huang-404-Q merged 2 files (26 lines) on Oct 23, 2026 03:55 UTC
View on GitHub
Huang-404-Q Huang-404-Q commented on Oct 20, 2026 11:23 UTC
Author

Summary

UseAlternateScreenBuffer sized the new alt buffer from _mutableViewport, which still holds the main-buffer size while the alt buffer is active: a resize in alt mode only updates _altBufferSize. A second ?1049h therefore rebuilt the alt buffer at the pre-resize size.

Use the existing _GetMutableViewport() helper (added for GH#3493), which returns _altBufferSize while in the alt buffer.

Fixes #20820.

Validation

Added TerminalApiTest::RepeatedAltBufferEntryKeepsLiveSize: create 100x30, enter alt, resize to 120x40, re-enter ?1049h, assert the buffer is 120x40.

I could not build or run the test locally: Visual Studio/MSBuild is not installed on this machine. The change is a one-line use of an existing helper; CI should run Terminal.Core.Unit.Tests.

AI assistance

Tool(s) used: Claude Code

How you used it: the assistant read the code, wrote the fix and the test. A human reviewed the diff and takes responsibility for the change.

  • I've read and understand every line of this change and take responsibility for it — it's not unreviewed AI output.
  • Diff: 26 lines (+25 / -1) across 2 files Reviewer: lhecker Review duration: 3871m
    All Vouch review confidence checks passed
    Residual risk 0.09 = Change Risk (0.29) × (1 − Review Confidence (0.68)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.29 · 26 lines diff across 2 files
    0.29
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.46 · 5 substantive comment(s)
    0.46
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    67%
    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.197
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    12 items
    azure-pipelines[bot] azure-pipelines[bot] commented on Oct 20, 2026 11:23 UTC
    Bot

    <!-- AzurePipelinesStatusComment -->
    <samp>
    Azure Pipelines:<br>
    There may be pipelines that require an authorized user to comment /azp run to run.<br>

    </samp>

    lhecker lhecker approved these changes on Oct 20, 2026 12:41 UTC
    Approved Reviewer

    The unit test is a bit verbose because it asserts on things that aren't relevant to what is being tested, but it's okay.

    Thank you for the fix!

    lhecker lhecker commented on Oct 20, 2026 12:43 UTC
    Contributor

    /azp run

    azure-pipelines[bot] azure-pipelines[bot] commented on Oct 20, 2026 12:44 UTC
    Bot

    <samp>
    Azure Pipelines:<br>
    Successfully started running 1 pipeline(s).<br>
    1 pipeline(s) were filtered out due to trigger conditions.<br>

    </samp>

    DHowett DHowett commented on Oct 20, 2026 23:01 UTC
    Contributor

    @huang-404-q we are unable to merge your submission until you accept the Contributor License Agreement.

    DHowett DHowett commented on code on Oct 20, 2026 23:03 UTC
    Code Review
    src/cascadia/TerminalCore/TerminalApi.cpp:1
    @@ -244,7 +244,10 @@ void Terminal::UseAlternateScreenBuffer(const TextAttribute& attrs)
         _assertLocked();
     
         // the new alt buffer is exactly the size of the viewport.
    -    _altBufferSize = _mutableViewport.Dimensions();
    +    // Use the live viewport: while the alt buffer is active, a resize only
    +    // updates _altBufferSize, so _mutableViewport still holds the stale main
    +    // size. A repeated ?1049h would otherwise rebuild the alt buffer at it.
    +    _altBufferSize = _GetMutableViewport().Dimensions();
    

        // Using the active viewport ensures that re-entering the alt buffer doesn't use the stale main viewport dimensions.
        _altBufferSize = _GetMutableViewport().Dimensions();
    

    this comment reads like Claudish, and is unpleasant to the eyes

    DHowett DHowett commented on code on Oct 20, 2026 23:04 UTC
    Code Review
    src/cascadia/UnitTests_TerminalCore/TerminalApiTest.cpp:1
    @@ -257,6 +258,29 @@ void TerminalCoreUnitTests::TerminalApiTest::AddHyperlinkCustomIdDifferentUri()
         VERIFY_ARE_NOT_EQUAL(oldAttributes.GetHyperlinkId(), tbi.GetCurrentAttributes().GetHyperlinkId());
     }
     
    +void TerminalApiTest::RepeatedAltBufferEntryKeepsLiveSize()
    +{
    +    Terminal term{ Terminal::TestDummyMarker{} };
    +    DummyRenderer renderer{ &term };
    +    term.Create({ 100, 30 }, 0, renderer);
    +
    +    auto settings = winrt::make<MockTermSettings>(0, 30, 100);
    +    term.UpdateSettings(settings);
    +
    +    term.UseAlternateScreenBuffer(TextAttribute{});
    +    VERIFY_ARE_EQUAL(term.GetTextBuffer().GetSize().Width(), 100);
    +
    +    // While the alt buffer is active, a resize only updates _altBufferSize.
    +    VERIFY_SUCCEEDED(term.UserResize({ 120, 40 }));
    +    VERIFY_ARE_EQUAL(term.GetTextBuffer().GetSize().Width(), 120);
    +
    +    // A repeated ?1049h must rebuild the alt buffer at the live size, not the
    +    // stale main-buffer viewport size.
    

        // Activating the alternate screen buffer a second time must not change its size.
    

    DHowett DHowett requested changes on Oct 20, 2026 23:04 UTC
    Changes Requested Reviewer

    plus the CLA.

    DHowett DHowett commented on Oct 23, 2026 03:16 UTC
    Contributor

    /azp run

    azure-pipelines[bot] azure-pipelines[bot] commented on Oct 23, 2026 03:16 UTC
    Bot

    <samp>
    Azure Pipelines:<br>
    Successfully started running 1 pipeline(s).<br>
    1 pipeline(s) were filtered out due to trigger conditions.<br>

    </samp>

    DHowett DHowett approved these changes on Oct 23, 2026 03:16 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    Huang-404-Q Huang-404-Q
    Labels
    risk: low confidence: 67.8% 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: 29.2% (LOW) · Higher = larger blast radius
    29.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: 67.8% · Lower = rushed or shallow review
    67.8%
    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: 9.4% · Safe to merge
    9.4%