-
Notifications
You must be signed in to change notification settings - Fork 131
refactor(rivetkit): add state manager for conn with symbol-based access #3423
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.
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: |
|
Deployment failed with the following error: Learn More: https://vercel.com/docs/limits#rate-limits |
Code Review: Refactor Connection State ManagementThis PR successfully extracts state management logic from the ✅ Strengths
🔍 Observations & Suggestions1. Unused
|
Code Review: refactor(rivetkit): add state manager for conn with symbol-based accessSummaryThis PR successfully refactors connection state management by extracting state-related logic into a dedicated Positive Aspects
Issues and Concerns1. Circular Dependency Risk (rivetkit-typescript/packages/rivetkit/src/actor/conn/state-manager.ts:5)import { CONN_ACTOR_SYMBOL, CONN_STATE_ENABLED_SYMBOL, type Conn } from "./mod";Issue: The Impact: While TypeScript handles this with the Recommendation: Consider moving the symbols to a separate 2. Unused Property (rivetkit-typescript/packages/rivetkit/src/actor/conn/state-manager.ts:33-35)get changed(): boolean {
return this.#changed;
}Issue: The Recommendation: Remove the unused 3. Inconsistent Access Pattern (rivetkit-typescript/packages/rivetkit/src/actor/conn/mod.ts:145-147)Issue: Some internal methods use symbol-based access as methods ( Recommendation: Consider making access patterns more consistent - either all symbols are getters or all are methods, based on whether they represent data or behavior. 4. Error Message Quality (rivetkit-typescript/packages/rivetkit/src/actor/conn/state-manager.ts:43)if (!this.#persist.state) throw new Error("state should exists");Issues:
Recommendation: if (!this.#persist.state) {
throw new errors.InternalError("Connection state should exist when state is enabled");
}5. Test CoverageIssue: No test files found for the connection state management functionality. Recommendation: Add tests covering:
Performance ConsiderationsThe refactoring appears performance-neutral:
Security ConcernsLow Risk: The symbol-based approach actually improves encapsulation by making it harder to accidentally access internal APIs. The change tracking and CBOR validation remain intact. Minor Issues6. Import Formatting (rivetkit-typescript/packages/cloudflare-workers/src/actor-driver.ts:9-12)The change from destructured import to type-only import is good, but the trailing comma removal on line 239 is unrelated formatting noise. 7. DocumentationThe
Recommendations SummaryHigh Priority:
Medium Priority: Low Priority: ConclusionThis is a solid refactoring that improves code organization. The main concerns are the circular dependency and lack of test coverage. Once addressed, this will be a good improvement to the codebase. Recommendation: Request changes for the circular dependency and error message issues, and strongly encourage adding tests before merging. |
- Created StateManager class for connection state management - Moved state proxying and change tracking to dedicated manager - Changed conn methods to use symbols for internal access: - actor, stateEnabled, persistRaw (getters) - hasChanges(), markSaved(), sendMessage() (methods) - Updated all references across codebase to use new symbols - Maintains backward compatibility for public API (send, disconnect, etc) - Consistent naming pattern with instance/mod.ts StateManager 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
4aa3109 to
7eb9e5f
Compare
37bad6b to
5aebfdc
Compare
5aebfdc to
d2d01ea
Compare
7eb9e5f to
af583ac
Compare
Code Review - PR #3423: Refactor Connection State ManagerSummaryThis PR successfully extracts connection state management into a dedicated ✅ Strengths
🔍 Issues & Concerns1. Circular Dependency Risk (Minor)Location: #conn: Conn<any, CP, CS, any, any, any>;The Recommendation: Consider passing only the necessary dependencies (actor instance, logging) rather than the entire // Instead of storing the entire Conn
constructor(
actor: ActorInstance<S, CP, CS, V, I, DB>,
connId: ConnId,
rLog: Logger
)2. Missing Getter Usage (Minor)Location: get changed(): boolean {
return this.#changed;
}This getter is defined but never used. The public API exposes Recommendation: Either remove the unused getter or use it in hasChanges(): boolean {
return this.changed; // Use the getter
}3. Inconsistent Null Handling (Low Priority)Location: get state(): CS {
this.#validateStateEnabled();
if (!this.#persist.state) throw new Error("state should exists");
return this.#persist.state;
}The error message has a grammatical error ("should exists" → "should exist") and uses a generic Recommendation: if (!this.#persist.state) {
throw new errors.InvalidState({
message: "Connection state should exist when state is enabled"
});
}4. Missing Documentation (Minor)Location: The Recommendation: Add JSDoc comments for:
5. Type Safety Concern (Low Priority)Location: (this.#actor as any)[ACTOR_INSTANCE_PERSIST_SYMBOL]The cast to Recommendation: Consider adding proper type definitions for symbol-based properties or using a more type-safe approach. 🧪 Test CoverageConcern: No new tests were added for the Recommendation: Add unit tests covering:
Example test file structure: // tests/conn-state-manager.test.ts
describe("ConnectionStateManager", () => {
test("tracks changes when state is modified", ...);
test("validates CBOR serializability", ...);
test("throws error when state not enabled", ...);
test("handles non-object persist data", ...);
});🔒 SecurityNo security concerns identified. The PR:
⚡ PerformanceObservation: The symbol-based method calls add minimal overhead compared to direct method calls, but the trade-off for better encapsulation is worthwhile. Note: The proxy setup in 📋 Minor Nitpicks
✅ Approval RecommendationOverall Assessment: APPROVE with minor suggestions This is a solid refactoring that:
The concerns raised are minor and don't block merging. Consider addressing them in follow-up PRs if needed. 📝 Action Items (Optional)
Great work on maintaining consistency with the |
Code Review: refactor(rivetkit): add state manager for conn with symbol-based accessSummaryThis PR successfully extracts state management logic from the ✅ Positives
🔍 Potential Issues & Suggestions1. Naming Collision Concern (Minor)Both
2. Unused
|
Code Review for PR #3423SummaryThis PR refactors the connection state management in RivetKit by extracting state-related functionality from the Positive AspectsArchitecture & Design✅ Clean separation of concerns - Moving state management logic into a dedicated ✅ Symbol-based internal API - Using symbols ( ✅ Consistent with existing patterns - The PR mentions this aligns with the pattern used in ✅ Encapsulation - Private fields in Code Quality✅ Good documentation - JSDoc comments are maintained and the ✅ Minimal surface area changes - The refactoring maintains the existing public API, which reduces the risk of breaking changes. Issues & Concerns1. Unused
|
Merge activity
|
…ss (#3423) - Created StateManager class for connection state management - Moved state proxying and change tracking to dedicated manager - Changed conn methods to use symbols for internal access: - actor, stateEnabled, persistRaw (getters) - hasChanges(), markSaved(), sendMessage() (methods) - Updated all references across codebase to use new symbols - Maintains backward compatibility for public API (send, disconnect, etc) - Consistent naming pattern with instance/mod.ts StateManager 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>

🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com