Skip to content

Conversation

rharkor
Copy link
Contributor

@rharkor rharkor commented Sep 2, 2025

✅ Checklist

  • I have followed every step in the contributing guide
  • The PR title follows the convention.
  • I ran and tested the code works

Testing

I deployed a built version of the webapp, supervisor into a public registry and tried it in my cluster.

Webapp: public.ecr.aws/n5q7l0s4/trigger-supervisor:latest
Supervisor: public.ecr.aws/n5q7l0s4/trigger-webapp:latest


Changelog

You can now add memory/cpu request specification to the machine override which allows you ton control request and limit independently for kubernetes.

💯

Copy link

changeset-bot bot commented Sep 2, 2025

⚠️ No Changeset found

Latest commit: 5e8188b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Sep 2, 2025

Walkthrough

Adds optional cpuRequest and memoryRequest fields to MachinePreset and machine override schemas. Updates Kubernetes resource request calculations in kubernetes-provider and supervisor to use these overrides when provided, falling back to previous defaults (CPU: cpu*0.75; Memory: memory) and formatting as strings with “G” for memory. Webapp validation (Zod) now accepts these override fields. Documentation updated to describe per-machine Kubernetes “requests,” include warnings about zero values, and provide a JSON example. No public API signatures change beyond the expanded MachinePreset schema types.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/core/src/v3/schemas/common.ts (1)

117-126: Validate cpuRequest/memoryRequest at the schema layer (non-negative and ≤ limits)

Prevents K8s admission errors when requests exceed limits and guards against negative values.

-export const MachinePreset = z.object({
-  name: MachinePresetName,
-  /** unit: vCPU */
-  cpu: z.number(),
-  cpuRequest: z.number().optional(), // Only used for k8s fallback to cpu
-  /** unit: GB */
-  memory: z.number(),
-  memoryRequest: z.number().optional(), // Only used for k8s fallback to memory
-  centsPerMs: z.number(),
-});
+export const MachinePreset = z
+  .object({
+    name: MachinePresetName,
+    /** unit: vCPU */
+    cpu: z.number(),
+    // Used for Kubernetes resource requests when provided; runtime falls back if undefined
+    cpuRequest: z.number().nonnegative().optional(),
+    /** unit: GB */
+    memory: z.number(),
+    // Used for Kubernetes resource requests when provided; runtime falls back if undefined
+    memoryRequest: z.number().nonnegative().optional(),
+    centsPerMs: z.number(),
+  })
+  .refine((p) => p.cpuRequest === undefined || p.cpuRequest <= p.cpu, {
+    path: ["cpuRequest"],
+    message: "cpuRequest must be <= cpu",
+  })
+  .refine((p) => p.memoryRequest === undefined || p.memoryRequest <= p.memory, {
+    path: ["memoryRequest"],
+    message: "memoryRequest must be <= memory",
+  });
🧹 Nitpick comments (3)
docs/self-hosting/overview.mdx (1)

94-104: Clarify defaults and enforce "requests ≤ limits" guidance

Add explicit defaults and the limit constraint to prevent misconfiguration.

-You can also set cpu/memory requests for each machine type. This is used in k8s environments to set the minimum resources required for each machine type.
-We do not recommend setting these values to zero, as it can cause the k8s scheduler to schedule an infinite number of pods in parallel and cause the pods to get killed due to resource exhaustion.
+You can also set cpu/memory requests for each machine type. This is used in k8s environments to set the minimum resources required for each machine type. If omitted, CPU request defaults to 75% of the machine's cpu, and memory request defaults to the machine's memory.
+Requests must be less than or equal to their corresponding limits (cpu and memory); otherwise, the pod will be rejected by Kubernetes. We do not recommend setting these values to zero, as it can lead to aggressive over‑scheduling and OOM evictions.
apps/supervisor/src/workloadManager/kubernetes.ts (1)

297-302: Deduplicate resource-request logic with kubernetes-provider

The same calculation exists in two places and is easy to drift. Consider a shared utility in a common package (e.g., @trigger.dev/core/v3/serverOnly) to format requests/limits from MachinePreset.

apps/webapp/app/services/platform.v3.server.ts (1)

81-86: Basic validation: requests should be non-negative; clarify comments

Local validation reduces bad configs before they reach core/provider.

 const MachineOverrideValues = z.object({
   cpu: z.number(),
-  cpuRequest: z.number().optional(), // Only used for k8s fallback to cpu
+  // Used for Kubernetes resource requests when provided
+  cpuRequest: z.number().nonnegative().optional(),
   memory: z.number(),
-  memoryRequest: z.number().optional(), // Only used for k8s fallback to memory
+  // Used for Kubernetes resource requests when provided
+  memoryRequest: z.number().nonnegative().optional(),
 });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 436d951 and 5e8188b.

📒 Files selected for processing (5)
  • apps/kubernetes-provider/src/index.ts (1 hunks)
  • apps/supervisor/src/workloadManager/kubernetes.ts (1 hunks)
  • apps/webapp/app/services/platform.v3.server.ts (1 hunks)
  • docs/self-hosting/overview.mdx (1 hunks)
  • packages/core/src/v3/schemas/common.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Always prefer using isomorphic code like fetch, ReadableStream, etc. instead of Node.js specific code
For TypeScript, we usually use types over interfaces
Avoid enums
No default exports, use function declarations

Files:

  • packages/core/src/v3/schemas/common.ts
  • apps/kubernetes-provider/src/index.ts
  • apps/supervisor/src/workloadManager/kubernetes.ts
  • apps/webapp/app/services/platform.v3.server.ts
{packages/core,apps/webapp}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

We use zod a lot in packages/core and in the webapp

Files:

  • packages/core/src/v3/schemas/common.ts
  • apps/webapp/app/services/platform.v3.server.ts
apps/webapp/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/webapp.mdc)

When importing from @trigger.dev/core in the webapp, never import the root package path; always use one of the documented subpath exports from @trigger.dev/core’s package.json

Files:

  • apps/webapp/app/services/platform.v3.server.ts
{apps/webapp/app/**/*.server.{ts,tsx},apps/webapp/app/routes/**/*.ts}

📄 CodeRabbit inference engine (.cursor/rules/webapp.mdc)

Access environment variables only via the env export from app/env.server.ts; do not reference process.env directly

Files:

  • apps/webapp/app/services/platform.v3.server.ts
apps/webapp/app/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/webapp.mdc)

Modules intended for test consumption under apps/webapp/app/**/*.ts must not read environment variables; accept configuration via options instead

Files:

  • apps/webapp/app/services/platform.v3.server.ts
🧠 Learnings (1)
📚 Learning: 2025-01-13T18:31:48.160Z
Learnt from: nicktrn
PR: triggerdotdev/trigger.dev#1608
File: apps/webapp/app/v3/services/triggerTask.server.ts:418-418
Timestamp: 2025-01-13T18:31:48.160Z
Learning: The `MachinePresetName` schema is used to validate machine preset values in the trigger.dev codebase, ensuring type safety and validation of machine preset options.

Applied to files:

  • packages/core/src/v3/schemas/common.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (22)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
  • GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: typecheck / typecheck

Comment on lines 546 to 551
#getResourceRequestsForMachine(preset: MachinePreset): ResourceQuantities {
return {
cpu: `${preset.cpu * 0.75}`,
memory: `${preset.memory}G`,
cpu: `${preset.cpuRequest ?? preset.cpu * 0.75}`,
memory: `${preset.memoryRequest ?? preset.memory}G`,
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Clamp requests to limits (mirror supervisor change)

Prevents admission failures when overrides set requests above limits.

   #getResourceRequestsForMachine(preset: MachinePreset): ResourceQuantities {
-    return {
-      cpu: `${preset.cpuRequest ?? preset.cpu * 0.75}`,
-      memory: `${preset.memoryRequest ?? preset.memory}G`,
-    };
+    const cpuReq = Math.min(Math.max(0, preset.cpuRequest ?? preset.cpu * 0.75), preset.cpu);
+    const memReq = Math.min(Math.max(0, preset.memoryRequest ?? preset.memory), preset.memory);
+    return {
+      cpu: `${cpuReq}`,
+      memory: `${memReq}G`,
+    };
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#getResourceRequestsForMachine(preset: MachinePreset): ResourceQuantities {
return {
cpu: `${preset.cpu * 0.75}`,
memory: `${preset.memory}G`,
cpu: `${preset.cpuRequest ?? preset.cpu * 0.75}`,
memory: `${preset.memoryRequest ?? preset.memory}G`,
};
}
#getResourceRequestsForMachine(preset: MachinePreset): ResourceQuantities {
const cpuReq = Math.min(
Math.max(0, preset.cpuRequest ?? preset.cpu * 0.75),
preset.cpu
);
const memReq = Math.min(
Math.max(0, preset.memoryRequest ?? preset.memory),
preset.memory
);
return {
cpu: `${cpuReq}`,
memory: `${memReq}G`,
};
}
🤖 Prompt for AI Agents
In apps/kubernetes-provider/src/index.ts around lines 546 to 551, the method
computing resource requests currently returns values that may exceed preset
limits; update it to clamp the computed cpu and memory requests to the
corresponding limits (e.g. cpuLimit and memoryLimit) so requests never exceed
limits. Compute cpuReq = min(preset.cpuRequest ?? preset.cpu * 0.75,
preset.cpuLimit ?? Infinity) and memoryReq = min(numeric(preset.memoryRequest ??
preset.memory), preset.memoryLimit ?? Infinity) then format cpu as string and
memory with trailing "G"; return those clamped values.

Comment on lines 297 to 302
#getResourceRequestsForMachine(preset: MachinePreset): ResourceQuantities {
return {
cpu: `${preset.cpu * 0.75}`,
memory: `${preset.memory}G`,
cpu: `${preset.cpuRequest ?? preset.cpu * 0.75}`,
memory: `${preset.memoryRequest ?? preset.memory}G`,
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Clamp requests to limits to avoid K8s 400s on misconfiguration

Even with schema checks, defensive clamping avoids failed pod creations when overrides drift or come from older configs.

   #getResourceRequestsForMachine(preset: MachinePreset): ResourceQuantities {
-    return {
-      cpu: `${preset.cpuRequest ?? preset.cpu * 0.75}`,
-      memory: `${preset.memoryRequest ?? preset.memory}G`,
-    };
+    const cpuReq = Math.min(Math.max(0, preset.cpuRequest ?? preset.cpu * 0.75), preset.cpu);
+    const memReq = Math.min(Math.max(0, preset.memoryRequest ?? preset.memory), preset.memory);
+    return {
+      cpu: `${cpuReq}`,
+      memory: `${memReq}G`,
+    };
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#getResourceRequestsForMachine(preset: MachinePreset): ResourceQuantities {
return {
cpu: `${preset.cpu * 0.75}`,
memory: `${preset.memory}G`,
cpu: `${preset.cpuRequest ?? preset.cpu * 0.75}`,
memory: `${preset.memoryRequest ?? preset.memory}G`,
};
}
#getResourceRequestsForMachine(preset: MachinePreset): ResourceQuantities {
const cpuReq = Math.min(Math.max(0, preset.cpuRequest ?? preset.cpu * 0.75), preset.cpu);
const memReq = Math.min(Math.max(0, preset.memoryRequest ?? preset.memory), preset.memory);
return {
cpu: `${cpuReq}`,
memory: `${memReq}G`,
};
}

@nicktrn
Copy link
Collaborator

nicktrn commented Sep 3, 2025

Thanks again @rharkor, will close this for now in favor of #2474 but happy to revisit at some point!

@nicktrn nicktrn closed this Sep 3, 2025
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