Skip to content

fix: correct ArrayQueue boundaries in takeWhile and takeFromEndWhile - #301119

Merged
Henning Dieterichs (hediet) merged 5 commits into
microsoft:mainfrom
Muszic:fix-arrayqueue-boundaries
Jul 29, 2026
Merged

fix: correct ArrayQueue boundaries in takeWhile and takeFromEndWhile#301119
Henning Dieterichs (hediet) merged 5 commits into
microsoft:mainfrom
Muszic:fix-arrayqueue-boundaries

Conversation

@Muszic

Copy link
Copy Markdown
Contributor

This PR fixes two symmetrical boundary bugs in ArrayQueue where takeWhile and takeFromEndWhile would ignore the internal lastIdx and firstIdx pointers. If both methods were interleaved on the same queue instance, it would lead to out-of-bounds reading and queue state corruption.

Fixes:

  • takeWhile now correctly checks startIdx <= this.lastIdx (previously checked against this.items.length).
  • takeFromEndWhile now correctly checks endIdx >= this.firstIdx (previously checked >= 0).

Tests:
Added regression tests to arrays.test.ts to ensure that mixed calls to takeWhile and takeFromEndWhile safely respect the active boundaries of the queue. Also includes the updated monaco.d.ts generated by the watch task.

@Muszic

Copy link
Copy Markdown
Contributor Author

Review the PR please João Moreno (@joaomoreno)

@joaomoreno

Copy link
Copy Markdown
Contributor

Sangeet (@Muszic) Did you review it yourself? What's up with those monaco.d.ts changes? Please remove them.

@Muszic
Sangeet (Muszic) force-pushed the fix-arrayqueue-boundaries branch from 2624ff2 to 5429fc5 Compare March 16, 2026 16:12
@Muszic

Copy link
Copy Markdown
Contributor Author

João Moreno (@joaomoreno) Apologies for that! The local watch task generated those diffs while I was compiling the test runner, and I mistakenly lumped them into the commit.

I have removed the monaco.d.ts changes and updated the branch. The PR is now strictly scoped to the ArrayQueue logic fix and the regression tests. Thanks for catching that!

@Muszic

Copy link
Copy Markdown
Contributor Author

Review the PR please João Moreno (@joaomoreno)

@joaomoreno

Copy link
Copy Markdown
Contributor

Moving it to Henning Dieterichs (@hediet)

@Muszic

Copy link
Copy Markdown
Contributor Author

Review the PR please Henning Dieterichs (@hediet)

3 similar comments
@Muszic

Copy link
Copy Markdown
Contributor Author

Review the PR please Henning Dieterichs (@hediet)

@Muszic

Copy link
Copy Markdown
Contributor Author

Review the PR please Henning Dieterichs (@hediet)

@Muszic

Copy link
Copy Markdown
Contributor Author

Review the PR please Henning Dieterichs (@hediet)

@hediet Henning Dieterichs (hediet) added this to the 1.114.0 milestone Mar 25, 2026
@Muszic

Copy link
Copy Markdown
Contributor Author

Henning Dieterichs (@hediet) I updated the branch and triggered a rebuild to clear out those flaky infrastructure failures (OOM and GPU crash). Whenever you have a moment, could you approve the workflows to run again? Thank you!

@Muszic

Copy link
Copy Markdown
Contributor Author

Ulugbek Abdullaev (@ulugbekna) Henning Dieterichs (@hediet) Thank you both for the reviews and approvals!

Since I am an outside contributor, the CI is currently paused. Could one of you please trigger the workflows when you get a chance so the auto-merge can finish up? Thank you!

@Muszic

Copy link
Copy Markdown
Contributor Author

Henning Dieterichs (@hediet) Ulugbek Abdullaev (@ulugbekna) Thank you both again for the approvals!

The CI is currently failing on the Linux runners, but the errors appear to be completely unrelated infrastructure/main branch issues rather than the ArrayQueue changes. Specifically:

Browser: Playwright is throwing HTTP 404s for vsda_bg.wasm.

Remote: The headless GPU process is crashing 6 times on initialization.

Since the core logic changes have been approved, could one of you kindly force-merge this, or trigger a re-run if those main branch issues have been patched? Thank you!

@Muszic

Copy link
Copy Markdown
Contributor Author

Henning Dieterichs (@hediet) Ulugbek Abdullaev (@ulugbekna) Can you please trigger a re-run or force merge

@Muszic

Copy link
Copy Markdown
Contributor Author

@Muszic

Copy link
Copy Markdown
Contributor Author

Can you please run the workflows and merge Henning Dieterichs (@hediet)

@alexr00 Alex Ross (alexr00) removed this from the 1.114.0 milestone Mar 30, 2026
@Muszic

Copy link
Copy Markdown
Contributor Author

Can you please run the workflows and merge Henning Dieterichs (@hediet) Ulugbek Abdullaev (@ulugbekna)

Copilot AI review requested due to automatic review settings June 2, 2026 09:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes a bug in ArrayQueue.takeWhile and takeFromEndWhile where the loop bounds used the underlying array's full range instead of respecting the queue's current firstIdx/lastIdx window. This caused incorrect results when both methods were used on the same queue.

Changes:

  • Use this.lastIdx as the upper bound in takeWhile instead of this.items.length.
  • Use this.firstIdx as the lower bound in takeFromEndWhile instead of 0.
  • Add a mixed-usage test covering both orderings.

Reviewed changes

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

File Description
src/vs/base/common/arrays.ts Constrain loop iteration to the active queue window in both take methods.
src/vs/base/test/common/arrays.test.ts Adds a test verifying correct behavior when takeWhile and takeFromEndWhile are mixed.

@Muszic

Copy link
Copy Markdown
Contributor Author

merge the PR please Henning Dieterichs (@hediet)

@hediet
Henning Dieterichs (hediet) merged commit fab68ed into microsoft:main Jul 29, 2026
29 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.132.0 milestone Jul 29, 2026
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.

8 participants