Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Nov 19, 2025

Overview

Adds client-side configuration for deployment concurrency grace periods, allowing users to control how long infrastructure has to start before concurrency slots are released. This addresses #19410 and brings OSS feature parity with Prefect Cloud.

Previously, the grace period was hardcoded server-side (300s in OSS). Now users can configure it per-deployment via:

  • prefect.yaml deployments
  • flow.deploy() / flow.serve() with ConcurrencyLimitConfig
  • Python deployment APIs

Changes

Schema & Models

  • Added grace_period_seconds field to ConcurrencyOptions (server schema) and ConcurrencyLimitConfig (client schema)
  • Field is optional with default of 600 seconds (10 minutes)
  • Validated range: 60-86400 seconds (1 minute to 1 day)
  • No database migration required - concurrency_options is already a JSON column

Orchestration

  • Updated SecureFlowConcurrencySlots policy to use configured grace period when creating concurrency leases
  • Handles concurrency_options as both dict and Pydantic model for backward compatibility
  • Falls back to server setting (initial_deployment_lease_duration, default 300s) when concurrency_options is None

CLI & Deployment

  • Added grace_period_seconds to ConcurrencyLimitSpec model
  • Updated _run_single_deploy to extract and pass through grace period from YAML
  • Updated RunnerDeployment to map grace period from ConcurrencyLimitConfig to deployment payload
  • Fixed YAML serialization to exclude None values from concurrency_limit dict

Documentation

  • Updated deployment concepts docs with grace period explanation and examples
  • Updated prefect.yaml reference with grace period field description

Test Coverage

Added 9 tests covering:

  • Boundary validation (5 tests): Min/max/default values for grace_period_seconds
  • YAML deployment mapping (2 tests): Verify grace period flows from YAML to deployment, and None values aren't serialized
  • Orchestration behavior (3 tests): Server setting fallback, model default, and custom grace period

All tests passing locally and in CI (49/51 checks passed, 2 cancelled due to infrastructure issues).

Important Review Points

  1. Fallback behavior: When concurrency_options is None, uses server setting (300s). When concurrency_options exists but grace_period_seconds not set, uses model default (600s). This difference is intentional but worth verifying.

  2. Type handling: Orchestration code handles concurrency_options as both dict and Pydantic model instance. This is necessary for backward compatibility but adds complexity.

  3. YAML serialization: Now filters out None values from concurrency_limit dict to avoid cluttering configs. Verify this doesn't affect other optional fields.

  4. Range validation: 60-86400 seconds (1 minute to 1 day). Confirm this range is appropriate for all use cases.


Link to Devin run: https://app.devin.ai/sessions/6a429e264eee42ffa97cffcdd6e0eada
Requested by: Nate Nowack (@zzstoatzz)

Checklist

  • This pull request references any related issue by including "closes Add support for concurrency grace period #19410"
  • If this pull request adds new functionality, it includes unit tests that cover the changes
  • If this pull request removes docs files, it includes redirect settings in mint.json. (N/A)
  • If this pull request adds functions or classes, it includes helpful docstrings.

@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@github-actions github-actions bot added the enhancement An improvement of an existing feature label Nov 19, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 19, 2025

CodSpeed Performance Report

Merging #19489 will not alter performance

Comparing devin/1763582330-add-deployment-concurrency-grace-period (6dd8a71) with main (63d071d)

Summary

✅ 2 untouched

@devin-ai-integration devin-ai-integration bot changed the title Add client-side configuration for deployment concurrency grace period Add client-side grace period configuration for deployment concurrency Nov 19, 2025
@github-actions github-actions bot added the docs label Dec 1, 2025
@zzstoatzz zzstoatzz force-pushed the devin/1763582330-add-deployment-concurrency-grace-period branch from 38f5016 to 4deadb4 Compare December 1, 2025 21:07
@devin-ai-integration devin-ai-integration bot changed the title Add client-side grace period configuration for deployment concurrency Add client-side configuration for deployment concurrency grace period Dec 1, 2025
@PrefectHQ PrefectHQ deleted a comment from claude bot Dec 2, 2025
@PrefectHQ PrefectHQ deleted a comment from claude bot Dec 2, 2025
@zzstoatzz zzstoatzz force-pushed the devin/1763582330-add-deployment-concurrency-grace-period branch 2 times, most recently from 29ea932 to 4036240 Compare December 3, 2025 20:59
…period

Add `grace_period_seconds` to deployment concurrency options, allowing users
to configure how long infrastructure has to start before concurrency slots
are released. This addresses #19410 and brings OSS feature parity with
Prefect Cloud.

Changes:
- Add `grace_period_seconds` field to `ConcurrencyOptions` (server) and
  `ConcurrencyLimitConfig` (client) schemas with validation (60-86400s)
- Update `SecureFlowConcurrencySlots` orchestration policy to use the
  configured grace period, falling back to server setting when not set
- Add CLI and YAML support for `grace_period_seconds` in deployments
- Add `_extract_concurrency_options` helper to reduce code duplication
- Filter None values from serialized concurrency config

Example usage in prefect.yaml:
```yaml
deployments:
  - name: my-deployment
    concurrency_limit:
      limit: 1
      collision_strategy: ENQUEUE
      grace_period_seconds: 720
```

Closes #19410

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@zzstoatzz zzstoatzz force-pushed the devin/1763582330-add-deployment-concurrency-grace-period branch 2 times, most recently from 9165d40 to 6dd8a71 Compare December 3, 2025 23:04
@zzstoatzz zzstoatzz marked this pull request as ready for review December 4, 2025 17:48
Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

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

LGTM!

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

Labels

docs enhancement An improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants