feat: task slot cost#4393
Open
BloggerBust wants to merge 4 commits into
Open
Conversation
A task can now declare how many default worker slots it consumes. One
that needs more memory or CPU reserves more slots, so a worker runs
fewer of them at once. The option is slotCost in TypeScript, slot_cost
in Python, and WithSlotCost in Go. Each maps to the engine request
slot_requests {default: N}. The map stays internal and defaults to one
slot.
The scheduler could already reserve multiple slots for a task, but the
engine stored a task's default-slot request as one slot. A trigger
writes a one-slot row when a step is created, and the query that stores
the requested units kept that row on conflict. The fix is the
CreateStepSlotRequests query in pkg/repository/sqlcv1/workflows.sql,
which now overwrites the trigger's row with the requested units.
|
@BloggerBust is attempting to deploy a commit to the Hatchet Team on Vercel. A member of the Team first needs to authorize it. |
680b288 to
bf90486
Compare
grutt
reviewed
Jul 10, 2026
Durable task options inherited slotCost from the base type and silently ignored it, making TypeScript the one SDK where a user could set it with no effect. Setting a real cost on durable slots stays out of scope until the custom slot types work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A customer asked to set how many worker slots a task consumes, so a task that needs more memory or CPU takes up more of a worker's capacity than a light one. The scheduler has supported multi-slot reservations since #2927, but no SDK exposed a way to request them. This adds a slot cost option to the TypeScript, Python, and Go task definitions. Durable and custom slot types are not exposed. The new docs page in this diff,
frontend/docs/pages/v1/advanced-assignment/slot-cost.mdx, explains the option and its limits.The part that needs the closest review is an engine fix. The engine was discarding the slot units a task registered and keeping a one-slot default in their place. Every SDK sent one slot, which matched the default, so no one noticed until the first larger value. The fix is in
pkg/repository/sqlcv1/workflows.sql.In the current behavior, a task whose cost exceeds every worker's slot count is cancelled, which will be confusing and hard to diagnose. I recommend a follow-up to improve diagnosability.
Type of change
What's Changed
pkg/repository/sqlcv1/workflows.sql)Checklist
Changes have been:
Testing
The repository test registers a workflow and checks the stored slot units. It stored one slot before the fix and stores the requested units after. I also tested with a local engine and a TypeScript worker, which confirmed the SDK sends the requested units, and is how the engine bug was found.
🤖 AI Disclosure
I acknowledge that an LLM was used in the creation of this Pull Request, in accordance with Hatchet's AI_POLICY.md.
Details: Claude Code (Claude Fable 5) was used for source investigation & planning as well as tests and validation against a local engine