Skip to content

fix: if candidate version is already rolled out gradual rollout evaluator short circuits#1116

Merged
adityachoudhari26 merged 3 commits into
mainfrom
grad-rollout-same-version-short-circuit
May 11, 2026
Merged

fix: if candidate version is already rolled out gradual rollout evaluator short circuits#1116
adityachoudhari26 merged 3 commits into
mainfrom
grad-rollout-same-version-short-circuit

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented May 11, 2026

Summary by CodeRabbit

  • New Features
    • Gradual rollout policy now immediately allows resources already deployed to the target version, bypassing timing constraints for improved deployment efficiency.

Review Change Stack

Copilot AI review requested due to automatic review settings May 11, 2026 14:36
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 11, 2026

Warning

Rate limit exceeded

@adityachoudhari26 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 24 minutes and 19 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c42541be-99cb-4b00-8a8b-f9af12bbc54b

📥 Commits

Reviewing files that changed from the base of the PR and between a04230b and 4638db1.

📒 Files selected for processing (4)
  • apps/workspace-engine/pkg/db/queries/releases.sql
  • apps/workspace-engine/pkg/db/releases.sql.go
  • apps/workspace-engine/pkg/workspace/releasemanager/policy/evaluator/gradualrollout/getters.go
  • apps/workspace-engine/pkg/workspace/releasemanager/policy/evaluator/gradualrollout/gradualrollout_test.go
📝 Walkthrough

Walkthrough

This PR adds a version check capability to the gradual rollout evaluator. When evaluating whether a resource should be updated, the system now checks if the resource is already deployed on the candidate version; if so, it immediately allows the update without consulting the rollout curve timing gates.

Changes

Version Check Short-Circuit for Gradual Rollout

Layer / File(s) Summary
Interface & Helper Definition
apps/workspace-engine/pkg/workspace/releasemanager/policy/evaluator/gradualrollout/getters.go
Imports adjusted to add errors and pgx support. Introduces parseReleaseTargetUUIDs helper to parse ResourceId, EnvironmentId, and DeploymentId with consistent wrapped error messages. Extends Getters interface with GetCurrentVersionID(ctx, releaseTarget) (*string, error) method.
PostgresGetters Implementation
apps/workspace-engine/pkg/workspace/releasemanager/policy/evaluator/gradualrollout/getters.go
Implements PostgresGetters.GetCurrentVersionID to retrieve the current release from the database, returning nil, nil when no rows exist, otherwise returning the version ID. Refactors HasCurrentRelease to use the shared parseReleaseTargetUUIDs helper instead of duplicating UUID parsing logic.
GradualRollout Evaluation Logic
apps/workspace-engine/pkg/workspace/releasemanager/policy/evaluator/gradualrollout/gradualrollout.go
Evaluate now calls GetCurrentVersionID at the start; if the resource is already on the candidate version, returns an allowed result immediately, short-circuiting release-target fetching and rollout curve calculations. Errors in fetching the version ID return a denied result.
Test Coverage & Mocks
apps/workspace-engine/pkg/workspace/releasemanager/policy/evaluator/gradualrollout/gradualrollout_test.go, apps/workspace-engine/svc/controllers/desiredrelease/policyeval/policyeval_test.go, apps/workspace-engine/svc/controllers/desiredrelease/reconcile_test.go, apps/workspace-engine/test/controllers/harness/mocks.go
Updates mockGetters with currentVersionID field and GetCurrentVersionID method to control test version state. Adds three new unit tests: (1) resource already on candidate version bypasses curve gating, (2) resource on different version still respects curve, (3) resource with no current version still respects curve. All other test mocks (policyeval_test, reconcile_test, harness/mocks) implement GetCurrentVersionID returning nil, nil. DesiredReleaseGetter mock adds CurrentVersionID field and optional CurrentVersionIDFn callback for flexible test configuration.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • ctrlplanedev/ctrlplane#706: Introduced the gradual rollout evaluator; this PR extends it with early version matching to skip curve gating when already on candidate version.

Suggested reviewers

  • jsbroks

Poem

🐰 A version check hops swiftly by,
No curve delays if we're close and nigh—
Already deployed? Then straight we go,
No waiting for the rollout flow! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a short-circuit optimization to the gradual rollout evaluator when a candidate version is already deployed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch grad-rollout-same-version-short-circuit

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an edge case in the workspace-engine gradual rollout policy evaluator where evaluating a candidate version against a release target that is already deployed on that version could return Pending (due to curve position) and trigger an unintended rollback to an older version during desired-release reconciliation.

Changes:

  • Add GetCurrentVersionID(...) to the gradual rollout getters interface and implement it in the Postgres-backed getters.
  • Short-circuit GradualRolloutEvaluator.Evaluate to Allowed when the current deployed version equals the candidate version.
  • Update controller/test mocks and add targeted tests covering the already-on-version behavior and ensuring normal curve gating still applies otherwise.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
apps/workspace-engine/test/controllers/harness/mocks.go Extends desiredrelease test harness getter to support GetCurrentVersionID.
apps/workspace-engine/svc/controllers/desiredrelease/reconcile_test.go Updates reconcile test mock to satisfy new getter interface method.
apps/workspace-engine/svc/controllers/desiredrelease/policyeval/policyeval_test.go Updates policy-eval test mock to satisfy new getter interface method.
apps/workspace-engine/pkg/workspace/releasemanager/policy/evaluator/gradualrollout/gradualrollout.go Adds “already on candidate version” short-circuit to prevent rollback behavior.
apps/workspace-engine/pkg/workspace/releasemanager/policy/evaluator/gradualrollout/gradualrollout_test.go Adds tests for the new short-circuit behavior (and non-short-circuit cases).
apps/workspace-engine/pkg/workspace/releasemanager/policy/evaluator/gradualrollout/getters.go Introduces GetCurrentVersionID in interface + Postgres implementation (using existing current-release query).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +129 to +133
row, err := p.queries.GetCurrentReleaseByReleaseTarget(
ctx,
db.GetCurrentReleaseByReleaseTargetParams{
ResourceID: resourceID,
EnvironmentID: environmentID,
Comment on lines +360 to +364
currentVersionID, err := e.getters.GetCurrentVersionID(ctx, releaseTarget)
if err != nil {
return results.
NewDeniedResult(fmt.Sprintf("Failed to get current version: %v", err)).
WithDetail("error", err.Error())
Comment on lines +1461 to +1462
// Pretend the resource at position 4 (whose curve slot is at t+240s) is
// already on this version because it advanced during an override.
}
return resourceID, environmentID, deploymentID, nil
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is just a nit, but this seems like a data clump, it might read nicer to have an object like, but this is also fine

type ReleaseTargetIDs struct {
    EnvironmentID    uuid.UUID
    ResourceID       uuid.UUID
    DeploymentID     uuid.UUID
}

@adityachoudhari26 adityachoudhari26 merged commit eba2906 into main May 11, 2026
@adityachoudhari26 adityachoudhari26 deleted the grad-rollout-same-version-short-circuit branch May 11, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants