Skip to content

fix: dont retrieve stale target states#1099

Merged
adityachoudhari26 merged 2 commits intomainfrom
dont-retreieve-stale-targets
May 4, 2026
Merged

fix: dont retrieve stale target states#1099
adityachoudhari26 merged 2 commits intomainfrom
dont-retreieve-stale-targets

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented May 4, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Fixed release target data retrieval to correctly filter by deployment and environment resources.

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

coderabbitai Bot commented May 4, 2026

Warning

Rate limit exceeded

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

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ 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: 206849c0-f91b-4e4b-88a2-eb42f1801a79

📥 Commits

Reviewing files that changed from the base of the PR and between 8420d61 and 55b05cb.

📒 Files selected for processing (1)
  • apps/api/src/routes/v1/workspaces/release-targets.ts
📝 Walkthrough

Walkthrough

The getReleaseTargetStates query in the release-targets API endpoint now filters release target desired releases by joining through computed deployment and environment resources, and explicitly selects resourceId, environmentId, and deploymentId instead of all columns from the base table.

Changes

Release Target Query Filtering

Layer / File(s) Summary
Query Logic
apps/api/src/routes/v1/workspaces/release-targets.ts
getReleaseTargetStates adds deploymentMatch and environmentMatch computed predicates, then performs innerJoin operations from schema.releaseTargetDesiredRelease to schema.computedDeploymentResource and schema.computedEnvironmentResource, filtering and projecting only resourceId, environmentId, and deploymentId.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 A query hops through computed fields so bright,
Joining resources left and right,
Release targets now precisely flow,
Three IDs selected, ready to go!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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: preventing retrieval of stale target states through improved query filtering logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 dont-retreieve-stale-targets

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
Review rate limit: 0/1 reviews remaining, refill in 34 minutes and 15 seconds.

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/api/src/routes/v1/workspaces/release-targets.ts`:
- Around line 286-297: The query building releaseTargets uses limit/offset
without deterministic ordering; update the db query that selects from
schema.releaseTargetDesiredRelease (the call that assigns releaseTargets) to add
an orderBy clause (e.g., order by schema.releaseTargetDesiredRelease.resourceId,
and optionally environmentId/deploymentId) so pagination is stable and rows
won’t shift between pages; ensure the orderBy is applied before limit/offset in
the query chain.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8cd99f79-4479-4073-86b0-1b12a633cdac

📥 Commits

Reviewing files that changed from the base of the PR and between 40c184e and 8420d61.

📒 Files selected for processing (1)
  • apps/api/src/routes/v1/workspaces/release-targets.ts

Comment thread apps/api/src/routes/v1/workspaces/release-targets.ts
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

This PR updates the API endpoint that lists release-target states to avoid returning states for “stale” release targets by ensuring the requested (deployment, environment, resource) triple still exists in the computed selector results.

Changes:

  • Filters release_target_desired_release rows by inner-joining against computed_deployment_resource and computed_environment_resource.
  • Narrows the selected columns for the paginated query to the release-target key fields (resourceId/environmentId/deploymentId).

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

.from(schema.releaseTargetDesiredRelease)
.innerJoin(schema.computedDeploymentResource, deploymentMatch)
.innerJoin(schema.computedEnvironmentResource, environmentMatch)
.where(filter)
Comment on lines 250 to 282
const filter = and(
eq(schema.releaseTargetDesiredRelease.deploymentId, deploymentId),
eq(schema.releaseTargetDesiredRelease.environmentId, environmentId),
);

const deploymentMatch = and(
eq(
schema.computedDeploymentResource.deploymentId,
schema.releaseTargetDesiredRelease.deploymentId,
),
eq(
schema.computedDeploymentResource.resourceId,
schema.releaseTargetDesiredRelease.resourceId,
),
);

const environmentMatch = and(
eq(
schema.computedEnvironmentResource.environmentId,
schema.releaseTargetDesiredRelease.environmentId,
),
eq(
schema.computedEnvironmentResource.resourceId,
schema.releaseTargetDesiredRelease.resourceId,
),
);

const [countResult] = await db
.select({ total: count() })
.from(schema.releaseTargetDesiredRelease)
.innerJoin(schema.computedDeploymentResource, deploymentMatch)
.innerJoin(schema.computedEnvironmentResource, environmentMatch)
.where(filter);
@adityachoudhari26 adityachoudhari26 merged commit 368f930 into main May 4, 2026
9 checks passed
@adityachoudhari26 adityachoudhari26 deleted the dont-retreieve-stale-targets branch May 4, 2026 15:03
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.

2 participants