Skip to content

Conversation

@cwillisf
Copy link
Contributor

@cwillisf cwillisf commented Nov 10, 2025

Sorry for assigning this to so many people, but I'm not sure who has time & scope to review this. If you don't, no worries! If you do, come see the cool bike shed I made! 😅

Resolves

In support of POD-238

Proposed Changes

Extract TaskQueue from scratch-vm into its own package, @scratch/task-herder, with some improvements. The new package is still part of the scratch-editor mono-repository.

Reason for Changes

I want to reuse this code in scratch-storage, which implies moving it to a common location.

Test Coverage

There are 6 test suites totalling 100% coverage:

  • Basics like constructing an instance and exceeding simple limits
  • Task cancellation
  • Rate limiting
  • Concurrency limit=1 (serialized / non-concurrent tasks)
  • Concurrency limit=2 (some concurrency)
  • Rate limiting mixed with concurrency

Since this is the first scratch-editor component using these build tools, I also wanted to check the CI behavior. To do that, I intentionally checked in failing tests during the draft phase of this PR. Check the GHA history of this branch to see how that went. These tests prompted me to make some changes, but I'm happy with where it ended up.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2025

Test report for task-herder

14 tests   14 ✅  0s ⏱️
 6 suites   0 💤
 1 files     0 ❌

Results for commit 3bc929c.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2025

Test report for scratch-svg-renderer

  1 files  ±0   60 suites  ±0   0s ⏱️ ±0s
124 tests ±0  124 ✅ ±0  0 💤 ±0  0 ❌ ±0 
276 runs  ±0  275 ✅ ±0  1 💤 ±0  0 ❌ ±0 

Results for commit 3bc929c. ± Comparison against base commit 8326b04.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2025

Test report for scratch-render

  1 files  ±0   55 suites  ±0   2s ⏱️ ±0s
209 tests ±0  209 ✅ ±0  0 💤 ±0  0 ❌ ±0 
279 runs  ±0  279 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 3bc929c. ± Comparison against base commit 8326b04.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2025

Test report for scratch-vm

    1 files  ± 0    763 suites   - 7   1m 5s ⏱️ ±0s
1 666 tests  - 20  1 666 ✅  - 20   0 💤 ±0  0 ❌ ±0 
4 855 runs   - 36  4 825 ✅  - 36  30 💤 ±0  0 ❌ ±0 

Results for commit 3bc929c. ± Comparison against base commit 8326b04.

This pull request removes 20 tests.
test/unit/util_task-queue.js > cancel ‑ Canceled task must not delay other tasks
test/unit/util_task-queue.js > cancel ‑ should be equal
test/unit/util_task-queue.js > cancel ‑ should be equivalent
test/unit/util_task-queue.js > cancelAll ‑ Tasks should cancel in order
test/unit/util_task-queue.js > constructor ‑ should be equal
test/unit/util_task-queue.js > max total cost ‑ (unnamed test)
test/unit/util_task-queue.js > max total cost ‑ should be equal
test/unit/util_task-queue.js > run tasks ‑ All tasks must run in correct order
test/unit/util_task-queue.js > run tasks ‑ Cheap task should run soon
test/unit/util_task-queue.js > run tasks ‑ Costly task must wait
…

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2025

Test report for scratch-gui

  2 files  ±0   62 suites  ±0   11m 1s ⏱️ +55s
398 tests ±0  390 ✅ ±0  8 💤 ±0  0 ❌ ±0 
416 runs  ±0  408 ✅ ±0  8 💤 ±0  0 ❌ ±0 

Results for commit 3bc929c. ± Comparison against base commit 8326b04.

♻️ This comment has been updated with latest results.

@cwillisf cwillisf marked this pull request as ready for review November 10, 2025 19:29
@cwillisf cwillisf requested a review from a team as a code owner November 10, 2025 19:29
@cwillisf cwillisf requested review from AndyForest, KManolov3, adzhindzhi, colbygk and Copilot and removed request for a team November 10, 2025 19:29
Copy link

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

This PR extracts the TaskQueue functionality from scratch-vm into a new standalone package @scratch/task-herder with several improvements including TypeScript support, modern build tooling (Vite/Rolldown), comprehensive test coverage (100%), and better API design. The package implements a token bucket algorithm for rate limiting combined with configurable concurrency control.

Key Changes:

  • New package @scratch/task-herder with TypeScript implementation replacing the old JavaScript TaskQueue in scratch-vm
  • Modern build configuration using Vite/Rolldown instead of traditional Webpack
  • Enhanced API with AbortSignal support and improved error handling
  • Comprehensive test suite with 6 test files achieving 100% coverage

Reviewed Changes

Copilot reviewed 26 out of 27 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/task-herder/src/TaskHerder.ts Main implementation of the token bucket + concurrency limiter
packages/task-herder/src/PromiseWithResolvers.ts Polyfill for Promise.withResolvers
packages/task-herder/test/*.test.ts Comprehensive test suites for all functionality
packages/task-herder/package.json Package configuration with modern dependencies
packages/task-herder/vite.config.js Vite build configuration with Rolldown
packages/task-herder/README.md Usage documentation and examples
packages/scratch-vm/src/util/task-queue.js Removed old implementation
.editorconfig Removed global indent_size setting
package.json Added new workspace and globals dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

The `abortSignal` name is more descriptive, but using `signal` instead
means that the API is more consistent with `fetch`. Since I expect this
to be used with `fetch` quite a bit, I think the consistency is
worthwhile.
Copy link

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

Copilot reviewed 26 out of 27 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@KManolov3 KManolov3 left a comment

Choose a reason for hiding this comment

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

After the new coat of paint this tool shed looks better than ever! 🙌

This also makes the class name less ambiguous: I'm working on an
additional feature that groups queues together, and I didn't want to end
up in a situation where I'm talking about a HerdHerd. That's the kind of
silliness that belongs in lunchtime conversations, not debugging
sessions :D
@cwillisf cwillisf added this pull request to the merge queue Nov 12, 2025
Merged via the queue into develop with commit 610c599 Nov 12, 2025
23 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 12, 2025
@cwillisf cwillisf deleted the task-herder branch November 12, 2025 15:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants