-
Notifications
You must be signed in to change notification settings - Fork 148
feat(rivetkit): add run #4002
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: graphite-base/4002
Are you sure you want to change the base?
feat(rivetkit): add run #4002
Conversation
|
🚅 Deployed to the rivet-pr-4002 environment in rivet-frontend
|
|
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.
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. |
|
Code Review: feat(rivetkit): add run This PR adds a new run lifecycle hook to RivetKit actors for background tasks. Overall, the implementation is well-designed and follows existing patterns. Strengths
Potential Issues1. Synchronous run handlers are silently ignored (Medium severity) In mod.ts:917-942, only Promise-returning functions are tracked. If a user defines a synchronous run handler, it executes once and is silently ignored - the actor wont crash as documented. Recommendation: Add a warning when run returns a non-Promise, or wrap non-Promise results to trigger the crash behavior. 2. Timeout promise cleanup (Low severity) In #waitForRunHandler (mod.ts:951-956), the setTimeout is not cancelled if the run handler completes first. While the promise result is ignored, the timeout still fires unnecessarily. Recommendation: Store the timeout handle and clear it when the race completes early. 3. Test coverage gap Tests for early exit and error scenarios dont verify that destroyCalled is true, even though the fixture tracks this state. 4. Documentation clarity The docs state "the actor will crash and reschedule" but tests show the file-system driver doesnt auto-reschedule. Consider clarifying what this means across different drivers. Security & PerformanceNo security concerns identified. The abort signal pattern properly prevents resource leaks, and the configurable runStopTimeout prevents shutdown hangs. SummarySolid implementation of a useful feature. Main issue is handling synchronous run functions. Recommended fixes:
Great work overall! |
| #startRunHandler() { | ||
| if (!this.#config.run) return; | ||
|
|
||
| this.#rLog.debug({ msg: "starting run handler" }); | ||
|
|
||
| const runResult = this.#config.run(this.actorContext); | ||
|
|
||
| if (runResult instanceof Promise) { | ||
| this.#runPromise = runResult | ||
| .then(() => { | ||
| // Run handler exited normally - this should crash the actor | ||
| this.#rLog.warn({ | ||
| msg: "run handler exited unexpectedly, crashing actor to reschedule", | ||
| }); | ||
| this.startDestroy(); | ||
| }) | ||
| .catch((error) => { | ||
| // Run handler threw an error - crash the actor | ||
| this.#rLog.error({ | ||
| msg: "run handler threw error, crashing actor to reschedule", | ||
| error: stringifyError(error), | ||
| }); | ||
| this.startDestroy(); | ||
| }); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The run handler only crashes the actor if it returns a Promise. If the run handler is synchronous (returns void), it exits immediately without crashing the actor, which violates the documented behavior.
According to the documentation and comments, if the run handler exits (returns), the actor should crash and reschedule. However, the current code only handles the Promise case.
Fix:
#startRunHandler() {
if (!this.#config.run) return;
this.#rLog.debug({ msg: "starting run handler" });
const runResult = this.#config.run(this.actorContext);
if (runResult instanceof Promise) {
this.#runPromise = runResult
.then(() => {
this.#rLog.warn({
msg: "run handler exited unexpectedly, crashing actor to reschedule",
});
this.startDestroy();
})
.catch((error) => {
this.#rLog.error({
msg: "run handler threw error, crashing actor to reschedule",
error: stringifyError(error),
});
this.startDestroy();
});
} else {
// Synchronous return - crash immediately
this.#rLog.warn({
msg: "run handler exited unexpectedly (synchronous), crashing actor to reschedule",
});
this.startDestroy();
}
}| #startRunHandler() { | |
| if (!this.#config.run) return; | |
| this.#rLog.debug({ msg: "starting run handler" }); | |
| const runResult = this.#config.run(this.actorContext); | |
| if (runResult instanceof Promise) { | |
| this.#runPromise = runResult | |
| .then(() => { | |
| // Run handler exited normally - this should crash the actor | |
| this.#rLog.warn({ | |
| msg: "run handler exited unexpectedly, crashing actor to reschedule", | |
| }); | |
| this.startDestroy(); | |
| }) | |
| .catch((error) => { | |
| // Run handler threw an error - crash the actor | |
| this.#rLog.error({ | |
| msg: "run handler threw error, crashing actor to reschedule", | |
| error: stringifyError(error), | |
| }); | |
| this.startDestroy(); | |
| }); | |
| } | |
| } | |
| #startRunHandler() { | |
| if (!this.#config.run) return; | |
| this.#rLog.debug({ msg: "starting run handler" }); | |
| const runResult = this.#config.run(this.actorContext); | |
| if (runResult instanceof Promise) { | |
| this.#runPromise = runResult | |
| .then(() => { | |
| // Run handler exited normally - this should crash the actor | |
| this.#rLog.warn({ | |
| msg: "run handler exited unexpectedly, crashing actor to reschedule", | |
| }); | |
| this.startDestroy(); | |
| }) | |
| .catch((error) => { | |
| // Run handler threw an error - crash the actor | |
| this.#rLog.error({ | |
| msg: "run handler threw error, crashing actor to reschedule", | |
| error: stringifyError(error), | |
| }); | |
| this.startDestroy(); | |
| }); | |
| } else { | |
| // Synchronous return - crash immediately | |
| this.#rLog.warn({ | |
| msg: "run handler exited unexpectedly (synchronous), crashing actor to reschedule", | |
| }); | |
| this.startDestroy(); | |
| } | |
| } |
Spotted by Graphite Agent
Is this helpful? React 👍 or 👎 to let us know.

No description provided.