Skip to content

fix: use default retry settings when no catchError handlers are defined #1852

New issue

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

By clicking “No 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? No Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025

Conversation

ericallam
Copy link
Member

@ericallam ericallam commented Mar 31, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a new task with configurable retry behavior using exponential backoff, enabling controlled retries and improved task resiliency.
  • Refactor
    • Enhanced task execution by consolidating error handling and retry logic for more predictable processing.
    • Optimized background operations by ensuring that only essential information is retrieved during processing.

Copy link

changeset-bot bot commented Mar 31, 2025

⚠️ No Changeset found

Latest commit: 1136c62

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

Walkthrough

This update refines database querying, error handling, and retry logic. In the webapp service, a select clause now limits database output to four specific fields. In the core worker module, a new constant centralizes retry logic in error handling, and the corresponding test has been updated to support additional retry configuration. Furthermore, a new file introduces a task with exponential backoff retry behavior, simulating failures until a configured condition is met.

Changes

File(s) Change Summary
apps/webapp/app/.../triggerTask.server.ts Added a select clause to the DB query in RunEngineTriggerTaskService to fetch only id, version, sdkVersion, and cliVersion.
packages/core/src/v3/workers/taskExecutor.ts
packages/core/test/taskExecutor.test.ts
Introduced defaultRetryResult to centralize retry logic and updated the executeTask signature to accept retrySettings; added a test case verifying retry settings.
references/hello-world/src/trigger/retry.ts Created a new task retryTask with exponential backoff (factor 1.8, min 20ms, max 100ms) that simulates failures until a specified success condition is met.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RetryTask

    Client->>RetryTask: run(payload with failCount)
    loop Retry Attempts (while current attempt <= failCount)
        RetryTask->>RetryTask: Log current attempt
        alt Attempt still failing
            RetryTask->>RetryTask: Throw error & Log warning
        end
    end
    RetryTask->>Client: Return result with number of attempts
Loading

Suggested reviewers

  • matt-aitken

Poem

I'm a little rabbit on the run,
Hopping through code under the sun,
With queries precise and tasks retried,
I celebrate changes with a joyful stride.
Bugs and errors, now neatly defied! 🐇💻


📜 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 8977d25 and 1136c62.

📒 Files selected for processing (4)
  • apps/webapp/app/runEngine/services/triggerTask.server.ts (1 hunks)
  • packages/core/src/v3/workers/taskExecutor.ts (3 hunks)
  • packages/core/test/taskExecutor.test.ts (4 hunks)
  • references/hello-world/src/trigger/retry.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: units / 🧪 Unit Tests
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (8)
apps/webapp/app/runEngine/services/triggerTask.server.ts (1)

285-290: Improved query performance by limiting field selection

The addition of a select clause optimizes the database query by explicitly requesting only the necessary fields (id, version, sdkVersion, and cliVersion) instead of fetching all columns.

packages/core/src/v3/workers/taskExecutor.ts (3)

1030-1036: Improved error handling with centralized retry logic

The introduction of a defaultRetryResult constant follows the DRY principle by eliminating duplicate retry logic code. This makes the code more maintainable and reduces the risk of inconsistencies in retry behavior implementation.


1051-1051: Refactored to use centralized retry logic

Updated to reference the new defaultRetryResult constant instead of inline retry logic, creating more consistent error handling.


1096-1096: Refactored to use centralized retry logic

Updated to reference the new defaultRetryResult constant instead of inline retry logic, creating more consistent error handling.

references/hello-world/src/trigger/retry.ts (1)

7-37: Well-implemented task with exponential backoff retry mechanism

The task effectively demonstrates the retry capability with exponential backoff settings and control of simulated failures. The configuration is comprehensive, with parameters for:

  • Maximum attempts
  • Exponential factor
  • Min/max timeout durations

The implementation clearly shows how to handle retry scenarios based on attempt count and provides useful logging at each stage.

packages/core/test/taskExecutor.test.ts (3)

788-828: Good test coverage for default retry behavior

This test confirms that default retry settings are properly applied when no catch error hook is provided. It validates both the structure of the error result and ensures the retry delay falls within the expected range based on the configured settings.


1669-1673: Enhanced test utility with configurable retry settings

The executeTask function has been improved to accept an optional retrySettings parameter, making it more flexible for testing different retry configurations.


1694-1694: Applied optional retry settings to task executor

Updated to conditionally use the provided retrySettings or fall back to the default configuration.

✨ 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 plan to trigger planning for file edits and PR creation.
  • @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.

@matt-aitken matt-aitken merged commit c963dcd into main Mar 31, 2025
12 checks passed
@matt-aitken matt-aitken deleted the ea-branch-29 branch March 31, 2025 12:57
@coderabbitai coderabbitai bot mentioned this pull request Apr 25, 2025
1 task
No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants