feat(supervisor): add optional memory limit overhead#2506
Conversation
|
WalkthroughAdds an optional environment variable KUBERNETES_MEMORY_OVERHEAD_GB to the supervisor’s Env schema (non-negative number, optional). In the Kubernetes workload manager, a new private field reads this value from env. When computing resource limits for a machine, the memory limit is set to preset.memory plus the configured overhead if provided; otherwise it remains preset.memory. Resource requests logic is unchanged. No public APIs are modified. Changes are confined to env schema and Kubernetes resource limit calculation. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Two files touched with a straightforward env plumbing and a small conditional in memory limit calculation; low heterogeneity and limited logic changes. Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
apps/supervisor/src/workloadManager/kubernetes.ts (2)
28-28: Use nullish coalescing to avoid truthiness pitfalls and simplify logic.This makes intent explicit and avoids edge cases if 0 is passed explicitly (still fine today, but clearer).
- private readonly memoryOverheadGb = env.KUBERNETES_MEMORY_OVERHEAD_GB; + private readonly memoryOverheadGb = env.KUBERNETES_MEMORY_OVERHEAD_GB ?? 0;
323-326: Memory limit calc is correct; tighten expression and double‑check units/requests intent.
- Minor tidy: compute in one expression.
- Units: you’re emitting
${...}G. That’s consistent with existing code, but please confirm decimals like0.5Gwon’t trip K8s parsing. If uncertain, consider rounding or using Mi.- Intent check: requests remain based on preset (not including overhead) while limits include overhead. If the goal is “safety cushion” above the app’s own memory target, this is correct. Please confirm this is desired to avoid over‑requesting cluster capacity.
- const memoryLimit = this.memoryOverheadGb - ? preset.memory + this.memoryOverheadGb - : preset.memory; + const memoryLimit = preset.memory + (this.memoryOverheadGb ?? 0);Optional follow-ups (no blocker):
- Emit a debug log when overhead > 0 to aid ops (“applying X GB memory overhead; limit YG, request ZG”).
- Consider passing an explicit env var like
TRIGGER_MEMORY_OVERHEAD_GBto the container for introspection alongsideLIMITS_MEMORY.Also applies to: 329-329
apps/supervisor/src/env.ts (1)
92-92: Clarify unit semantics — avoid relying on ambiguous "0.5G".Kubernetes accepts fixed‑point quantities like "0.5G", but that is decimal (0.5G = 500,000,000 bytes) and can be ambiguous vs binary (Gi). If you mean half a gibibyte use 512Mi. Choose one:
- Option A — keep decimals: keep
z.coerce.number().min(0).optional()but DOCUMENT the unit (decimal GB vs Gi) and ensure downstream converts the float into a canonical k8s quantity (e.g., emit "512Mi" if you intend Gi).- Option B — require integers: change to
.int()and accept/emit explicit Mi/Gi integers to remove ambiguity (or rename var to indicate unit).Location: apps/supervisor/src/env.ts:92
KUBERNETES_MEMORY_OVERHEAD_GB: z.coerce.number().min(0).optional(), // Optional memory overhead to add to the limit in GB
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/supervisor/src/env.ts(1 hunks)apps/supervisor/src/workloadManager/kubernetes.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{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:
apps/supervisor/src/env.tsapps/supervisor/src/workloadManager/kubernetes.ts
🧬 Code graph analysis (1)
apps/supervisor/src/workloadManager/kubernetes.ts (1)
apps/supervisor/src/env.ts (1)
env(118-118)
⏰ 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). (23)
- GitHub Check: build (supervisor)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
- GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 8)
- GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
- GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 8)
- GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
- GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
- GitHub Check: typecheck / typecheck
- GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
- GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
- GitHub Check: Analyze (javascript-typescript)
This provides flexibility for workloads that require extra memory headroom for system processes or similar.
New env vars
KUBERNETES_MEMORY_OVERHEAD_GB- Optional memory overhead in GB to add to pod memory limits (no default, when unset no overhead is applied)