Skip to content

Add supervisor split service control #1774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 7, 2025
Merged

Conversation

nicktrn
Copy link
Collaborator

@nicktrn nicktrn commented Mar 7, 2025

Also has orchestrator-specific fixes for the workload api domain

Summary by CodeRabbit

  • New Features

    • Enhanced configuration for workload and API settings, allowing separate control over protocol, domain, and port.
    • Introduced options to enable or disable specific session features such as queue processing and notifications.
  • Refactor

    • Streamlined environment variable processing with improved boolean handling and clearer conditional startup behavior.
    • Improved logging and feedback when custom API configurations are detected.

Copy link

changeset-bot bot commented Mar 7, 2025

⚠️ No Changeset found

Latest commit: 94a4ff8

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 Mar 7, 2025

Walkthrough

This pull request refactors environment variable handling and associated configuration across several components. It introduces a new boolean preprocessing schema (BoolEnv) and updates the Env object by removing WORKER_HOST_IP and adding multiple TRIGGER_WORKLOAD_API_* and TRIGGER_DEQUEUE_* fields. The ManagedSupervisor now conditionally starts the workload API server based on these settings. Similar updates apply to the Docker and Kubernetes workload managers, the WorkloadManagerOptions interface, the ManagedRunController, and the SupervisorSession, which now includes options for queue consumer and run notifications along with revised socket management.

Changes

File(s) Change Summary
apps/.../env.ts Introduced BoolEnv preprocessing; removed WORKER_HOST_IP; added TRIGGER_WORKLOAD_API_ENABLED, TRIGGER_WORKLOAD_API_PROTOCOL, TRIGGER_WORKLOAD_API_DOMAIN, TRIGGER_WORKLOAD_API_PORT_INTERNAL, TRIGGER_DEQUEUE_ENABLED, and repositioned TRIGGER_DEQUEUE_INTERVAL_MS.
apps/.../index.ts Updated ManagedSupervisor to initialize new workload API variables and conditionally start the workload server; added properties for session configuration.
apps/.../workloadManager/docker.ts, apps/.../workloadManager/kubernetes.ts Added logging for a custom workload API domain; replaced TRIGGER_WORKER_API_URL with TRIGGER_SUPERVISOR_API_PROTOCOL, TRIGGER_SUPERVISOR_API_PORT, and TRIGGER_SUPERVISOR_API_DOMAIN.
apps/.../workloadManager/types.ts Modified WorkloadManagerOptions by removing workerApiUrl and adding workloadApiProtocol, workloadApiDomain, and workloadApiPort.
packages/cli-v3/.../managed-run-controller.ts Reconstructed workerApiUrl using new environment variables; removed the old TRIGGER_WORKER_API_URL definition to form a more structured URL.
packages/core/.../session.ts Updated SupervisorSession to include queueConsumerEnabled and runNotificationsEnabled options; renamed and adjusted socket management for run notifications.

Sequence Diagram(s)

sequenceDiagram
    participant Env as Environment Variables
    participant MS as ManagedSupervisor
    participant WS as Workload Server
    participant Log as Logger

    MS->>Env: Read TRIGGER_WORKLOAD_API_ENABLED and API config
    alt Workload API Enabled
        MS->>Log: Log protocol, domain, and port
        MS->>WS: Start workload server with new config
    else Workload API Disabled
        MS->>Log: Log warning "workload API disabled"
    end
Loading
sequenceDiagram
    participant Sess as SupervisorSession
    participant RS as RunNotificationsSocket
    participant QC as QueueConsumer

    Sess->>Sess: Read runNotificationsEnabled and queueConsumerEnabled
    alt runNotificationsEnabled
        Sess->>RS: Create run notifications socket
        RS-->>Sess: Socket initialized
    else
        Sess->>Log: Log notifications disabled
    end
    alt queueConsumerEnabled
        Sess->>QC: Initialize queue consumer service
    else
        Sess->>Log: Log consumer disabled
    end
Loading

Possibly related PRs

Poem

I'm a little rabbit, hopping through the code,
New env variables sprout along each road.
I left behind old fields, like WORKER_HOST_IP,
Embraced fresh settings in a structured leap.
Workload APIs now start on conditions so fine,
With protocols, domains, and ports in line.
CodeRabbit cheers—let these changes shine!

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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

Documentation and Community

  • 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: 0

🧹 Nitpick comments (4)
apps/supervisor/src/index.ts (1)

249-258: Conditional workload API server startup

Good addition of a feature toggle with appropriate logging for both enabled and disabled states. This allows for more deployment flexibility.

Consider adding error handling for cases where workload API server fails to start when enabled:

 if (env.TRIGGER_WORKLOAD_API_ENABLED) {
   this.logger.log("[ManagedWorker] Workload API enabled", {
     protocol: env.TRIGGER_WORKLOAD_API_PROTOCOL,
     domain: env.TRIGGER_WORKLOAD_API_DOMAIN,
     port: env.TRIGGER_WORKLOAD_API_PORT_INTERNAL,
   });
-  await this.workloadServer.start();
+  try {
+    await this.workloadServer.start();
+  } catch (error) {
+    this.logger.error("[ManagedWorker] Failed to start Workload API server", { error });
+    // Consider whether to throw or continue with degraded functionality
+  }
 } else {
   this.logger.warn("[ManagedWorker] Workload API disabled");
 }
packages/core/src/v3/runEngineWorker/supervisor/session.ts (1)

37-38: Default values for feature toggles

Setting sensible defaults for the new feature toggles ensures backward compatibility.

Consider moving these defaults to the type definition for improved clarity:

type SupervisorSessionOptions = SupervisorClientCommonOptions & {
-  queueConsumerEnabled?: boolean;
-  runNotificationsEnabled?: boolean;
+  queueConsumerEnabled?: boolean; // defaults to true
+  runNotificationsEnabled?: boolean; // defaults to true
  heartbeatIntervalSeconds?: number;
  dequeueIntervalMs?: number;
  preDequeue?: PreDequeueFn;
  preSkip?: PreSkipFn;
};
apps/supervisor/src/workloadManager/docker.ts (2)

33-35: Environment variable restructuring

Breaking down the previously monolithic TRIGGER_WORKER_API_URL into component parts enhances configurability and aligns with the structure changes elsewhere in the codebase.

The fallback to getDockerHostDomain() is appropriate, but consider adding error handling:

+      // Ensure we have a valid domain for the supervisor API
+      const supervisorDomain = this.opts.workloadApiDomain ?? getDockerHostDomain();
+      if (!supervisorDomain) {
+        this.logger.error("[DockerWorkloadProvider] Failed to determine supervisor domain");
+      }
       `--env=TRIGGER_SUPERVISOR_API_PROTOCOL=${this.opts.workloadApiProtocol}`,
       `--env=TRIGGER_SUPERVISOR_API_PORT=${this.opts.workloadApiPort}`,
-      `--env=TRIGGER_SUPERVISOR_API_DOMAIN=${this.opts.workloadApiDomain ?? getDockerHostDomain()}`,
+      `--env=TRIGGER_SUPERVISOR_API_DOMAIN=${supervisorDomain}`,

56-60: Consider propagating errors in create method

The current implementation logs errors but doesn't propagate them to callers, potentially masking issues.

    try {
      const { stdout, stderr } = await x("docker", runArgs);
      this.logger.debug("[DockerWorkloadProvider] Create succeeded", { stdout, stderr });
    } catch (error) {
      this.logger.error("[DockerWorkloadProvider] Create failed:", { opts, error });
+     throw error; // Propagate the error to allow callers to handle it
    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4dbf11a and 94a4ff8.

📒 Files selected for processing (7)
  • apps/supervisor/src/env.ts (1 hunks)
  • apps/supervisor/src/index.ts (5 hunks)
  • apps/supervisor/src/workloadManager/docker.ts (2 hunks)
  • apps/supervisor/src/workloadManager/kubernetes.ts (2 hunks)
  • apps/supervisor/src/workloadManager/types.ts (1 hunks)
  • packages/cli-v3/src/entryPoints/managed-run-controller.ts (4 hunks)
  • packages/core/src/v3/runEngineWorker/supervisor/session.ts (7 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: units / 🧪 Unit Tests
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (17)
apps/supervisor/src/workloadManager/kubernetes.ts (2)

27-31: Good addition of warning log for custom workload API domain.

This warning message provides useful visibility when a custom domain is being used, helping with debugging and understanding system configuration.


81-100: Environment variable restructuring looks good.

The change from a single API URL to separate environment variables for protocol, port, and domain provides better flexibility. The conditional logic for domain specification is well-implemented, falling back to the pod's host IP when no custom domain is provided.

apps/supervisor/src/workloadManager/types.ts (1)

4-6: Well-structured API configuration interface.

Breaking down the workload API configuration into separate components (protocol, domain, port) is a good design choice that provides more flexibility than a single URL. The comment for workloadApiDomain clearly explains the fallback behavior.

apps/supervisor/src/env.ts (2)

5-11: Good implementation of boolean environment variable parsing.

The BoolEnv preprocessor nicely handles string-to-boolean conversion for environment variables, supporting both "true" and "1" values. This improves type safety and reduces potential runtime errors.


22-34: Well-organized configuration with clear section comments.

The workload API settings are well-structured with appropriate defaults and types. Breaking out the configuration into logical sections with comments makes the code more maintainable. The transformation for TRIGGER_WORKLOAD_API_PROTOCOL ensures valid values.

packages/cli-v3/src/entryPoints/managed-run-controller.ts (3)

39-41: Environment variables properly aligned with other components.

These new environment variables correctly match the refactored approach used in other files, ensuring consistency across the system.


89-89: Appropriate construction of worker API URL from components.

The workerApiUrl is now properly constructed from separate protocol, domain, and port components, which aligns with the configuration changes in other files.

Also applies to: 253-253


755-755: Updated socket creation to use the new URL structure.

The WebSocket URL creation now correctly uses the refactored workerApiUrl property, maintaining consistent connectivity behavior.

apps/supervisor/src/index.ts (4)

32-34: Enhanced configuration modularity introduced

The introduction of separate variables for workload API configuration components (protocol, domain, port) provides more granular control than using a single URL.


45-48: Configuration structure improvement for workload managers

Breaking down the workload API URL into component parts (protocol, domain, port) enhances flexibility and maintainability.

Also applies to: 53-56


66-67: Feature toggles added for supervisor session capabilities

The new properties enable granular control over queue consumption and run notification features, allowing them to be independently enabled/disabled.


191-191: Port naming clarification

Changing from TRIGGER_WORKLOAD_API_PORT to TRIGGER_WORKLOAD_API_PORT_INTERNAL better reflects the purpose of the port and distinguishes it from external-facing configurations.

packages/core/src/v3/runEngineWorker/supervisor/session.ts (4)

14-15: Extended configurability for SupervisorSession

Added optional properties enhance the configurability of the session by allowing specific features to be toggled.


25-28: Socket property refactoring for clarity

Renaming socket to runNotificationsSocket clarifies the purpose of the socket instance, improving code readability.


127-159: Renamed method reflects specific purpose

Renaming createSocket to createRunNotificationsSocket better describes the method's purpose, improving code clarity.


180-193: Feature toggle implementation for session services

The conditional initialization of services based on feature toggles provides deployment flexibility while maintaining appropriate logging.

apps/supervisor/src/workloadManager/docker.ts (1)

14-20: Added logging for custom workload API domain configuration

Good addition of warning logs when custom domain is used, improving observability of non-default configurations.

@nicktrn nicktrn merged commit 38ddd83 into main Mar 7, 2025
6 of 18 checks passed
@nicktrn nicktrn deleted the feat/supervisor-split-controls branch March 7, 2025 12:40
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