Skip to content

Implement 5s timeout for ConPTY handoff embedding. - #20051

Open
Kuldeep2822k wants to merge 1 commit into
microsoft:mainfrom
Kuldeep2822k:handoff-timeout-timer
Open

Implement 5s timeout for ConPTY handoff embedding.#20051
Kuldeep2822k wants to merge 1 commit into
microsoft:mainfrom
Kuldeep2822k:handoff-timeout-timer

Conversation

@Kuldeep2822k

Copy link
Copy Markdown

Add a timer in WindowEmperor to automatically exit after 5 seconds if no windows are created during a ConPTY handoff. The timer is cancelled as soon as a new window is created. This prevents the process from staying alive indefinitely if a handoff fails or is never received.

Summary of the Pull Request

I've implemented a 5-second timeout for the ConPTY handoff embedding in the Windows Terminal.

  1. Added a SafeDispatcherTimer _handoffTimeoutTimer; member to the WindowEmperor class.
  2. In HandleCommandlineArgs, when the application is launched with the -Embedding flag (ConPTY handoff), the timer is started with a 5-second interval.
  3. If the timer ticks (indicating no window was created within 5 seconds), it calls _postQuitMessageIfNeeded() to attempt an application exit.
  4. In CreateNewWindow, the timer is explicitly stopped to ensure that the application doesn't exit if a window is successfully created.

The implementation follows the existing codebase patterns using SafeDispatcherTimer and _postQuitMessageIfNeeded

References and Relevant Issues

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

PR Checklist

  • Closes #xxx
  • Tests added/passed
  • Documentation updated
    • If checked, please file a pull request on our docs repo and link it here: #xxx
  • Schema updated (if necessary)

@Kuldeep2822k

Copy link
Copy Markdown
Author

@Kuldeep2822k please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

@lhecker

lhecker commented Apr 2, 2026

Copy link
Copy Markdown
Member

How did you test this?

@Kuldeep2822k

Copy link
Copy Markdown
Author

How did you test this?

I tested this by launching wt.exe -Embedding without sending a handoff signal. The process (PID 18960) exited automatically after ~5 seconds, confirming the SafeDispatcherTimer fires and calls _postQuitMessageIfNeeded() correctly. Without this fix, the process would remain alive indefinitely.

@DHowett DHowett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lhecker honestly I'm not sure I hate this; it seems reasonable that we don't want to stick around, and we did leave a comment about that!

@lhecker lhecker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DHowett yep!

@DHowett

DHowett commented Aug 1, 2026

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.

@DHowett
DHowett enabled auto-merge (squash) August 1, 2026 17:31
@DHowett
DHowett disabled auto-merge August 1, 2026 17:31
@DHowett
DHowett enabled auto-merge (squash) August 1, 2026 17:32
auto-merge was automatically disabled August 5, 2026 18:34

Head branch was pushed to by a user without write access

@github-actions

This comment has been minimized.

@DHowett

DHowett commented Aug 5, 2026

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.

@DHowett

DHowett commented Aug 5, 2026

Copy link
Copy Markdown
Member

did you fix the code format by eye or by using one of our code formatting scripts...

@DHowett

DHowett commented Aug 5, 2026

Copy link
Copy Markdown
Member

(i ask since it failed again)

@Kuldeep2822k

Copy link
Copy Markdown
Author

I fixed it by eye — I didn't use your code formatting scripts. Here's what I did:

Identified the CI failure: "Code Health Check Code Format failed"
Read your .clang-format configuration to understand the Microsoft style rules
Examined the code changes in WindowEmperor.cpp
Spotted the unnecessary blank lines before/after _handoffTimeoutTimer.Stop();
Manually edited the file to remove them

this was done because i use linux

@DHowett

DHowett commented Aug 5, 2026

Copy link
Copy Markdown
Member

you know, clang-format runs on linux...

@DHowett

DHowett commented Aug 5, 2026

Copy link
Copy Markdown
Member

as long as you don't munge the line endings :)

@Kuldeep2822k

Copy link
Copy Markdown
Author

from what i understand it i ran curl.exe -s -S -L "https://raw.githubusercontent.com/check-spelling/check-spelling/cfb6f7e75bbfc89c71eaa30366d0c166f1bd9c8c/apply.pl" | perl - "https://github.com/microsoft/terminal/actions/runs/31035358696/attempts/1"
and commit it should fix it ?

@DHowett

DHowett commented Aug 5, 2026

Copy link
Copy Markdown
Member

this is not a spelling check failure. that script will not help you.

@Kuldeep2822k

Copy link
Copy Markdown
Author

you know, clang-format runs on linux...

oh sorry i missed that i was trying to run but it kept failing so i tried a general approach

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Kuldeep2822k
Kuldeep2822k force-pushed the handoff-timeout-timer branch from 5e124f2 to 8f1cf6b Compare August 5, 2026 20:46
@Kuldeep2822k

Copy link
Copy Markdown
Author

i have resolved the spell check issue now it cleared without any issue can you check @DHowett

@DHowett

DHowett commented Aug 5, 2026

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants