Skip to content

Fix empty OSC 2 sequence not clearing terminal title#315317

Open
wpfleger96 wants to merge 5 commits into
microsoft:mainfrom
wpfleger96:wpfleger/empty-osc-2-not-clearing-terminal-title
Open

Fix empty OSC 2 sequence not clearing terminal title#315317
wpfleger96 wants to merge 5 commits into
microsoft:mainfrom
wpfleger96:wpfleger/empty-osc-2-not-clearing-terminal-title

Conversation

@wpfleger96
Copy link
Copy Markdown

@wpfleger96 wpfleger96 commented May 8, 2026

When a shell sends an empty OSC 2 sequence (\033]2;\007), the ${sequence} terminal title variable should reset to "" and the tab should revert to the process name. Instead, _sequence retained its last non-empty value permanently.

The guard in _updateTitleProperties used if (!title), which treats empty string as falsy and returns before the TitleEventSource.Sequence case can assign this._sequence = "". xterm.js correctly fires onTitleChange("") for empty OSC 2 — the bug was entirely in VS Code's handler. Changed to if (title == null) so empty strings flow through to the switch while still guarding undefined/null.

Since the broader guard also lets empty strings through the Api path, rename("") (reachable from the rename input box) would now set _staticTitle = "" and _titleSource = Api, blocking future process-name updates. Added a normalization in rename() that converts empty/whitespace-only titles to undefined, so the existing null guard handles it as a reset — matching validateTerminalName's stated intent.

  • terminalInstance.ts: change guard from !title to title == null
  • terminalInstance.ts: normalize empty rename() input to undefined
  • terminalInstance.test.ts: add test for empty sequence falling back to process name

Fixes #312403

`_updateTitleProperties` guarded with `if (!title)`, treating empty
string as falsy and early-returning before the Sequence case could
set `this._sequence = ""`. Change to `if (title == null)` so empty
OSC 2 sequences flow through and clear the title variable, letting
the tab revert to the process name.
Copilot AI review requested due to automatic review settings May 8, 2026 17:17
@wpfleger96
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

…itle

* main:
  Fixes tests
  Escapes model id in chatEditHunk event
  Strip codicons from terminal quickpick filter matching (microsoft#313197)
  Approval telemetry (microsoft#315215)
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes handling of empty OSC 2 title sequences so ${sequence} can be cleared (and tab titles can fall back to the process name) by allowing empty strings to flow through the terminal title update logic.

Changes:

  • Update TerminalInstance._updateTitleProperties to guard only null/undefined (not ""), enabling empty OSC 2 to clear the stored sequence.
  • Add a TerminalLabelComputer test asserting ${sequence}${separator}${process} resolves to the process name when sequence: "".

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/vs/workbench/contrib/terminal/browser/terminalInstance.ts Adjusts title update guard to allow empty strings through, enabling sequence clearing.
src/vs/workbench/contrib/terminal/test/browser/terminalInstance.test.ts Adds a label-template test for the empty-sequence fallback behavior.

Comment thread src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
wpfleger96 added 2 commits May 8, 2026 14:09
`rename("")` is reachable from the rename input box (validateTerminalName
shows an info message but doesn't block). With the `title == null` guard
change, empty string now flows into the Api case and sets `_staticTitle`
/ `_titleSource`, blocking future process-name updates. Normalize empty
to `undefined` so it hits the null guard and resets as intended.
…2-not-clearing-terminal-title

* upstream/main:
  chat: hide plugin actions for synced customization items (microsoft#315320)
  fixes microsoft#291188 (microsoft#314713)
  sessions: restore last active session on reload (microsoft#315312)
  Replace "Agents app" with "Agents window" in user-facing strings (microsoft#315302)
  chat: remove 'Bridged' badge from MCP servers in AI Customizations UI (microsoft#315319)
  Add proposal for custom editor diff/merge priority
  agentHost: revert undefined-field omission, update tests instead
  sessions: fix Customizations single-entry width overflow (microsoft#315125)
  agentHost: rewrite Resource attachments and omit undefined fields
  agentHost: support image and blob user-message attachments
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.

Empty OSC 2 escape sequence does not clear ${sequence} terminal title variable

3 participants