Skip to content

feat: CANCEL_EXCEPT_NEWEST/CANCEL_EXCEPT_OLDEST concurrency strategies - #4793

Open
juliusgeo wants to merge 16 commits into
mainfrom
new_concurrency_strats
Open

feat: CANCEL_EXCEPT_NEWEST/CANCEL_EXCEPT_OLDEST concurrency strategies#4793
juliusgeo wants to merge 16 commits into
mainfrom
new_concurrency_strats

Conversation

@juliusgeo

@juliusgeo juliusgeo commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Description

Adds two new concurrency strategies:

  • CANCEL_EXCEPT_NEWEST which, while there are no spots available (maxRuns is full), will cancel all runs except the newest. As soon as the currently running tasks end, the newest that was queued while blocked will be enqueued.
  • CANCEL_EXCEPT_OLDEST the same thing except that the oldest run that happened while maxRuns was full will be enqueued when there is space available.

Fixes #4639

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Documentation change (pure documentation change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking changes to code which doesn't change any behaviour)
  • Performance improvement (non-breaking change which improves performance)
  • CI (any automation pipeline changes)
  • Chore (changes which are not directly related to any business logic)
  • Test changes (add, refactor, improve or change a test)
  • This change requires a documentation update

Checklist

Changes have been:

  • Documented (where applicable)
  • Added to CHANGELOG (where applicable) -- see Keep a Changelog

🤖 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: [e.g. generating tests, writing docs]
    Claude code, generating tests, not used for writing docs because it's bad at it

@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hatchet-docs Ready Ready Preview Aug 28, 2026 5:44pm

Request Review

@github-actions github-actions Bot added documentation Improvements or additions to documentation sdk-ts Related to the Typescript SDK sdk-py Related to the Python sdk engine Related to the core Hatchet engine sdk-ruby Related to the Ruby SDK labels Aug 25, 2026
@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Benchmark results

goos: linux
goarch: amd64
pkg: github.com/hatchet-dev/hatchet/pkg/scheduling/v1/concurrency
cpu: AMD Ryzen 9 7950X3D 16-Core Processor          
                                        │ /tmp/old.txt │            /tmp/new.txt            │
                                        │    sec/op    │    sec/op     vs base              │
ConcurrencyThroughput/wal/batch=100-8      2.284 ±  1%    2.287 ±  1%       ~ (p=0.589 n=6)
ConcurrencyThroughput/wal/batch=1000-8    275.0m ±  2%   279.5m ±  4%       ~ (p=0.699 n=6)
ConcurrencyThroughput/wal/batch=10000-8   49.34m ±  3%   50.33m ±  4%       ~ (p=0.240 n=6)
ConcurrencyThroughput/initial-drain-8     8.675m ± 10%   8.774m ± 19%       ~ (p=0.589 n=6)
geomean                                   128.1m         129.6m        +1.22%

                                        │ /tmp/old.txt │            /tmp/new.txt            │
                                        │  slots/sec   │  slots/sec    vs base              │
ConcurrencyThroughput/wal/batch=100-8     87.55k ±  1%   87.44k ±  1%       ~ (p=0.589 n=6)
ConcurrencyThroughput/wal/batch=1000-8    727.3k ±  2%   715.6k ±  4%       ~ (p=0.699 n=6)
ConcurrencyThroughput/wal/batch=10000-8   4.054M ±  3%   3.974M ±  4%       ~ (p=0.240 n=6)
ConcurrencyThroughput/initial-drain-8     23.05M ± 11%   22.79M ± 16%       ~ (p=0.589 n=6)
geomean                                   1.562M         1.543M        -1.21%

                                        │ /tmp/old.txt │            /tmp/new.txt            │
                                        │     B/op     │     B/op      vs base              │
ConcurrencyThroughput/wal/batch=100-8     124.2Mi ± 0%   124.2Mi ± 0%       ~ (p=0.937 n=6)
ConcurrencyThroughput/wal/batch=1000-8    119.8Mi ± 0%   119.8Mi ± 0%       ~ (p=0.589 n=6)
ConcurrencyThroughput/wal/batch=10000-8   109.2Mi ± 0%   109.2Mi ± 0%       ~ (p=0.485 n=6)
ConcurrencyThroughput/initial-drain-8     13.49Mi ± 0%   13.49Mi ± 0%       ~ (p=1.000 n=6)
geomean                                   68.43Mi        68.43Mi       +0.00%

                                        │ /tmp/old.txt │           /tmp/new.txt            │
                                        │  allocs/op   │  allocs/op   vs base              │
ConcurrencyThroughput/wal/batch=100-8      780.5k ± 0%   780.5k ± 0%       ~ (p=0.567 n=6)
ConcurrencyThroughput/wal/batch=1000-8     313.3k ± 0%   313.3k ± 0%       ~ (p=0.240 n=6)
ConcurrencyThroughput/wal/batch=10000-8    97.76k ± 0%   97.75k ± 0%       ~ (p=0.361 n=6)
ConcurrencyThroughput/initial-drain-8      49.06k ± 0%   49.06k ± 0%       ~ (p=0.636 n=6)
geomean                                    185.0k        185.0k       -0.00%

Compared against main (3d586d3)

@juliusgeo
juliusgeo marked this pull request as ready for review August 26, 2026 20:01
@greptile-apps

greptile-apps Bot commented Aug 26, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds CANCEL_EXCEPT_NEWEST and CANCEL_EXCEPT_OLDEST concurrency strategies across the scheduler, repository, API contracts, SDKs, examples, migrations, and documentation.

  • Uses enqueue-time ordering rather than task priority when choosing the oldest or newest queued survivors.
  • Adds scheduler and SQL implementations for standalone and parent concurrency strategies.
  • Exposes the strategies through the Go, Python, Ruby, and TypeScript SDKs.
  • Adds tests, examples, documentation, and the database enum migration.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains from the previously reported issues.

The scheduler now uses an enqueue-time-only comparator for both new strategies, and the previously unsafe negative slice boundary in CANCEL_EXCEPT_OLDEST is clamped before slicing; no blocking failure remains.

Reviews (3): Last reviewed commit: "Merge branch 'main' into new_concurrency..." | Re-trigger Greptile

Comment thread pkg/scheduling/v1/concurrency/strategy.go
Comment thread pkg/scheduling/v1/concurrency/strategy.go Outdated
Comment thread pkg/repository/scheduler_concurrency.go
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-ruby Related to the Ruby SDK sdk-ts Related to the Typescript SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Cancel-except-newest/oldest concurrency strategies.

1 participant