-
Notifications
You must be signed in to change notification settings - Fork 133
refactor(rivetkit): restructure connection lifecycle contexts #3428
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
4b4b76b to
aedd8f2
Compare
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: Connection Lifecycle Context RestructuringSummaryThis PR refactors the connection lifecycle context handling in RivetKit by:
Positive AspectsArchitecture & Design✅ Excellent use of inheritance hierarchy: The new ConnInitContext and ConnContext base classes create a clear and logical separation between connection initialization phases and active connection phases. Context hierarchy:
✅ Cleaner API: Moving request from an opts parameter to a context property (c.request) is more ergonomic and consistent with the rest of the API. ✅ Type safety: The request?: Request | undefined typing correctly reflects that requests may not always be present in all connection scenarios. Implementation Quality✅ Consistent refactoring: All lifecycle hooks have been updated consistently across the codebase. ✅ Backward compatibility considerations: The migration path is clear, as evidenced by the fixture updates. Issues & Concerns🔴 Critical: Incomplete Migration (Blocking)Location: rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/raw-websocket.ts:54 The getRequestInfo handler is commented out with a throw "TODO" statement. This is a runtime bomb that will fail if any test calls this code path. Recommendation: Either:
Suggested fix: Access ctx.request to get the request URL info, similar to how it's done in request-access.ts fixture.
|
Code Review: Connection Lifecycle Context RestructuringThis PR refactors the RivetKit connection lifecycle contexts to improve type safety and reduce code duplication. Overall, the changes are well-structured and follow good architectural patterns. Strengths
Issues and Concerns1. Breaking Change with TODO Comment (HIGH PRIORITY) In rivetkit-typescript/packages/rivetkit/fixtures/driver-test-suite/raw-websocket.ts:54, the code now has throw TODO where request info should be returned. This test fixture now throws an error instead of providing working functionality. Recommendation: Either complete the implementation using c.request, remove this test case if no longer relevant, or add a proper error message. 2. Request Availability Not Clear (MEDIUM PRIORITY) The request field is marked as Request | undefined in multiple contexts, but the documentation does not clearly explain when it will be undefined and what users should check before using it. Recommendation: Add clearer documentation explaining that request will be defined for connections initiated via HTTP/WebSocket upgrade requests, but undefined for connections restored from hibernation. 3. Empty Type Definition (LOW PRIORITY) In websocket.ts:8, changed from empty object to Record never never. While more explicit, the old empty object was clearer for representing an empty object type. 4. Type Safety in ConnectionManager (LOW PRIORITY) In connection-manager.ts, there are several as any casts at lines 153, 275, and 286. Consider adding proper type definitions to avoid type assertions. Questions
Performance and Security
Recommendations SummaryBefore Merge:
Nice to Have: Overall AssessmentThis is a solid refactoring that improves code quality and API design. The inheritance hierarchy is well-thought-out and the reduction in code duplication is significant. The main blocker is the incomplete TODO implementation. Recommendation: Request changes for the TODO issue, then approve. |
b1ac4de to
9878acc
Compare
7de7488 to
27c352a
Compare
|
Deployment failed with the following error: Learn More: https://vercel.com/docs/limits#rate-limits |
PR Review: Restructure Connection Lifecycle ContextsThank you for this refactoring! This is a well-thought-out restructuring that improves type safety and API consistency. Strengths1. Excellent Type HierarchyThe new context hierarchy is clean and logical:
This makes the capabilities available at each stage explicit in the type system. 2. Improved API ConsistencyMoving request from the opts parameter to context.request is more consistent with the framework's design patterns. 3. Reduced BoilerplateUsing inheritance eliminates significant code duplication across ActionContext, RequestContext, and WebSocketContext. Issues & Concerns1. Breaking Change with TODO Comment (CRITICAL)In fixtures/driver-test-suite/raw-websocket.ts:54, there's a throw TODO that breaks the getRequestInfo functionality. This will cause runtime errors if any tests rely on this. Recommendation: Either implement the new way to access request info via ctx.request, remove this code path, or handle the error gracefully. 2. Type Safety NoteThe change from {} to Record<never, never> for ConnDriverWebSocketState is more explicit but could be a subtle breaking change in structural typing scenarios. 3. Error HandlingIn request-access.ts:105, throw Missing request should use a proper Error object instead of a string. 4. Backwards CompatibilityThe signature changes are breaking. Consider providing a migration guide for users. Suggestions
SummaryOverall Assessment: Solid refactoring that improves maintainability and type safety. Main blocker is the TODO/throw that needs resolution. Recommended Actions Before Merge:
Great work on this refactoring! |
27c352a to
714660b
Compare
9878acc to
57377f5
Compare
PR Review: Connection Lifecycle RefactoringI've reviewed this PR that restructures the connection lifecycle contexts in RivetKit. Overall, this is a well-executed refactoring that improves type safety and code organization. Here's my detailed feedback: Strengths1. Excellent Context Hierarchy Design
This hierarchy properly models the different stages of connection lifecycle and eliminates code duplication across 150+ lines in 2. Improved API Consistency
This is more intuitive and consistent with how other context properties are accessed. 3. Type Safety Improvements
4. Good Test Coverage Issues & ConcernsCritical: Incomplete ImplementationLocation: } else if (parsed.type === "getRequestInfo") {
throw "TODO";
// Send back the request URL info
// websocket.send(...)Issue: The Impact: This test will fail when run, as the fixture throws "TODO" instead of returning request info. Recommendation: Either:
The fix should look something like: } else if (parsed.type === "getRequestInfo") {
if (!c.request) {
websocket.send(JSON.stringify({
type: "error",
message: "Request not available"
}));
} else {
websocket.send(JSON.stringify({
type: "requestInfo",
url: c.request.url,
pathname: new URL(c.request.url).pathname,
search: new URL(c.request.url).search,
}));
}Breaking ChangesSignature Changes (non-breaking for TypeScript but behavioral):
Migration Path: Users need to change from Type Safety ConcernLocation: > extends ActorContext<TState, undefined, undefined, TVars, TInput, TDatabase> {Using Minor Issues1. Documentation
2. Export Organization 3. Variable Naming const ctx = new OnBeforeConnectContext(this.#actor, request);
await config.onBeforeConnect(ctx, params);This is clean and readable. Performance & Security
Recommendations
Test CoverageThe test fixtures have been comprehensively updated:
ConclusionThis is a solid refactoring that improves code quality and API consistency. The only blocker is the incomplete Recommendation: Request changes to fix the TODO before merging. Note: Following CLAUDE.md conventions - no formatting was run as per project guidelines. |
PR Review: Refactor RivetKit Connection Lifecycle ContextsSummaryThis PR restructures the connection lifecycle contexts in RivetKit by creating a cleaner inheritance hierarchy and moving the Code Quality & Architecture✅ Positive Changes
|
Merge activity
|

No description provided.