Skip to content

More v1 run engine fixes #1644

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
Jan 28, 2025
Merged

More v1 run engine fixes #1644

merged 3 commits into from
Jan 28, 2025

Conversation

ericallam
Copy link
Member

@ericallam ericallam commented Jan 28, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Added configuration options for MARQS queue management
      • Introduced MARQS_REUSE_SNAPSHOT_COUNT to control snapshot reuse
      • Added MARQS_MAXIMUM_ORG_COUNT to limit organization selection in queue processing
  • Improvements

    • Enhanced fair dequeuing strategy with more flexible queue distribution
    • Improved performance by implementing snapshot reuse mechanism
  • Testing

    • Added comprehensive test coverage for new queue management features
    • Verified snapshot reuse and organization selection behaviors

Copy link

changeset-bot bot commented Jan 28, 2025

⚠️ No Changeset found

Latest commit: 772150c

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 Jan 28, 2025

Walkthrough

This pull request introduces new configuration options for the MARQS (Message Queue Routing and Queuing System) in the web application. Two new environment variables, MARQS_REUSE_SNAPSHOT_COUNT and MARQS_MAXIMUM_ORG_COUNT, are added to the environment schema. These changes enhance the FairDequeuingStrategy by allowing more granular control over snapshot reuse and organization-level queue distribution. The modifications include updates to the environment configuration, queue distribution logic, and corresponding test cases to validate the new functionality.

Changes

File Change Summary
apps/webapp/app/env.server.ts Added two new environment properties: MARQS_REUSE_SNAPSHOT_COUNT (default 0) and MARQS_MAXIMUM_ORG_COUNT (optional)
apps/webapp/app/v3/marqs/fairDequeuingStrategy.server.ts Updated FairDequeuingStrategyOptions with new optional properties, added #selectTopOrgs method for organization selection
apps/webapp/app/v3/marqs/index.server.ts Configured FairDequeuingStrategy instances with new reuseSnapshotCount and maximumOrgCount properties
apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts Removed socket-related code in #handleResumeMessage method
apps/webapp/test/fairDequeuingStrategy.test.ts Added two new test cases for snapshot reuse and organization count selection

Sequence Diagram

sequenceDiagram
    participant Env as Environment Config
    participant Strategy as FairDequeuingStrategy
    participant Queue as Message Queues

    Env->>Strategy: Configure reuseSnapshotCount
    Env->>Strategy: Configure maximumOrgCount
    Strategy->>Queue: Create Initial Queue Snapshot
    Strategy->>Strategy: Check Snapshot Reuse Limit
    Strategy->>Strategy: Select Top Organizations
    Strategy->>Queue: Distribute Queues
Loading

Possibly related PRs

Suggested reviewers

  • matt-aitken

Poem

🐰 Queues dancing with grace and might,
MARQS strategy shining bright,
Snapshots reused, orgs in line,
Efficiency's new design divine!
Hop along, code rabbit's delight! 🚀

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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: 1

🧹 Nitpick comments (3)
apps/webapp/app/v3/marqs/fairDequeuingStrategy.server.ts (2)

47-48: Consider documenting how these new optional properties are intended to be used.
They look appropriate, but adding clearer doc comments or inline explanations on the usage and defaults (especially for maximumOrgCount) would help future maintainers.


319-340: Add or note an expiration mechanism if outdated snapshots pose a risk.
The logic correctly checks reuseCount against reuseSnapshotCount, but stale snapshots could accumulate if the queue changes drastically. As a follow-up, consider time-based validation or periodic clearing to ensure data freshness.

apps/webapp/test/fairDequeuingStrategy.test.ts (1)

206-294: Performance-based test checks risk flakiness on slower machines.
Large multipliers (>10x speed) can fail intermittently in certain CI environments. Consider adjusting thresholds or using more robust performance testing.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6da5e7a and 772150c.

📒 Files selected for processing (5)
  • apps/webapp/app/env.server.ts (1 hunks)
  • apps/webapp/app/v3/marqs/fairDequeuingStrategy.server.ts (6 hunks)
  • apps/webapp/app/v3/marqs/index.server.ts (1 hunks)
  • apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts (0 hunks)
  • apps/webapp/test/fairDequeuingStrategy.test.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts
⏰ 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: typecheck / typecheck
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: units / 🧪 Unit Tests
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (9)
apps/webapp/app/v3/marqs/fairDequeuingStrategy.server.ts (6)

95-98: Evaluate potential concurrency risks when using a shared Map in async code.
Although Node.js is single-threaded, high concurrency triggers can cause rapid reads and writes which may lead to race conditions in _reusedSnapshotForConsumer. Consider adding a lock or verifying that calls will not overlap for the same consumer.


342-342: No issues to report here.


354-363: Implementation for maximumOrgCount is clear.
The code flows well. Just ensure that callers handle edge cases when maximumOrgCount is 0 or undefined.


397-401: Good addition of tracing attributes for org-level concurrency details.
This provides clear observability without cluttering.


434-438: Parallel environment-level tracing attributes are consistent.
The approach is uniform and helps maintain clarity across both orgs and envs.


451-460: Snapshot caching logic is consistent with earlier checks.
The same concurrency verification applies here. If usage patterns grow complex, consider adding a short TTL to reduce stale entries.

apps/webapp/app/env.server.ts (1)

235-236: Environment variables look well integrated.
Defining a default of 0 for MARQS_REUSE_SNAPSHOT_COUNT and making MARQS_MAXIMUM_ORG_COUNT optional seems consistent with the usage patterns in FairDequeuingStrategyOptions.

apps/webapp/test/fairDequeuingStrategy.test.ts (1)

783-912: Comprehensive test for maximumOrgCount.
This test thoroughly exercises average-age logic and ensures only top orgs are selected. Logging is handy for debugging.

apps/webapp/app/v3/marqs/index.server.ts (1)

1628-1629: LGTM! Configuration changes enhance queue distribution control.

The addition of reuseSnapshotCount and maximumOrgCount to the shared queue's FairDequeuingStrategy configuration provides more granular control over queue distribution and performance optimization.

Let's verify the environment variables are properly defined:

✅ Verification successful

✓ Configuration changes are properly implemented

The reuseSnapshotCount and maximumOrgCount properties are correctly:

  • Defined as optional parameters in FairDequeuingStrategyOptions
  • Configured through environment variables with proper type validation
  • Used consistently in the MARQS implementation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify environment variable definitions and their usage.

# Test: Search for environment variable definitions
echo "Searching for environment variable definitions..."
rg -A 2 "MARQS_(REUSE_SNAPSHOT_COUNT|MAXIMUM_ORG_COUNT)"

# Test: Search for FairDequeuingStrategy options type definition
echo "Searching for FairDequeuingStrategy options type..."
ast-grep --pattern 'interface $_ {
  $$$
  reuseSnapshotCount?: $_
  maximumOrgCount?: $_
  $$$
}'

Length of output: 1061


Script:

#!/bin/bash
# Search for FairDequeuingStrategy type definition with a more flexible pattern
echo "Searching for FairDequeuingStrategy type definition..."
ast-grep --pattern 'class FairDequeuingStrategy {
  $$$
}'

# Also search for any type definitions containing these properties
echo "Searching for type definitions with these properties..."
rg -A 5 "(?:interface|type).*\{[^}]*(?:reuseSnapshotCount|maximumOrgCount)"

Length of output: 378


Script:

#!/bin/bash
# Broader search for FairDequeuingStrategy
echo "Searching for FairDequeuingStrategy mentions..."
rg -A 5 "FairDequeuingStrategy"

# Search for files containing both properties
echo "Searching for files with both properties..."
rg -l "reuseSnapshotCount.*maximumOrgCount|maximumOrgCount.*reuseSnapshotCount"

Length of output: 12832

Copy link

pkg-pr-new bot commented Jan 28, 2025

@trigger.dev/build

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/build@1644

trigger.dev

npm i https://pkg.pr.new/triggerdotdev/trigger.dev@1644

@trigger.dev/react-hooks

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/react-hooks@1644

@trigger.dev/rsc

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/rsc@1644

@trigger.dev/core

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/core@1644

@trigger.dev/sdk

npm i https://pkg.pr.new/triggerdotdev/trigger.dev/@trigger.dev/sdk@1644

commit: 772150c

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.

1 participant