Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 11, 2025

Description

Terminal sticky scroll fails on second task run when presentation.clear: true is configured. getCommandForLine() returns disposed commands because it compares marker line numbers without checking validity—disposed markers have line === -1, making -1 <= 0 evaluate true.

Changes

Modified getCommandForLine() in commandDetectionCapability.ts:

  • Filter commands where marker.line === -1 (disposed after clearBuffer())
  • Check first command marker validity before iteration
  • Added inline comment explaining disposal state

Added test coverage:

  • Verifies disposed commands are skipped after xterm.clear()
  • Confirms current partial command is returned instead of stale command

Example

// Before: returned disposed command with marker.line === -1
const command = capability.getCommandForLine(0);

// After: skips disposed commands, returns current command
if (commandMarker.line !== -1 && commandMarker.line <= line) {
    return this.commands[i];
}

Related to #199305

Original prompt

This section details on the original issue you should resolve

<issue_title>Task terminal sticky scroll bug after being cleared</issue_title>
<issue_description>
Type: Bug

With the following task.json (and a sufficiently small terminal), running the task twice makes the terminal sticky scroll feature bug, as the command is not printed twice after the task's terminal is cleared.

This is very similar to #199305

{
	"version": "2.0.0",
	"tasks": [
		{
			"label": "whatever",
			"type": "shell",
			"command": "echo 'manatee\nchocolate\ndistribute\npride\nfox\nfree\nmethod\ntradition\npenny\nfreight\nproductive\nconference'",
			"presentation": { "clear": true }
		}
	]
}

VS Code version: Code 1.106.2 (1e3c50d, 2025-11-19T16:56:50.023Z)
OS version: Linux x64 6.17.8-arch1-1
Modes:

Extensions (10)
Extension Author (truncated) Version
copilot-chat Git 0.33.3
rainbow-csv mec 3.23.0
debugpy ms- 2025.16.0
python ms- 2025.18.0
vscode-pylance ms- 2025.10.2
vscode-python-envs ms- 1.12.0
remote-ssh ms- 0.120.0
remote-ssh-edit ms- 0.87.0
hexeditor ms- 1.11.1
remote-explorer ms- 0.5.0
A/B Experiments
vsliv368cf:30146710
pythonvspyt551:31249599
binariesv615:30325510
nativeloc1:31344060
dwcopilot:31170013
dwoutputs:31242946
copilot_t_ci:31333650
e5gg6876:31282496
pythonrdcb7:31342333
aj953862:31281341
nes-set-on:31351930
6abeh943:31336334
envsdeactivate2:31353495
cloudbuttont:31379625
todos-1:31405332
qwen_all_req:31402696
treatment_gpt5applypatchexclusively:31412086
3efgi100_wstrepl:31403338
trigger-command-fix:31379601
auto_model_enabled:31385282
use-responses-api:31390855
6j29d282:31407606
ec5jj548:31422691
copilot-nes-oct-t:31418199
cmp-ext-treat:31426748
cp_cls_c_966_ss:31426491
defaultvisibility:31426295
expandedtokens:31426297
c0683394:31419495
ief76360:31426358
g0h3h215:31426582
b53de340:31426751
fa76a614:31426783
38bie571_auto:31426784

<agent_instructions>Investigate and tell me what happens when terminal is re-used for tasks.
What happens with output. Scrollback, viewport of that task termianl. When task are first run, secondly run. </agent_instructions>

Comments on the Issue (you are @copilot in this section)

@anthonykim1 Thanks for the issue! Will investigate. Need to figure out what happens when we re-run task in same terminal.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits December 11, 2025 22:45
When a task is re-run with presentation.clear=true, clearBuffer() is called which disposes old markers (sets line to -1). The old commands remain in the _commands array with invalid markers. getCommandForLine() was checking if marker.line <= requestedLine, which incorrectly returned old commands since -1 <= 0 is true.

This fix filters out commands with invalid markers (line === -1) in getCommandForLine(), ensuring only valid commands are returned.

Fixes terminal sticky scroll showing incorrect/missing command information on second task run.

Co-authored-by: anthonykim1 <[email protected]>
Copilot AI changed the title [WIP] Fix terminal sticky scroll bug after being cleared Fix terminal sticky scroll returning disposed commands after clearBuffer Dec 11, 2025
Copilot AI requested a review from anthonykim1 December 11, 2025 22:49
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.

Task terminal sticky scroll bug after being cleared

2 participants