Skip to content

Conversation

@NathanFlurry
Copy link
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Member Author

NathanFlurry commented Feb 10, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

This was referenced Feb 10, 2026
@claude
Copy link

claude bot commented Feb 10, 2026

PR Review: fix(rivetkit): remove top-level promise errors

Summary

This PR addresses unhandled promise rejections by adding rejection handlers to all promiseWithResolvers calls throughout the RivetKit codebase. The approach modifies the promiseWithResolvers utility to require an onReject callback parameter.

Code Quality & Best Practices ✅

Strengths:

  • Systematic approach to handling unhandled promise rejections across the entire codebase
  • Consistent logging pattern for all rejection handlers using structured logging
  • Good use of structured logging with context ({ msg: "...", reason })

Concerns:

  1. Breaking API Change ⚠️

    • The promiseWithResolvers function now requires an onReject parameter, making it non-optional
    • This is a breaking change for any external consumers of this utility
    • Recommendation: Consider making onReject optional with a default no-op or basic console.warn:
    export function promiseWithResolvers<T>(onReject?: (reason?: any) => void): {
        // ...
        promise.catch(onReject ?? ((reason) => console.warn('Unhandled promise rejection:', reason)));
        return { promise, resolve, reject };
    }
  2. Indentation in engine/actor-driver.ts 📝

    • The try-catch block adds extra indentation to ~35 lines of code (lines 438-472)
    • This creates deep nesting that could impact readability
    • Recommendation: Consider extracting the actor initialization logic into a separate method:
    try {
        await this.#initializeActor(actorId, actorConfig, input, handler, name, key);
    } catch (innerError) {
        // error handling
    }
  3. Inconsistent Logger Usage ⚠️

    • Some files use loggerWithoutContext() while others use logger()
    • In queue-manager.ts and state-manager.ts: uses loggerWithoutContext()
    • In cloudflare-workers/actor-driver.ts and client/actor-conn.ts: uses logger()
    • Question: Is this intentional based on context availability, or should it be standardized?

Potential Bugs 🐛

  1. Error Handling in #runnerOnActorStart

    • Lines 473-481: The catch block rejects handler.actorStartPromise but this promise is already being caught by the rejection handler added in line 108 of utils.ts
    • This means the error will be logged twice: once by the onReject callback and once by the explicit reject
    • The explicit reject() call is correct for propagating errors to waiters, but the double logging might be confusing
    • Recommendation: This is likely fine, but consider if the log messages should be differentiated
  2. Promise Chain Handling 🤔

    • Line 108: promise.catch(onReject) attaches the handler, but the promise is still returned
    • If callers also add their own .catch(), both handlers will fire
    • This is generally safe but worth noting in documentation

Performance Considerations ⚡

  • Negligible performance impact from adding rejection handlers
  • The logger calls are only invoked on actual rejections, not in happy paths
  • No concerns here

Security Concerns 🔒

  • The reason parameter is logged directly, which could potentially expose sensitive information if errors contain secrets
  • Recommendation: Consider sanitizing the reason before logging, or at least document that rejection reasons should not contain sensitive data

Test Coverage 🧪

  1. Missing Tests

    • No new tests added to verify that unhandled rejections are properly caught and logged
    • Recommendation: Add tests that:
      • Verify rejection handlers are called when promises are rejected
      • Check that appropriate log messages are generated
      • Ensure the error propagation still works correctly
  2. Test File Changes

    • The change to fixtures/driver-test-suite/sleep.ts is appropriate and follows the same pattern

Additional Observations

  1. Documentation: The promiseWithResolvers function comment mentions it's a polyfill for Cloudflare Workers, but doesn't document the new required parameter

  2. Migration Guide: For a breaking change like this, consider:

    • Updating CHANGELOG with migration notes
    • Documenting why this change was necessary
    • Providing examples of the new usage pattern

Recommendations Summary

Must Fix:

  • ⚠️ Make onReject parameter optional to avoid breaking external consumers

Should Fix:

  • 📝 Consider extracting nested logic in actor-driver.ts to reduce indentation
  • 🧪 Add tests for the new rejection handling behavior
  • 📚 Update function documentation to describe the onReject parameter

Consider:

  • 🔍 Standardize logger usage (logger() vs loggerWithoutContext())
  • 🛡️ Add guidance about not including sensitive data in rejection reasons
  • 📖 Add migration notes for this breaking change

Conclusion

This PR addresses a real issue with unhandled promise rejections systematically. The core approach is sound, but the breaking API change and lack of test coverage are concerns that should be addressed before merging. The code quality is generally good and follows project conventions well.

Status: ⚠️ Needs revisions before merge

@NathanFlurry NathanFlurry marked this pull request as ready for review February 10, 2026 08:39
@graphite-app
Copy link
Contributor

graphite-app bot commented Feb 10, 2026

Merge activity

  • Feb 10, 8:45 AM UTC: NathanFlurry added this pull request to the Graphite merge queue.
  • Feb 10, 8:46 AM UTC: CI is running for this pull request on a draft pull request (#4166) due to your merge queue CI optimization settings.
  • Feb 10, 8:48 AM UTC: The Graphite merge queue removed this pull request due to downstack failures on PR #4081.
  • Feb 10, 8:48 AM UTC: The Graphite merge queue removed this pull request due to downstack failures on PR #4081.
  • Feb 10, 7:35 PM UTC: NathanFlurry added this pull request to the Graphite merge queue.
  • Feb 10, 7:36 PM UTC: CI is running for this pull request on a draft pull request (#4167) due to your merge queue CI optimization settings.
  • Feb 10, 7:36 PM UTC: Merged by the Graphite merge queue via draft PR: #4167.

graphite-app bot pushed a commit that referenced this pull request Feb 10, 2026
# Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

## How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

## Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
@NathanFlurry NathanFlurry force-pushed the 02-09-fix_clean_up_vite_hacks branch from c1ea946 to e554d7e Compare February 10, 2026 19:25
@NathanFlurry NathanFlurry force-pushed the 02-09-fix_rivetkit_remove_top-level_promise_errors branch from e0e274e to 2c75012 Compare February 10, 2026 19:25
graphite-app bot pushed a commit that referenced this pull request Feb 10, 2026
# Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

## How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

## Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
@graphite-app graphite-app bot closed this Feb 10, 2026
@graphite-app graphite-app bot deleted the 02-09-fix_rivetkit_remove_top-level_promise_errors branch February 10, 2026 19:36
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