Skip to content

perf: reduce deployment targets endpoing response size to reduce memory usage#868

Merged
adityachoudhari26 merged 3 commits intomainfrom
reduce-release-targets-endpoint-response-size
Mar 26, 2026
Merged

perf: reduce deployment targets endpoing response size to reduce memory usage#868
adityachoudhari26 merged 3 commits intomainfrom
reduce-release-targets-endpoint-response-size

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented Mar 26, 2026

Summary by CodeRabbit

  • Refactor
    • Streamlined latestJob in release target APIs and SDK: now includes id, status, createdAt (now mandatory), completedAt (optional), message (optional), metadata (string map) and verifications (array). Removed several less-used job fields to reduce payload and improve consistency across API responses and client schemas.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 517fbc0b-190f-4254-9bd9-b361be82867d

📥 Commits

Reviewing files that changed from the base of the PR and between 1716d87 and 8164382.

📒 Files selected for processing (6)
  • apps/workspace-engine/oapi/openapi.json
  • apps/workspace-engine/oapi/spec/schemas/release_targets.jsonnet
  • apps/workspace-engine/pkg/db/queries/release_targets.sql
  • apps/workspace-engine/pkg/db/release_targets.sql.go
  • apps/workspace-engine/pkg/oapi/oapi.gen.go
  • packages/workspace-engine-sdk/src/schema.ts
💤 Files with no reviewable changes (1)
  • apps/workspace-engine/pkg/db/queries/release_targets.sql
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/workspace-engine-sdk/src/schema.ts
  • apps/workspace-engine/oapi/openapi.json
  • apps/workspace-engine/oapi/spec/schemas/release_targets.jsonnet

📝 Walkthrough

Walkthrough

Refactors ReleaseTargetItem.latestJob into an explicit, narrower inline object across OpenAPI, JSON schema, DB query projections, generated Go types, HTTP getter, and TypeScript SDK — removing many previously exposed job fields and keeping core fields plus metadata and verifications. (50 words)

Changes

Cohort / File(s) Summary
OpenAPI & Schema Definitions
apps/workspace-engine/oapi/openapi.json, apps/workspace-engine/oapi/spec/schemas/release_targets.jsonnet
Replaced allOf composition against Job with an explicit type: "object" schema for latestJob. Defined properties id, status, createdAt, completedAt?, message?, metadata, and verifications; required: id,status,createdAt,metadata,verifications.
Database Layer
apps/workspace-engine/pkg/db/queries/release_targets.sql, apps/workspace-engine/pkg/db/release_targets.sql.go
Reduced SELECT projection in ListLatestJobsByDeploymentID to omit several job columns (reason, started_at, updated_at, external_id, job_agent_id, job_agent_config, dispatch_context). Updated generated Go row struct and Scan to match removed columns.
Generated Go OpenAPI Types
apps/workspace-engine/pkg/oapi/oapi.gen.go
Simplified ReleaseTargetItem.LatestJob anonymous struct: removed many previously included job fields; changed createdAt from *time.Time to time.Time; retained id, status, message, createdAt, completedAt, metadata, and verifications.
HTTP Handler / Getter
apps/workspace-engine/svc/http/server/openapi/release_targets/getters.go
Adjusted PostgresGetter.ListReleaseTargets to construct latestJob payload with the reduced field set (id, status, message, createdAt, metadata, verifications) and reformatted composite key construction logic.
TypeScript SDK
packages/workspace-engine-sdk/src/schema.ts
Changed SDK type for ReleaseTargetItem.latestJob from Job & { verifications: JobVerification[] } to an explicit inline object type matching the new schema (fields: id, status, createdAt, optional completedAt/message, metadata, verifications).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • jsbroks

Poem

🐇 I trimmed the fields, made latestJob neat,

id, status, metadata — now compact and sweet.
Verifications hop along in a row,
Clean schema, clean code — watch the deploys go! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of this PR: reducing the response size of the deployment targets endpoint to improve performance and reduce memory usage by removing unnecessary fields from the latestJob schema.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch reduce-release-targets-endpoint-response-size

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

@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

🧹 Nitpick comments (1)
apps/workspace-engine/svc/http/server/openapi/release_targets/getters.go (1)

158-162: message can stay optional here.

The slimmed payload still writes message for every latestJob, even though the new schema makes that field optional. Building jobH without message by default and only adding it when a message exists would trim the response a bit further.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/workspace-engine/svc/http/server/openapi/release_targets/getters.go`
around lines 158 - 162, The current construction of jobH always includes
"message" even when empty; update the code that builds jobH (the map for lj /
latestJob) to omit the "message" key by default and only set it when
lj.JobMessage is present (e.g., check lj.JobMessage != "" or lj.JobMessage.Valid
/ non-nil depending on the type) so the JSON payload only contains "message"
when there is a value; keep other fields (id, status, metadata, createdAt)
unchanged.
🤖 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/workspace-engine/oapi/spec/schemas/release_targets.jsonnet`:
- Around line 21-38: The change narrows the published contract by replacing the
full Job reference with an inline partial object for latestJob, removing fields
consumers rely on (e.g., startedAt, completedAt); restore the original contract
shape by using allOf with openapi.schemaRef('Job') combined with any additional
constraints instead of redefining properties inline, ensuring latestJob still
exposes the full Job schema (so callers like DeploymentSummaries.tsx that read
latestJob?.completedAt keep working) or explicitly add back every removed Job
field if you truly intend a breaking change and update all consumers
accordingly.

---

Nitpick comments:
In `@apps/workspace-engine/svc/http/server/openapi/release_targets/getters.go`:
- Around line 158-162: The current construction of jobH always includes
"message" even when empty; update the code that builds jobH (the map for lj /
latestJob) to omit the "message" key by default and only set it when
lj.JobMessage is present (e.g., check lj.JobMessage != "" or lj.JobMessage.Valid
/ non-nil depending on the type) so the JSON payload only contains "message"
when there is a value; keep other fields (id, status, metadata, createdAt)
unchanged.
🪄 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: d6045f73-065f-47a7-96ad-eb558b4081b6

📥 Commits

Reviewing files that changed from the base of the PR and between cb1cd84 and 1716d87.

📒 Files selected for processing (7)
  • apps/workspace-engine/oapi/openapi.json
  • apps/workspace-engine/oapi/spec/schemas/release_targets.jsonnet
  • apps/workspace-engine/pkg/db/queries/release_targets.sql
  • apps/workspace-engine/pkg/db/release_targets.sql.go
  • apps/workspace-engine/pkg/oapi/oapi.gen.go
  • apps/workspace-engine/svc/http/server/openapi/release_targets/getters.go
  • packages/workspace-engine-sdk/src/schema.ts
💤 Files with no reviewable changes (1)
  • apps/workspace-engine/pkg/db/queries/release_targets.sql

Comment on lines 21 to +38
latestJob: {
nullable: true,
allOf: [
openapi.schemaRef('Job'),
{
type: 'object',
required: ['id', 'status', 'createdAt', 'metadata', 'verifications'],
properties: {
id: { type: 'string' },
status: openapi.schemaRef('JobStatus'),
message: { type: 'string' },
createdAt: { type: 'string', format: 'date-time' },
metadata: {
type: 'object',
required: ['verifications'],
properties: {
verifications: {
type: 'array',
items: openapi.schemaRef('JobVerification'),
},
},
additionalProperties: { type: 'string' },
},
],
verifications: {
type: 'array',
items: openapi.schemaRef('JobVerification'),
},
},
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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's verify the file exists and check its structure
git ls-files | grep -E "(release_targets|Job)" | head -20

Repository: ctrlplanedev/ctrlplane

Length of output: 897


🏁 Script executed:

# Check the file at the specified location
cat -n "apps/workspace-engine/oapi/spec/schemas/release_targets.jsonnet" | head -50

Repository: ctrlplanedev/ctrlplane

Length of output: 1702


🏁 Script executed:

# Search for Job schema definition
fd -t f "\.jsonnet$" apps/workspace-engine/oapi/spec/schemas/ -x grep -l "Job" {}

Repository: ctrlplanedev/ctrlplane

Length of output: 527


🏁 Script executed:

# Let's examine the Job schema to see what fields it has
cat -n "apps/workspace-engine/oapi/spec/schemas/jobs.jsonnet"

Repository: ctrlplanedev/ctrlplane

Length of output: 6790


🏁 Script executed:

# Check git history to see what latestJob was before this change
cd apps/workspace-engine/oapi/spec/schemas && git log --oneline -20 release_targets.jsonnet

Repository: ctrlplanedev/ctrlplane

Length of output: 78


🏁 Script executed:

# Get the diff for this specific file to see what changed
cd apps/workspace-engine/oapi/spec/schemas && git show HEAD:release_targets.jsonnet 2>/dev/null | head -50 || echo "Cannot get previous version"

Repository: ctrlplanedev/ctrlplane

Length of output: 48


🏁 Script executed:

# Search for references to latestJob in the codebase
rg "latestJob" --type ts --type go --type jsonnet -B2 -A2

Repository: ctrlplanedev/ctrlplane

Length of output: 97


🏁 Script executed:

# Let's search for latestJob references more broadly
rg "latestJob" -A3 -B3

Repository: ctrlplanedev/ctrlplane

Length of output: 49409


🏁 Script executed:

# Check the git diff to see what changed in this file
cd apps/workspace-engine/oapi/spec/schemas && git diff HEAD~1 release_targets.jsonnet 2>/dev/null || git log --all --oneline release_targets.jsonnet | head -10

Repository: ctrlplanedev/ctrlplane

Length of output: 157


🏁 Script executed:

# Let's look at the generated Go types to see if they match
find apps/workspace-engine -name "*.go" -type f | xargs grep -l "ReleaseTargetItem" | head -3

Repository: ctrlplanedev/ctrlplane

Length of output: 108


🏁 Script executed:

# Check if there are TypeScript SDK files generated from these schemas
find apps -name "*.ts" -type f | xargs grep -l "ReleaseTargetItem\|latestJob" | head -5

Repository: ctrlplanedev/ctrlplane

Length of output: 313


🏁 Script executed:

# Let's verify that DeploymentSummaries.tsx actually uses completedAt and would break
grep -n "completedAt" "apps/web/app/routes/ws/environments/_components/DeploymentSummaries.tsx"

Repository: ctrlplanedev/ctrlplane

Length of output: 177


🏁 Script executed:

# Check the git diff for the specific commit to see if this is intentional
cd apps/workspace-engine/oapi/spec/schemas && git show af5f8f12:release_targets.jsonnet | head -50

Repository: ctrlplanedev/ctrlplane

Length of output: 321


🏁 Script executed:

# Check the previous version of the file
cd apps/workspace-engine/oapi/spec/schemas && git show af5f8f12:apps/workspace-engine/oapi/spec/schemas/release_targets.jsonnet | head -50

Repository: ctrlplanedev/ctrlplane

Length of output: 1186


🏁 Script executed:

# Check the current HEAD against the previous commit to see what changed
git diff af5f8f12 HEAD -- apps/workspace-engine/oapi/spec/schemas/release_targets.jsonnet | head -100

Repository: ctrlplanedev/ctrlplane

Length of output: 1484


This narrows a published contract.

latestJob is being changed from a full Job reference to an inline partial object. Previously it used allOf: [openapi.schemaRef('Job'), {...}], but now it explicitly defines only id, status, message, createdAt, metadata, and verifications. This removes access to fields like startedAt, completedAt, updatedAt, jobAgentId, jobAgentConfig, releaseId, workflowJobId, and others.

Existing code already uses removed fields (e.g., DeploymentSummaries.tsx accesses latestJob?.completedAt on line 96), which will break with this schema change. Treat this as an explicit breaking change and verify all consumers are updated, or revert to the allOf approach that preserves the full Job contract.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/workspace-engine/oapi/spec/schemas/release_targets.jsonnet` around lines
21 - 38, The change narrows the published contract by replacing the full Job
reference with an inline partial object for latestJob, removing fields consumers
rely on (e.g., startedAt, completedAt); restore the original contract shape by
using allOf with openapi.schemaRef('Job') combined with any additional
constraints instead of redefining properties inline, ensuring latestJob still
exposes the full Job schema (so callers like DeploymentSummaries.tsx that read
latestJob?.completedAt keep working) or explicitly add back every removed Job
field if you truly intend a breaking change and update all consumers
accordingly.

@adityachoudhari26 adityachoudhari26 merged commit 6d6aa92 into main Mar 26, 2026
11 checks passed
@adityachoudhari26 adityachoudhari26 deleted the reduce-release-targets-endpoint-response-size branch March 26, 2026 19:35
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.

1 participant