microsoft / microsoft/vscode

Editor group restore keeps phantom sticky editors when several sticky editors fail to deserialize

Open
#332,635 0 comments 0 reactions 1 assignee Claimed by @benibenj View on GitHub
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

### Bug description

`EditorGroupModel.deserialize` (`src/vs/workbench/common/editor/editorGroupModel.ts`) decreases the serialized sticky index once per editor that fails to deserialize, so the sticky marker stays aligned after the editors array is compacted:

```ts
if (!editor && typeof data.sticky === 'number' && index <= data.sticky) {
data.sticky--;
}
```

The comparison uses the already-decremented value. Once one dead sticky slot has been processed, a later dead slot whose raw index was still inside the original sticky range no longer satisfies `index <= data.sticky` and is skipped. The restored group keeps more sticky editors than were serialized (phantom stickiness), including a sticky count of 1 on an otherwise empty group.

Minimal failing vector: serialized editors `[dead, alive, dead, alive]` with `sticky = 2` restores `sticky = 1`, correct is `0`. With `[dead, dead, alive]` and `sticky = 1` the old code restores `0`, correct is `-1` (no sticky editors).

### Steps to reproduce

1. Serialize a group where several editors inside the sticky prefix fail to deserialize (e.g. their serializer is gone after an extension uninstall), with at least one surviving editor between two dead ones.
2. Deserialize: `stickyCount` is higher than the number of sticky editors that actually survived.

### Expected behavior

The decrement fires once per dead editor whose raw index falls inside the serialized sticky prefix; comparing against the captured incoming index instead of the mutated value achieves that.

### Version tested

Commit `3d0791852991` on `main`; both failure modes pinned with round-trip unit tests in `editorGroupModel.test.ts`. A fix is ready.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.