-
Notifications
You must be signed in to change notification settings - Fork 146
fix: set failure reason regardless of crash policy #3835
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: 01-09-feat_add_metrics_to_pb_guard
Are you sure you want to change the base?
fix: set failure reason regardless of crash policy #3835
Conversation
f7e33e7 to
b613527
Compare
9297e74 to
442651f
Compare
PR Review: Fix failure reason setting regardless of crash policyOverviewThis PR refactors how failure reasons are set when Rivet Actors stop, ensuring failure reasons are always recorded regardless of the crash policy. The changes improve observability by guaranteeing that crash/failure information is preserved even when actors are configured to sleep on crash. ✅ Positive Changes1. Improved Failure Reason Tracking (mod.rs:879-919)The refactoring correctly moves failure reason setting earlier in the flow and handles all crash types uniformly:
This is a significant improvement - previously, failure reasons for normal crashes were only set in the CrashPolicy::Sleep branch, meaning crashes with CrashPolicy::Restart or other policies would not record the failure reason. 2. Removed Redundant Code (mod.rs:1073)The ctx.removed activity call is now correctly placed in the CrashPolicy::Sleep branch. This makes sense because failure reasons are now set upfront for all crash types. 3. Fixed Database Query Bug (debug.rs:663-694)Good catch changing tx.read() to tx.read_opt() and handling the None case. This prevents crashes when workflows are deleted mid-query during debug operations. 4. Removed Premature State Clearing (runtime.rs:1130)Removing state.failure_reason = None from set_started is correct. The failure reason should only be cleared when an actor successfully allocates, not when it becomes connectable. This preserves failure history during the actor lifecycle. 🔍 Potential Issues & Questions1. Match Expression Restructuring (mod.rs:879-919)The match expression is now split into 3 arms instead of 2. While functionally correct, if new StopCode variants are added in the future, this match might not catch them at compile time. A nested match structure could provide better exhaustiveness checking. 2. Test CoverageI could not find explicit unit tests for the failure reason setting logic. Consider adding tests for:
3. State Management ConsistencyThe code now has two places where failure_reason is cleared:
Question: Are both necessary? It seems like line 478 might be redundant if set_allocated always clears it. 🔒 Security & PerformanceSecurity: ✅ No security concerns identified 📋 Code QualityAdherence to CLAUDE.md:
📝 Suggestions
SummaryVerdict: ✅ Approve with minor suggestions This is a solid fix that improves failure tracking across all crash policies. The core logic is sound, and the refactoring makes the code more maintainable. The main suggestion is to add test coverage to prevent regression and document the state lifecycle more clearly. The bug fix in debug.rs is a good catch that prevents potential crashes. Overall, this PR improves both correctness and observability of the Rivet Actor system. Reviewed by Claude Sonnet 4.5 |
More templates
@rivetkit/cloudflare-workers
@rivetkit/db
@rivetkit/framework-base
@rivetkit/next-js
@rivetkit/react
rivetkit
@rivetkit/sql-loader
@rivetkit/virtual-websocket
@rivetkit/engine-runner
@rivetkit/engine-runner-protocol
commit: |
b613527 to
b4daf93
Compare
7915d6f to
258ae43
Compare
0b9ca2f to
1a08758
Compare
42cfc6d to
506742d
Compare
1a08758 to
5b1c724
Compare
506742d to
ca4cbfc
Compare
5b1c724 to
8152462
Compare
ca4cbfc to
8102256
Compare
8152462 to
82ed36d
Compare
82ed36d to
f5a4f68
Compare
4b907cb to
dc985c0
Compare
f5a4f68 to
9e4ae6f
Compare
dc985c0 to
f3f7d72
Compare
595d7b8 to
250667d
Compare
f3f7d72 to
ae1c40c
Compare
250667d to
980dd0a
Compare
ae1c40c to
3da23f7
Compare

No description provided.