-
Notifications
You must be signed in to change notification settings - Fork 148
feat: actor messages & queues #3989
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: main
Are you sure you want to change the base?
Conversation
|
🚅 Deployed to the rivet-pr-3989 environment in rivet-frontend
|
How to use the Graphite Merge QueueAdd 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. |
PR Review: Actor Messages & QueuesThis PR introduces a comprehensive queue messaging system for Rivet Actors. Overall, the implementation is solid with good test coverage and appropriate error handling. Here are my findings: ✅ Strengths
🔍 Issues & RecommendationsCritical Issues1. Race Condition in Queue Waiter Resolution (queue-manager.ts:300-325) The // Current code - problematic
for (const waiter of pending) {
const messages = await this.#drainMessages(
waiter.nameSet,
waiter.count,
);
if (messages.length === 0) {
continue; // Next waiter gets nothing even if it wants the same queue
}
// ...
}Recommendation: Implement fair distribution or FIFO ordering for waiters. Consider:
2. Potential Message Loss on Metadata Update Failure (queue-manager.ts:288-298) Messages are deleted first, then metadata is updated in a separate operation. If the metadata update fails, the messages are lost but the size counter remains incorrect. await this.#driver.kvBatchDelete(this.#actor.id, keys);
await this.#driver.kvBatchPut(this.#actor.id, [
[KEYS.QUEUE_METADATA, this.#serializeMetadata()],
]); // If this fails, messages are lost but size is wrongRecommendation: Either:
3. Missing Abort Signal Check After Async Operations (queue-manager.ts:311-315) Between the async const messages = await this.#drainMessages(waiter.nameSet, waiter.count);
// Actor could have been aborted during drainMessages
if (messages.length === 0) {
continue;
}
waiter.resolve(messages); // Resolving even though actor is abortedRecommendation: Add abort signal check after Medium Priority Issues4. Inefficient Queue Scanning (queue-manager.ts:246-279)
Recommendation: Consider:
5. Size Mismatch Silently Corrected (queue-manager.ts:274-277) When the actual message count doesn't match metadata size, it's silently corrected without logging. if (this.#metadata.size \!== decoded.length) {
this.#metadata.size = decoded.length;
this.#actor.inspector.updateQueueSize(this.#metadata.size);
}Recommendation: Log this event at warn/error level since it indicates data corruption or a bug. 6. Missing Input Validation (queue-manager.ts:156-161) The async receive(
names: string[], // Could be empty
count: number, // Could be negative or 0 before clamping
timeout?: number,
abortSignal?: AbortSignal,
): Promise<QueueMessage[] | undefined> {
const limitedCount = Math.max(1, count);
const nameSet = new Set(names);Recommendation: Validate inputs and throw descriptive errors for invalid parameters. 7. Queue Proxy "then" Special Case (queue.ts:103) The proxy returns if (prop === "then") return undefined;Recommendation: Add a comment explaining why this is necessary (prevents the proxy from being treated as a thenable). Low Priority / Nice-to-Have8. Inconsistent Error Message Format Some error messages end with periods, others don't. Some include documentation links, others don't. Recommendation: Standardize error message formatting across the codebase. 9. Type Safety in Queue Proxy The Recommendation: Consider using a builder pattern or typed proxy that knows valid queue names from the actor definition. 10. Missing JSDoc Comments Private methods in Recommendation: Add JSDoc comments for complex private methods like 11. Inconsistent Logging Practices (queue-manager.ts:81-86) Metadata decode failure logs the error object directly: this.#actor.rLog.error({
msg: "failed to decode queue metadata, rebuilding from messages",
error,
});But according to CLAUDE.md, structured logging should be used with field syntax like Recommendation: Use 📝 Code Quality Notes
🧪 Testing Recommendations
📋 Minor Suggestions
✅ SummaryThis is a well-structured implementation with good error handling and test coverage. The main concerns are:
Once the critical issues are addressed, this will be a solid feature. The code follows most of the project conventions and demonstrates good software engineering practices. Recommendation: Address the critical issues before merging, and consider the medium-priority improvements in follow-up PRs. |
20d84dd to
ed996b2
Compare
ed996b2 to
11d2f22
Compare
11d2f22 to
266ebbd
Compare
266ebbd to
2dd6f17
Compare
2dd6f17 to
92b8706
Compare

No description provided.