Skip to content

fix(engine): wait for trigger slots on idempotent runs - #4755

Open
grutt wants to merge 2 commits into
mainfrom
fix/idempotent-trigger-slot-wait
Open

fix(engine): wait for trigger slots on idempotent runs#4755
grutt wants to merge 2 commits into
mainfrom
fix/idempotent-trigger-slot-wait

Conversation

@grutt

@grutt grutt commented Aug 20, 2026

Copy link
Copy Markdown
Member

Description

Idempotent workflow triggers now wait for an available in-process trigger slot instead of failing immediately when the slot limit is saturated. If the request deadline expires while waiting, the API returns ResourceExhausted so clients can retry.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Test changes (add, refactor, improve or change a test)

What's Changed

  • Idempotent triggers wait for a slot (or the request deadline) instead of failing as soon as the slot limit is reached
  • Slot exhaustion on that path returns gRPC ResourceExhausted instead of Internal
  • Existing status errors from ingest are no longer wrapped into a generic trigger failure
  • Unit tests cover fail-fast, wait-until-free, and deadline-while-waiting slot acquisition

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

🤖 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: Cursor Grok 4.6 wrote the slot-wait implementation, unit tests, and this PR description.

Idempotent triggers cannot fail-fast into Internal when the in-process
slot limit is saturated; wait for a slot or return ResourceExhausted.
@vercel

vercel Bot commented Aug 20, 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 20, 2026 8:26pm

Request Review

@github-actions github-actions Bot added the engine Related to the core Hatchet engine label Aug 20, 2026
@grutt
grutt requested a review from mrkaye97 August 20, 2026 13:26
@greptile-apps

greptile-apps Bot commented Aug 20, 2026

Copy link
Copy Markdown

Greptile Summary

The PR makes idempotent workflow triggers wait for an in-process trigger slot and preserves gRPC status errors returned through the trigger path.

  • Introduces shared blocking and fail-fast semaphore acquisition.
  • Uses blocking acquisition for idempotent batches in both admin API implementations.
  • Adds tests for immediate exhaustion, successful unblocking, and deadline expiration.

Confidence Score: 4/5

The PR should not merge until canceled idempotent trigger requests retain cancellation semantics instead of being returned as retryable capacity failures.

The previously reported cancellation issue remains: acquireSlot wraps context cancellation together with ErrNoTriggerSlots, and both ingest implementations classify that combined error as ResourceExhausted.

Files Needing Attention: internal/services/controllers/task/trigger/trigger.go, internal/services/admin/server_v1.go, internal/services/admin/v1/server.go

Reviews (2): Last reviewed commit: "Merge branch 'main' into fix/idempotent-..." | Re-trigger Greptile

return ErrNoTriggerSlots
return func() { <-tw.semaphore }, nil
case <-ctx.Done():
return nil, fmt.Errorf("%w: %w", ErrNoTriggerSlots, ctx.Err())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Cancellation becomes slot exhaustion

When a client cancels an idempotent trigger while it is waiting for a slot, this error wraps both context.Canceled and ErrNoTriggerSlots, so both ingest callers return ResourceExhausted instead of Canceled, causing clients to treat a deliberately canceled request as a retryable capacity failure.

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.

I think this is legit

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

lgtm pending greptile comment, also discussed offline the memory leak risk here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine Related to the core Hatchet engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants