Skip to content
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

feat(bundles): retry based on retry attempts #299

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

karlprieb
Copy link
Collaborator

No description provided.

@karlprieb karlprieb requested a review from djwhitt January 30, 2025 17:12
Copy link

codecov bot commented Jan 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.47%. Comparing base (f8b2591) to head (a346215).
Report is 21 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #299      +/-   ##
===========================================
+ Coverage    72.40%   72.47%   +0.07%     
===========================================
  Files           40       40              
  Lines        10114    10130      +16     
  Branches       584      585       +1     
===========================================
+ Hits          7323     7342      +19     
+ Misses        2787     2784       -3     
  Partials         4        4              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

coderabbitai bot commented Jan 30, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

error @permaweb/[email protected]: The engine "yarn" is incompatible with this module. Expected version "please-use-npm". Got "1.22.22"
error Found incompatible module.

📝 Walkthrough

Walkthrough

This pull request introduces enhancements to the bundles table for tracking retry attempts. The changes include adding three new columns (retry_attempt_count, first_retried_at, and last_retried_at) to the database schema. A new SQL method updateBundleRetry is implemented to increment retry attempts and update timestamps. The database worker and interface are extended to support saving bundle retry information. Corresponding migration scripts and test cases are added to validate the new functionality, focusing on improving the system's ability to track and manage bundle retry operations.

Changes

File Change Summary
migrations/2025.01.30T14.12.03.bundles.add-retry-stats.sql Added columns for retry tracking: retry_attempt_count, first_retried_at, last_retried_at. Dropped import_attempt_last_queued_idx, created new indexes import_attempt_last_retried_idx and root_transaction_id_idx.
migrations/down/2025.01.30T14.12.03.bundles.add-retry-stats.sql Reverse migration to drop new columns and recreate previous index configuration.
src/database/sql/bundles/import.sql Added updateBundleRetry SQL statement to update retry attempt count and timestamps.
src/database/sql/bundles/repair.sql Modified selectFailedBundleIds to sort by retry_attempt_count and last_retried_at.
src/database/standalone-sqlite.test.ts Added test suite saveBundleRetries to validate retry tracking functionality.
src/database/standalone-sqlite.ts Introduced saveBundleRetries method in database worker classes.
src/types.d.ts Added saveBundleRetries method to BundleIndex interface.
src/workers/bundle-repair-worker.ts Updated retry interval and added saveBundleRetries call in retryBundles method.
test/bundles-schema.sql Updated bundles table schema with new columns and indexes.

Possibly related PRs

Suggested reviewers

  • djwhitt

📜 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 d1dc6aa and a346215.

📒 Files selected for processing (6)
  • src/database/sql/bundles/import.sql (1 hunks)
  • src/database/sql/bundles/repair.sql (1 hunks)
  • src/database/standalone-sqlite.test.ts (2 hunks)
  • src/database/standalone-sqlite.ts (3 hunks)
  • src/types.d.ts (1 hunks)
  • src/workers/bundle-repair-worker.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/types.d.ts
  • src/database/sql/bundles/repair.sql
  • src/database/sql/bundles/import.sql
  • src/workers/bundle-repair-worker.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test (macos-latest)
🔇 Additional comments (6)
src/database/standalone-sqlite.test.ts (3)

1177-1214: LGTM! Well-structured test setup.

The test setup is comprehensive with good test data preparation:

  • Clear variable naming with distinct IDs for easy tracking
  • Proper setup of test bundles with different root transaction IDs
  • SQL query preparation for result verification

1216-1268: LGTM! Thorough test coverage for bundle retry updates.

Test case effectively verifies:

  • Initial state validation
  • Retry count increments
  • Timestamp updates
  • Selective updates based on root transaction ID

1270-1291: LGTM! Good timestamp synchronization verification.

Test case properly validates:

  • Timestamp equality across bundles with same root transaction ID
  • Correct timestamp ordering (last_retried_at > first_retried_at)
src/database/standalone-sqlite.ts (3)

914-920: LGTM! Clean implementation of worker method.

The implementation:

  • Properly decodes the root transaction ID from base64url
  • Updates bundle retry information using SQL statement
  • Uses current timestamp for retry tracking

2934-2936: LGTM! Well-defined main class method.

The method:

  • Returns Promise for async operation
  • Correctly queues write operation to bundles worker
  • Maintains consistent parameter passing

3356-3359: LGTM! Proper worker message handling integration.

The message handler:

  • Correctly invokes worker method
  • Maintains consistent null response pattern
  • Follows existing message handling structure
✨ 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: 0

🧹 Nitpick comments (3)
src/workers/bundle-repair-worker.ts (1)

68-69: Consider keeping the retry interval configurable.

The retry interval has been hardcoded to 60 seconds, removing the configurability previously provided by config.BUNDLE_REPAIR_RETRY_INTERVAL_SECONDS. This might limit the system's adaptability to different environments or requirements.

-      60 * 1000,
-      // config.BUNDLE_REPAIR_RETRY_INTERVAL_SECONDS * 1000,
+      config.BUNDLE_REPAIR_RETRY_INTERVAL_SECONDS * 1000,
migrations/2025.01.30T14.12.03.bundles.add-retry-stats.sql (1)

1-7: LGTM! Consider adding documentation.

The schema changes look good. The column types are appropriate, and the indexes will help optimize queries. Consider adding comments to document:

  • The purpose of each column
  • The expected values/format for timestamps
  • The rationale for replacing import_attempt_last_queued_idx with import_attempt_last_retried_idx
src/database/standalone-sqlite.test.ts (1)

1177-1292: LGTM! Consider adding edge case tests.

The test suite thoroughly covers the core functionality. Consider adding tests for:

  • Maximum retry attempts (if there's a limit)
  • Concurrent retry updates
  • Error cases (e.g., invalid root transaction ID)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fbbd411 and d1dc6aa.

📒 Files selected for processing (9)
  • migrations/2025.01.30T14.12.03.bundles.add-retry-stats.sql (1 hunks)
  • migrations/down/2025.01.30T14.12.03.bundles.add-retry-stats.sql (1 hunks)
  • src/database/sql/bundles/import.sql (1 hunks)
  • src/database/sql/bundles/repair.sql (1 hunks)
  • src/database/standalone-sqlite.test.ts (2 hunks)
  • src/database/standalone-sqlite.ts (3 hunks)
  • src/types.d.ts (1 hunks)
  • src/workers/bundle-repair-worker.ts (2 hunks)
  • test/bundles-schema.sql (2 hunks)
🔇 Additional comments (10)
src/workers/bundle-repair-worker.ts (1)

112-112: LGTM! Proper placement of retry tracking.

The saveBundleRetries call is correctly placed after logging but before queueing the transaction, and it's properly wrapped in the existing try-catch block for error handling.

src/types.d.ts (1)

230-230: LGTM! Well-defined interface method.

The saveBundleRetries method is properly typed with a clear parameter and return type, maintaining consistency with the interface's style.

src/database/standalone-sqlite.ts (3)

914-920: LGTM! Proper implementation of bundle retry tracking.

The worker implementation correctly:

  • Decodes the rootTransactionId from base64
  • Updates the bundle retry information with current timestamp

2934-2936: LGTM! Clean interface implementation.

The main class implementation properly queues the write operation while maintaining consistent error handling patterns.


3356-3359: LGTM! Proper message handling integration.

The worker message handling is correctly integrated into the switch statement, maintaining the established null response pattern.

migrations/down/2025.01.30T14.12.03.bundles.add-retry-stats.sql (2)

1-3: LGTM! Clean column removal.

The columns are dropped in a clear and straightforward manner.


5-7: LGTM! Proper index management.

The index operations properly use IF EXISTS/IF NOT EXISTS clauses to prevent errors during migration.

src/database/sql/bundles/repair.sql (1)

22-22: LGTM! The ordering change aligns with the new retry-based tracking.

The change to sort by retry_attempt_count and last_retried_at is consistent with the schema changes and provides a good strategy for prioritizing bundle processing.

src/database/sql/bundles/import.sql (1)

57-66: LGTM! The retry update logic is well-implemented.

The SQL statement correctly handles:

  • NULL values using COALESCE
  • First-time vs subsequent retries
  • Parameterized inputs for safety
test/bundles-schema.sql (1)

57-57: LGTM! Test schema matches production schema.

The test schema correctly includes all the new columns and indexes from the migration.

Also applies to: 159-160

@karlprieb karlprieb force-pushed the PE-7436-bundle-retry-counts branch from d1dc6aa to a346215 Compare January 30, 2025 17:18
@@ -107,6 +108,7 @@ export class BundleRepairWorker {
);
for (const bundleId of bundleIds) {
this.log.info('Retrying failed bundle', { bundleId });
await this.bundleIndex.saveBundleRetries(bundleId);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djwhitt I'm awaiting here to make sure we update retry stats

@djwhitt
Copy link
Collaborator

djwhitt commented Jan 31, 2025

Planning to merge this one after release 24 on Monday.

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