Skip to content

Comments

feat(supervisor): add optional memory limit overhead#2506

Merged
nicktrn merged 1 commit intomainfrom
feat/memory-overheads
Sep 15, 2025
Merged

feat(supervisor): add optional memory limit overhead#2506
nicktrn merged 1 commit intomainfrom
feat/memory-overheads

Conversation

@nicktrn
Copy link
Collaborator

@nicktrn nicktrn commented Sep 15, 2025

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)

@changeset-bot
Copy link

changeset-bot bot commented Sep 15, 2025

⚠️ No Changeset found

Latest commit: d2f534f

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 15, 2025

Walkthrough

Adds 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)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description explains the new env var and intent but does not follow the repository's required template: it is missing the "Closes #" line, the checklist, a Testing section with concrete steps, a Changelog entry, and the Screenshots section required by the template. Please update the PR description to match the repository template by adding "Closes #" if applicable, completing the checklist, providing concrete testing steps you ran, adding a short changelog entry, and including screenshots if relevant.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title "feat(supervisor): add optional memory limit overhead" directly and concisely summarizes the primary change—introducing an optional memory overhead for supervisor Kubernetes pod limits—and follows the repository's conventional commit style, making the intent clear to reviewers.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/memory-overheads

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.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

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.

❤️ Share

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

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: 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 like 0.5G won’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_GB to the container for introspection alongside LIMITS_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

📥 Commits

Reviewing files that changed from the base of the PR and between dc42ae7 and d2f534f.

📒 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.ts
  • apps/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)

@nicktrn nicktrn merged commit 7c4ce6f into main Sep 15, 2025
32 checks passed
@nicktrn nicktrn deleted the feat/memory-overheads branch September 15, 2025 15:09
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