Skip to content

Add idle dequeue interval to supervisor #2007

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 3 commits into from
May 1, 2025

Conversation

nicktrn
Copy link
Collaborator

@nicktrn nicktrn commented May 1, 2025

When no results are being returned, we may want to dequeue less frequently.

Summary by CodeRabbit

  • New Features

    • Introduced separate configuration options for active and idle dequeue polling intervals, allowing more responsive and efficient queue processing.
    • Added configurable worker heartbeat interval for improved monitoring and control.
  • Improvements

    • Adjusted default polling intervals for faster queue checks and optimized idle handling.
    • Enhanced flexibility in timing parameters for worker supervision and queue consumption.

Copy link

changeset-bot bot commented May 1, 2025

⚠️ No Changeset found

Latest commit: eceaecb

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.

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 May 1, 2025

Walkthrough

This update introduces new environment variables and configuration options to fine-tune supervisor worker timing, specifically for heartbeat intervals and queue dequeue polling. The environment schema now includes TRIGGER_WORKER_HEARTBEAT_INTERVAL_SECONDS and TRIGGER_DEQUEUE_IDLE_INTERVAL_MS, with adjusted defaults for dequeue intervals. These values are propagated through supervisor session options and into the queue consumer, which now distinguishes between active and idle polling intervals. The queue consumer's logic dynamically adjusts its polling interval based on queue activity, and heartbeat intervals are now explicitly configured.

Changes

File(s) Change Summary
apps/supervisor/src/env.ts Added TRIGGER_WORKER_HEARTBEAT_INTERVAL_SECONDS and TRIGGER_DEQUEUE_IDLE_INTERVAL_MS to environment schema, changed default for TRIGGER_DEQUEUE_INTERVAL_MS from 1000 to 250.
apps/supervisor/src/index.ts Passed new environment variables (dequeueIdleIntervalMs, heartbeatIntervalSeconds) to SupervisorSession initialization in ManagedSupervisor.
packages/core/src/v3/runEngineWorker/supervisor/queueConsumer.ts Updated RunQueueConsumerOptions to require intervalMs and new idleIntervalMs; adjusted logic to use different intervals for active vs idle polling; changed scheduleNextDequeue to require explicit delay.
packages/core/src/v3/runEngineWorker/supervisor/session.ts Updated SupervisorSessionOptions to require heartbeatIntervalSeconds, dequeueIntervalMs, and new dequeueIdleIntervalMs; removed fallback defaults; passed new options to RunQueueConsumer.

Sequence Diagram(s)

sequenceDiagram
    participant Env as Environment
    participant ManagedSupervisor
    participant SupervisorSession
    participant RunQueueConsumer

    Env->>ManagedSupervisor: Provide config vars (intervals, heartbeat)
    ManagedSupervisor->>SupervisorSession: Initialize with intervals & heartbeat
    SupervisorSession->>RunQueueConsumer: Initialize with intervalMs & idleIntervalMs
    RunQueueConsumer->>RunQueueConsumer: On dequeue()
    alt Queue has work
        RunQueueConsumer->>RunQueueConsumer: scheduleNextDequeue(intervalMs)
    else Queue idle or skipping
        RunQueueConsumer->>RunQueueConsumer: scheduleNextDequeue(idleIntervalMs)
    end
    SupervisorSession->>SupervisorSession: Heartbeat at heartbeatIntervalSeconds
Loading

Poem

In the warren, timers tick and spin,
Heartbeats thump as queues begin.
Idle or busy, the intervals dance—
Now finely tuned for every chance.
Rabbits rejoice, the code’s more spry,
With every hop, the bugs say bye!
🐇⏱️


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cb47200 and eceaecb.

📒 Files selected for processing (4)
  • apps/supervisor/src/env.ts (2 hunks)
  • apps/supervisor/src/index.ts (1 hunks)
  • packages/core/src/v3/runEngineWorker/supervisor/queueConsumer.ts (5 hunks)
  • packages/core/src/v3/runEngineWorker/supervisor/session.ts (3 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 (14)
apps/supervisor/src/index.ts (2)

119-119: Adding idle dequeue interval is a good optimization.

This change supports dynamic adjustment of dequeue frequency. When the queue is inactive, the system will poll less frequently, reducing unnecessary resource usage.


124-124: Explicit heartbeat interval configuration adds flexibility.

Making the heartbeat interval configurable allows for fine-tuning the supervisor's communication frequency with the worker platform.

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

9-9: Good addition of heartbeat interval configuration.

Adding a configurable heartbeat interval allows system administrators to adjust communication frequency based on their specific needs.


35-36: Improved dequeue interval configuration.

These changes optimize the system by:

  1. Decreasing the active dequeue interval from 1000ms to 250ms for faster response during active periods
  2. Adding a separate idle interval of 1000ms for more conservative polling when inactive

This should improve both responsiveness and efficiency.

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

16-19: Properly enforcing required configuration parameters.

Making these parameters required ensures proper configuration of the supervisor session. This is a good practice to prevent misconfigurations and runtime errors.


50-50: Passing idle interval to queue consumer.

Correctly propagating the idle interval to the queue consumer enables the dynamic polling behavior.


66-66: Setting explicit heartbeat interval.

Using the configured heartbeat interval directly ensures consistent behavior across the system.

packages/core/src/v3/runEngineWorker/supervisor/queueConsumer.ts (7)

7-8: Making interval parameters required.

Enforcing both active and idle intervals as required parameters prevents configuration errors and makes the API more explicit.


22-23: Added idle interval as a class property.

Storing both intervals as instance variables enables dynamic switching between them.


28-29: Properly initializing interval properties.

Properly assigns both interval values from constructor options, maintaining clear initialization patterns.


90-90: Using idle interval for skipped dequeues.

Correctly uses the idle interval when dequeuing is skipped due to resource constraints or other conditions.


93-94: Intelligent interval selection logic.

This is the core of the optimization feature:

  1. Starts with the idle interval as the default
  2. Switches to the active interval when work is found
  3. Dynamically adapts to workload patterns

This implementation will reduce unnecessary polling during quiet periods while maintaining responsiveness during active periods.

Also applies to: 107-109


118-118: Applying dynamic interval for next dequeue.

Using the dynamically selected interval for scheduling ensures the optimization is properly applied.


121-122: Improved method signature for scheduleNextDequeue.

Making the delay parameter required improves type safety and code clarity by removing implicit defaults.

✨ 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.

Support

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

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@nicktrn nicktrn merged commit 0df7af4 into main May 1, 2025
13 checks passed
@nicktrn nicktrn deleted the feat/supervisor-dequeue-idle-interval branch May 1, 2025 09:53
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