Skip to content

feat: task slot cost#4393

Open
BloggerBust wants to merge 4 commits into
hatchet-dev:mainfrom
BloggerBust:feat/task-slot-cost
Open

feat: task slot cost#4393
BloggerBust wants to merge 4 commits into
hatchet-dev:mainfrom
BloggerBust:feat/task-slot-cost

Conversation

@BloggerBust

Copy link
Copy Markdown
Collaborator

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

What's Changed

  • A slot cost option in each SDK's task definition
  • An engine fix so registered slot units persist (pkg/repository/sqlcv1/workflows.sql)
  • A docs page under advanced assignment, with example snippets and cross-links
  • Tests that the scheduler reserves the requested slots, that registration stores them (red before the fix), and that the SDKs send them
  • TypeScript SDK 1.25.0 and Python SDK 1.34.0, with changelog entries

Checklist

Changes have been:

  • Tested (unit, integration, or manually with steps specified)
  • Linted and formatted
  • Documented (where applicable)
  • Added to CHANGELOG (where applicable) -- see Keep a Changelog

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

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.
@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

@BloggerBust is attempting to deploy a commit to the Hatchet Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added documentation Improvements or additions to documentation sdk-ts Related to the Typescript SDK sdk-go Related to the Go SDK sdk-py Related to the Python sdk engine Related to the core Hatchet engine labels Jul 9, 2026
@BloggerBust BloggerBust force-pushed the feat/task-slot-cost branch from 680b288 to bf90486 Compare July 9, 2026 23:50
@BloggerBust BloggerBust added the semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases label Jul 9, 2026
Comment thread sdks/typescript/src/v1/task.ts
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation engine Related to the core Hatchet engine sdk-go Related to the Go SDK sdk-py Related to the Python sdk sdk-ts Related to the Typescript SDK semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants