-
Notifications
You must be signed in to change notification settings - Fork 130
fix(rivetkit): properly apply clientEndpoint from metadata lookup #3402
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
base: 11-06-fix_rivetkit_properly_handle_msgindex_for_hibernatable_websocket_reconnection
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
More templates
@rivetkit/actor
@rivetkit/cloudflare-workers
@rivetkit/core
@rivetkit/db
@rivetkit/framework-base
@rivetkit/next-js
@rivetkit/react
rivetkit
@rivetkit/sql-loader
@rivetkit/engine-runner
@rivetkit/engine-runner-protocol
commit: |
Code Review - PR #3402SummaryThis PR fixes the proper application of clientEndpoint from metadata lookup by refactoring the metadata checking logic into a dedicated module and renaming disableHealthCheck to the more accurate disableMetadataLookup. Strengths
Concerns and Issues1. Critical: Config Mutation IssueLine 76 in mod.ts mutates this.#config.endpoint after the cache key has been set. This could cause issues if multiple RemoteManagerDriver instances are created with the same initial endpoint but receive different clientEndpoint values. The cache uses the original endpoint as the key, but the config is modified afterward. Recommendation: Consider using a separate field or documenting this behavior clearly. The current implementation appears correct but the mutation could be error-prone. 2. Infinite Retry Riskmetadata.ts:42 sets retries to Number.MAX_SAFE_INTEGER, which will retry forever if the metadata endpoint is permanently unavailable or misconfigured. While the exponential backoff caps at 15 seconds, this could still cause the application to hang indefinitely during startup. Recommendation: Set a reasonable retry limit (e.g., 10-20 retries, which would span 2-5 minutes with the backoff strategy) or add a total timeout. 3. Error Handling in Metadata PromiseNo .catch() handler on the promise at mod.ts:72-89. If lookupMetadataCached eventually fails, this promise will reject. When methods await this.#metadataPromise, they will throw, but there is no recovery mechanism or clear error message for users. Recommendation: Consider adding error handling to log the failure clearly and provide guidance about checking endpoint configuration. 4. Cache Never ExpiresThe cache at metadata.ts:10 is never cleared. If metadata changes during the application lifecycle, the cached value will be stale. Recommendation: Document that the cache is intentionally permanent for the lifetime of the process, or add a TTL mechanism if metadata might change. 5. Logging Inconsistencymod.ts:63 still says disabling health check but should say disabling metadata lookup to match the renamed config field. Test CoverageNo tests were added or modified in this PR. Recommendations:
Specific Recommendations
Overall AssessmentThis is a solid refactoring that improves code organization and fixes a real bug with endpoint override. The main concerns are around error handling and the infinite retry behavior. With the recommended changes, this would be production-ready. Recommendation: Approve with minor changes requested |
22a431f to
b540cc6
Compare
314e8b4 to
80503c7
Compare
Code Review - PR #3402SummaryThis PR refactors the metadata lookup logic by extracting it into a separate module and fixes a critical bug where Positive Observations✅ Good separation of concerns - Extracting metadata lookup into ✅ Proper caching strategy - Using a global cache with endpoint as the key prevents duplicate requests ✅ Better error handling - The refactored code maintains retry logic with exponential backoff ✅ Correct bug fix - The ✅ Consistent naming - Renaming from Issues & Concerns🔴 Critical: Config Mutation BugLocation: this.#config.endpoint = metadataData.clientEndpoint;Problem: This directly mutates the Impact: Race conditions and unpredictable behavior when multiple clients share config objects. Recommendation: // Option 1: Clone the config
this.#config = { ...runConfig };
// Option 2: Use a separate field for the resolved endpoint
#resolvedEndpoint: string | undefined;🟡 Medium: Infinite Retry Could Cause Resource ExhaustionLocation: retries: Number.MAX_SAFE_INTEGER,Problem: Setting retries to
Recommendation: retries: 30, // Reasonable limit (e.g., ~5 minutes with exponential backoff)Or add a timeout mechanism to fail fast after a certain duration. 🟡 Medium: Missing Error Handling in ConstructorLocation: Problem: The metadata lookup promise is created but error handling only logs. If metadata lookup fails, Current code: this.#metadataPromise = lookupMetadataCached(this.#config).then(
(metadataData) => {
// ... success handling
},
);Issue: No Recommendation: this.#metadataPromise = lookupMetadataCached(this.#config)
.then((metadataData) => {
// ... success handling
})
.catch((error) => {
logger().error({
msg: "metadata lookup failed permanently",
error: stringifyError(error),
});
// Consider: should we continue without metadata or throw?
// Current behavior will cause all operations to fail
});🟡 Medium: Cache Never ClearedLocation: const metadataLookupCache = new Map<string, Promise<MetadataResponse>>();Problem: The cache is a module-level global that persists for the lifetime of the process. If:
Recommendation: Consider adding:
🟢 Minor: Logging InconsistencyLocation: logger().info({
msg: "overriding cached client endpoint",
endpoint: metadataData.clientEndpoint,
});Issue: The message says "overriding cached client endpoint" but this happens on first lookup too, not just when overriding. The word "cached" is misleading. Recommendation: msg: "applying client endpoint from metadata"🟢 Minor: Type SafetyThe code assumes Test Coverage Concerns
Recommended test cases:
Performance Considerations✅ Caching strategy is good for performance Security Considerations✅ No obvious security issues Recommendations SummaryMust Fix:
Should Fix: Nice to Have: Overall AssessmentThis is a good refactoring that properly fixes the Recommendation: Request changes for critical issues, approve after fixes. |
80503c7 to
83daa5f
Compare
|
Review comments posted in thread |
Pull Request ReviewSummaryThis PR refactors the metadata lookup functionality in RivetKit's remote manager driver by extracting it into a dedicated module. The key change is ensuring that the Code Quality & Best Practices ✅Strengths:
Minor concerns:
|
Potential Bugs & Issues
|
Performance Considerations ⚡Good:
Consideration:
Security Concerns 🔒Low Risk:
Consideration:
|
Test Coverage 🧪Missing:
Recommendation: Add unit tests in Additional Observations
|
Recommendations SummaryMust Fix:
Should Fix:
Consider:
Overall, this is a solid refactoring that improves code organization. The main concerns are around config mutation and cache key specificity, which should be addressed before merging. |
83daa5f to
f1241ea
Compare
Pull Request ReviewSummaryThis PR refactors the metadata lookup mechanism in RivetKit to properly apply the ✅ Positive Observations1. Good Separation of Concerns
2. Proper Cache Implementation
3. Improved Naming
4. Consistent Retry Logic
🐛 Potential Issues1. Critical: Config Mutation Bug // Line 76 in mod.ts
this.#config.endpoint = metadataData.clientEndpoint;Problem: If multiple
Recommendation: Either:
2. Error Handling Gap
Recommendation: Consider adding a circuit breaker or timeout 3. Cache Never Invalidates // Line 10 in metadata.ts
const metadataLookupCache = new Map<string, Promise<MetadataResponse>>();Problem:
Recommendation:
⚡ Performance Considerations1. Sequential Blocking 2. Retry Forever 🔒 Security ConsiderationsNo significant security issues identified. The changes maintain existing security patterns:
🧪 Test CoverageMissing Test Coverage:
Recommendation: Add tests covering:
📋 Minor Suggestions1. Type Safety 2. Logging Consistency 3. Comment Update 🎯 Overall AssessmentCode Quality: Good - Clean refactoring with improved separation of concerns Correctness: Moderate concerns - Config mutation and error handling need attention Risk Level: Medium - The config mutation bug could cause subtle issues in production Recommendation: Request changes to address the config mutation and error handling issues before merging. Action ItemsMust Fix:
Should Fix: Nice to Have: |
f1241ea to
e5467bd
Compare
Code ReviewSummaryThis PR fixes a race condition in the metadata lookup mechanism and properly applies the clientEndpoint from the metadata response. The refactoring extracts metadata lookup logic into a dedicated module with proper caching. Strengths
Observations and Suggestions1. Potential Memory Leak in Cache 2. Error Handling in Constructor 3. Race Condition with Endpoint Override 4. Config Mutation Test Coverage ConcernsMissing Test Coverage: There are no test files for the metadata lookup functionality. This is a critical path that handles race conditions, retry logic, cache behavior, and endpoint override logic. Recommendations:
Performance ConsiderationsPositive Impact: Prevents duplicate metadata requests through caching, retry logic ensures eventual consistency Potential Issue: The forever: true retry option means failed metadata lookups will retry indefinitely. In production, this could mask configuration issues. Consider adding a maximum retry count or a circuit breaker pattern. VerdictApprove with minor suggestions. The core fix is sound and addresses the race condition properly. The refactoring improves code organization. Priority Recommendations:
Great work on identifying and fixing the race condition! The separation into a dedicated module makes the code much cleaner. |
PR Review: fix(rivetkit): properly apply clientEndpoint from metadata lookupSummaryThis PR refactors metadata lookup logic in RivetKit by extracting it into a separate module ( Code Quality: ✅ GoodStrengths
Areas for Improvement
Bug Fix: ✅ Critical Fix AppliedThe core issue is fixed on lines 79-86 of if (metadataData.clientEndpoint) {
this.#config.endpoint = metadataData.clientEndpoint;
logger().info({
msg: "overriding cached client endpoint",
endpoint: metadataData.clientEndpoint,
});
}Before: The metadata was fetched but This is crucial for serverless runners where the initial endpoint needs to be redirected to the actual manager endpoint. Performance Considerations: ✅ Good
Suggestion: Consider adding cache TTL or invalidation mechanism. The current implementation caches metadata forever, which could be problematic if the Security Concerns:
|
8b4fb49 to
406bd5a
Compare
26c1b12 to
5eb1e45
Compare
Code Review for PR #3402SummaryThis PR refactors the metadata lookup mechanism in the remote manager driver to properly apply the ✅ Positive Changes
🔍 Issues & Concerns1. Critical: Shallow Clone Issue
|
Code ReviewThis PR fixes an important bug where the clientEndpoint from metadata lookup was not being properly applied. The refactoring improves code organization and makes the metadata lookup behavior more explicit. Overall, the changes are well-structured, but I have some observations and suggestions. Strengths
|
Observations and Potential Issues
|
Test CoverageI noticed there are no tests added for this change. Consider adding tests for:
SummaryThe core bug fix is solid, and the refactoring improves code organization. The main concerns are:
Recommendation: Consider addressing items 1 and 2 before merging, as they could cause production issues. Adding tests would also significantly improve confidence in this change. Great work on identifying and fixing the endpoint override bug! |

No description provided.